题目:
# -*- coding:utf-8 -*-
import re
import requests
s = requests.Session()
r = s.get("http://120.24.86.145:8002/qiumingshan/")
searchObj = re.search(r'^<div>(.*)=\?;</div>$', r.text, re.M | re.S)
d = {"value": eval(searchObj.group(1))}
r = s.post("http://120.24.86.145:8002/qiumingshan/", data=d)
print (r.text)
以上代码在python3 下能顺利运行,多试几次就能得到flag。也可以写个循环,如下:
import re
import requests
while(True):
s = requests.Session()
r = s.get("http://120.24.86.145:8002/qiumingshan/")
searchObj = re.search(r'^<div>(.*)=\?;</div>$', r.text, re.M | re.S)
d = {"value": eval(searchObj.group(1))}
r = s.post("http://120.24.86.145:8002/qiumingshan/", data=d)
print (r.text)
if r.text.strip():
break
现在考虑用python2.7 运行代码,会遇到编码问题,调整如下:
# -*- coding:utf-8 -*-
import re
import requests
while(True):
s = requests.Session()
r = s.get("http://120.24.86.145:8002/qiumingshan/")
searchObj = re.search(r'^<div>(.*)=\?;</div>$', r.text, re.M | re.S)
d = {"value": eval(searchObj.group(1))}
r = s.post("http://120.24.86.145:8002/qiumingshan/", data=d)
flag = r.text
print flag.encode('utf-8')
if flag.strip():
break
考虑一个问题,关于最后输出结果的编码问题,如何解决呢?python新手,求指教。