利用python實現對web服務器的目錄探測的方法
一、python
Python是一種解釋型、面向對象、動態(tài)數據類型的高級程序設計語言。
python 是一門簡單易學的語言,并且功能強大也很靈活,在滲透測試中的應用廣泛,讓我們一起打造屬于自己的滲透測試工具
二、web服務器的目錄探測腳本打造
1、在滲透時如果能發(fā)現web服務器中的webshell,滲透是不是就可以變的簡單一點尼
通常情況下御劍深受大家的喜愛,但是今天在測試的時候webshell不知道為什么御劍掃描不到
仔細查看是webshell有防爬功能,是檢測User-Agent頭,如果沒有就回返回一個自己定義的404頁面
1、先來看看工具效果

2、利用python讀取掃描的目錄字典
def get_url(path):
with open(path, "r", encoding='ISO-8859-1') as f:
for url in f.readlines():
url_list.append(url.strip())
return url_list
3、利用 python 的 requests 庫對web目標服務器進行目錄探測
def Go_scan(url):
while not queue.empty():
url_path = queue.get(timeout=1)
new_url = url + url_path
res = requests.get(new_url, headers=headers, timeout=5)
#print(res.status_code)
status_code = "[" + str(res.status_code) + "]"
if str(res.status_code) != "404":
print(get_time(), status_code, new_url)
4、利用 python 的 threading 庫對探測進行線程的設置
def thread(Number,url):
threadlist = []
for pwd in url_list:
queue.put(pwd)
for x in range(Number):
t = threading.Thread(target=Go_scan, args=(url,))
threadlist.append(t)
for t in threadlist:
t.start()
5、利用 python 的 argparse 庫進行對自己的工具進行封裝
def main():
if len(sys.argv) == 1:
print_banner()
exit(1)
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
use examples:
python dir_scan.py -u [url]http://www.test.com[/url] -d /root/dir.txt
python dir_scan.py -u [url]http://www.test.com[/url] -t 30 -d /root/dir.txt
''')
parser.add_argument("-u","--url", help="scan target address", dest='url')
parser.add_argument("-t","--thread", help="Number of threads", default="20", type=int, dest='thread')
parser.add_argument("-d","--Dictionaries", help="Dictionary of Blasting Loading",
dest="Dictionaries")
總結
各位大哥有意見或者建議盡管提,文章哪里不對的話會改的,小弟定會虛心學習最后附上全部源碼供大佬指教
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import threading
import argparse,sys
import time,os
from queue import Queue
url_list = []
queue = Queue()
headers = {
'Connection':'keep-alive',
'Accept':'*/*',
'Accept-Language': 'zh-CN',
'User-Agent':'Mozilla/5.0 (Windows NT 6.2; rv:16.0) Gecko/20100101 Firefox/16.0'
}
def print_banner():
banner = r"""
.___.__ __________________ _____ _______
__| _/|__|_______ / _____/\_ ___ \ / _ \ \ \
/ __ | | |\_ __ \ \_____ \ / \ \/ / /_\ \ / | \
/ /_/ | | | | | \/ / \\ \____/ | \/ | \
\____ | |__| |__| /_______ / \______ /\____|__ /\____|__ /
\/ \/ \/ \/ \/
[*] Very fast directory scanning tool.
[*] try to use -h or --help show help message
"""
print(banner)
def get_time():
return '[' + time.strftime("%H:%M:%S", time.localtime()) + '] '
def get_url(path):
with open(path, "r", encoding='ISO-8859-1') as f:
for url in f.readlines():
url_list.append(url.strip())
return url_list
def Go_scan(url):
while not queue.empty():
url_path = queue.get(timeout=1)
new_url = url + url_path
res = requests.get(new_url, headers=headers, timeout=5)
#print(res.status_code)
status_code = "[" + str(res.status_code) + "]"
if str(res.status_code) != "404":
print(get_time(), status_code, new_url)
def thread(Number,url):
threadlist = []
for pwd in url_list:
queue.put(pwd)
for x in range(Number):
t = threading.Thread(target=Go_scan, args=(url,))
threadlist.append(t)
for t in threadlist:
t.start()
def main():
if len(sys.argv) == 1:
print_banner()
exit(1)
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
use examples:
python dir_scan.py -u [url]http://www.test.com[/url] -d /root/dir.txt
python dir_scan.py -u [url]http://www.test.com[/url] -t 30 -d /root/dir.txt
''')
parser.add_argument("-u","--url", help="scan target address", dest='url')
parser.add_argument("-t","--thread", help="Number of threads", default="20", type=int, dest='thread')
parser.add_argument("-d","--Dictionaries", help="Dictionary of Blasting Loading",
dest="Dictionaries")
args = parser.parse_args()
Number =args.thread
url = args.url
url_path = args.Dictionaries
print_banner()
get_url(url_path)
print(get_time(), "[INFO] Start scanning----\n")
time.sleep(2)
thread(Number,url)
if __name__ == '__main__':
main()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Python Web服務器Tornado使用小結
- Python 搭建Web站點之Web服務器與Web框架
- Python基于twisted實現簡單的web服務器
- Python實現的檢測web服務器健康狀況的小程序
- Python實現簡易版的Web服務器(推薦)
- Python編程實現的簡單Web服務器示例
- Python命令啟動Web服務器實例詳解
- Python 搭建Web站點之Web服務器網關接口
- python探索之BaseHTTPServer-實現Web服務器介紹
- python批量同步web服務器代碼核心程序
- python快速建立超簡單的web服務器的實現方法
- Python Web程序搭建簡單的Web服務器
- python實現靜態(tài)web服務器
相關文章
解決安裝torch后,torch.cuda.is_available()結果為false的問題
這篇文章主要介紹了解決安裝torch后,torch.cuda.is_available()結果為false的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12
Python正則表達式函數match()和search()使用全面指南
在Python中,正則表達式是強大的工具,能夠用于文本匹配、搜索和替換,re模塊提供了許多函數來處理正則表達式,其中match()和search()是兩個常用的函數,本文將深入探討這兩個函數的用法、區(qū)別和示例,幫助你更好地理解它們的功能2024-01-01

