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:設置
設置超時時間,以及忽略不信任證書
import urllib3 urllib3.disable_warnings() req = requests.get(url=url,headers=headers,timeout=3,verify=False)
再加個異常處理

調(diào)試一下

再進行改進,如果為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頁面進行處理
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:保存結果
再讓結果自動保存

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頁面進行處理
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)站后臺掃描器編寫指南的詳細內(nèi)容,更多關于PyHacker網(wǎng)站后臺掃描器的資料請關注腳本之家其它相關文章!
相關文章
python實現(xiàn)數(shù)學模型(插值、擬合和微分方程)
這篇文章主要介紹了python實現(xiàn)數(shù)學模型(插值、擬合和微分方程),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11
分享python機器學習中應用所產(chǎn)生的聚類數(shù)據(jù)集方法
本文根據(jù) 機器學習中常用的聚類數(shù)據(jù)集生成方法 中的內(nèi)容進行編輯實驗和整理而得,有需要的朋友可以參考想,希望可以對大家在聚類數(shù)據(jù)方面有所幫助2021-08-08
Python多線程編程(八):使用Event實現(xiàn)線程間通信
這篇文章主要介紹了Python多線程編程(八):使用Event實現(xiàn)線程間通信,,需要的朋友可以參考下2015-04-04
Python?Asyncio庫之a(chǎn)syncio.task常用函數(shù)詳解
Asyncio在經(jīng)過一段時間的發(fā)展以及獲取Curio等第三方庫的經(jīng)驗來提供更多的功能,目前高級功能也基本完善。本文主要介紹了Asyncio庫中asyncio.task常用函數(shù)的使用,需要的可以參考一下2023-03-03

