[GXYCTF2019]StrongestMind

知识点:爬虫

目标明确,成功1000次。
因为每次都要保存上一次的状态,所以这边要保存一下session,也就是会话。
虽说只要1000,但我们写脚本的时候最好多来几次,难免中间有几次挂了。

[GXYCTF2019]StrongestMind_第1张图片
废话不多说,上脚本。

import requests
import re
import time

url = 'http://66905b90-a9f4-4d2d-8eed-d9949b027ca7.node4.buuoj.cn:81/'
session = requests.session()
req = session.get(url).text
flag = ""

for i in range(1010):
    try:
        result = re.findall("\\(\d.*?)\\",req)#获取[数字]
        result = "".join(result)#提取字符串
        result = eval(result)#运算
        print("time: "+ str(i) +"   "+"result: "+ str(result))

        data = {"answer":result}
        req = session.post(url,data=data).text
        if "flag{" in req:
            print(re.search("flag{.*}", req).group(0)[:50])
            break
        time.sleep(0.1)#防止访问太快断开连接
    except:
        print("[-]")

官方exp:

from requests import *
import re


s = session()
a = s.get("http://172.21.4.12:10044/index.php")
pattern = re.findall(r'\d+.[+-].\d+', a.text) 
c = eval(pattern[0])
a = s.post("http://172.21.4.12:10044/index.php", data = {"answer" : c})
for i in range(1000):
	pattern = re.findall(r'\d+.[+-].\d+', a.text) 
	c = eval(pattern[0])
	print(c)
	a = s.post("http://172.21.4.12:10044/index.php", data = {"answer" : c})
print(a.text)

你可能感兴趣的:(BUUCTF,session会话,爬虫)