PyHacker實現(xiàn)網(wǎng)站后臺掃描器編寫指南
包括如何處理假的200頁面/404智能判斷等
喜歡用Python寫腳本的小伙伴可以跟著一起寫一寫呀。
編寫環(huán)境:Python2.x
00x1:模塊
需要用到的模塊如下:
import request
00x2:請求基本代碼
先將請求的基本代碼寫出來:
import requests
def dir(url):
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0'}
req = requests.get(url=url,headers=headers)
print req.status_code
dir('http://www.hackxc.cc')
00x3:設(shè)置
設(shè)置超時時間,以及忽略不信任證書
import urllib3 urllib3.disable_warnings() req = requests.get(url=url,headers=headers,timeout=3,verify=False)
再加個異常處理

調(diào)試一下

再進(jìn)行改進(jìn),如果為200則輸出
if req.status_code==200:
print "[*]",req.url00x4:200頁面處理
難免會碰到假的200頁面,我們再處理一下
處理思路:
首先訪問hackxchackxchackxc.php和xxxxxxxxxx記錄下返回的頁面的內(nèi)容長度,然后在后來的掃描中,返回長度等于這個長度的判定為404
def dirsearch(u,dir):
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0'}
#假的200頁面進(jìn)行處理
hackxchackxchackxc = '/hackxchackxchackxc.php'
hackxchackxchackxc_404 =requests.get(url=u+hackxchackxchackxc,headers=headers)
# print len(hackxchackxchackxc_404.content)
xxxxxxxxxxxx = '/xxxxxxxxxxxx'
xxxxxxxxxxxx_404 = requests.get(url=u + xxxxxxxxxxxx, headers=headers)
# print len(xxxxxxxxxxxx_404.content)
#正常掃描
req = requests.get(url=u+dir,headers=headers,timeout=3,verify=False)
# print len(req.content)
if req.status_code==200:
if len(req.content)!=len(hackxchackxchackxc_404.content)and len(req.content)!= len(xxxxxxxxxxxx_404.content):
print "[+]",req.url
else:
print u+dir,404
except:
pass很nice

00x5:保存結(jié)果
再讓結(jié)果自動保存

0x06:完整代碼
#!/usr/bin/python
#-*- coding:utf-8 -*-
import requests
import urllib3
urllib3.disable_warnings()
urls = []
def dirsearch(u,dir):
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0'}
#假的200頁面進(jìn)行處理
hackxchackxchackxc = '/hackxchackxchackxc.php'
hackxchackxchackxc_404 =requests.get(url=u+hackxchackxchackxc,headers=headers)
# print len(hackxchackxchackxc_404.content)
xxxxxxxxxxxx = '/xxxxxxxxxxxx'
xxxxxxxxxxxx_404 = requests.get(url=u + xxxxxxxxxxxx, headers=headers)
# print len(xxxxxxxxxxxx_404.content)
#正常掃描
req = requests.get(url=u+dir,headers=headers,timeout=3,verify=False)
# print len(req.content)
if req.status_code==200:
if len(req.content)!=len(hackxchackxchackxc_404.content)and len(req.content)!= len(xxxxxxxxxxxx_404.content):
print "[+]",req.url
with open('success_dir.txt','a+')as f:
f.write(req.url+"\n")
else:
print u+dir,404
else:
print u + dir, 404
except:
pass
if __name__ == '__main__':
url = raw_input('\nurl:')
print ""
if 'http' not in url:
url = 'http://'+url
dirpath = open('rar.txt','r')
for dir in dirpath.readlines():
dir = dir.strip()
dirsearch(url,dir)以上就是PyHacker實現(xiàn)網(wǎng)站后臺掃描器編寫指南的詳細(xì)內(nèi)容,更多關(guān)于PyHacker網(wǎng)站后臺掃描器的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python操作Redis之設(shè)置key的過期時間實例代碼
這篇文章主要介紹了Python操作Redis之設(shè)置key的過期時間實例代碼,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下2018-01-01
安裝pycurl報錯Could not run curl-config: &ap
這篇文章主要為大家介紹了安裝pycurl報錯Could not run curl-config: 'curl-config'解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12
Pygame游戲開發(fā)之太空射擊實戰(zhàn)圖像精靈下篇
相信大多數(shù)8090后都玩過太空射擊游戲,在過去游戲不多的年代太空射擊自然屬于經(jīng)典好玩的一款了,今天我們來自己動手實現(xiàn)它,在編寫學(xué)習(xí)中回顧過往展望未來,下面開始入門篇2022-08-08
解決python 出現(xiàn)unknown encoding: idna 的問題
這篇文章主要介紹了解決python出現(xiàn) unknown encoding: idna 的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03
python射線法判斷檢測點是否位于區(qū)域外接矩形內(nèi)
這篇文章主要為大家詳細(xì)介紹了python射線法判斷檢測點是否位于區(qū)域外接矩形內(nèi),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-06-06
pandas去重復(fù)行并分類匯總的實現(xiàn)方法
這篇文章主要介紹了pandas去重復(fù)行并分類匯總的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01
python實現(xiàn)定時壓縮指定文件夾發(fā)送郵件
這篇文章主要為大家詳細(xì)介紹了python實現(xiàn)定時壓縮指定文件夾發(fā)送郵件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-04-04

