Python教程

利用Python编写网站管理入口穷举测试工具

本文主要是介绍利用Python编写网站管理入口穷举测试工具,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

import requests
import optparse
import sys
import os
import urllib.parse
import time

class AdminPanelFinder:
    def __init__(self) -> None:
        self.banner()
        self.target_url = self.get_params()[0]
        self.word_list = self.get_params()[1]
    
    def banner(self):
        banner = """
            ******************************************************************
            ******************************************************************
                            Admin Panel Finder  by Jason Wong V1.0
            ******************************************************************
            ******************************************************************
        """
        print(banner)

    def get_params(self):
        parser = optparse.OptionParser('Usage: <Program> -u target_url -w word list')
        parser.add_option('-u', '--target_url', dest='target_url', type="string", help="Enter target url")
        parser.add_option('-w','--word_list', dest='word_list', type='string', help='Enter path of word list')
        options, args = parser.parse_args()
        if options.target_url is None or options.word_list is None:
            print(parser.usage)
            sys.exit()
        if not os.path.exists(options.word_list):
            print("The file does not exist")
            sys.exit()
        return options.target_url, options.word_list
    
    def request_handler(self, url):
        try:
            headers = {
                    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0'
                }
            print("Trying: %s" % url)
            response = requests.get(url=url, headers=headers)
            
            if response.status_code == '200':
                print("The admin panel found: %s" % url)
        except:
            pass


    def run(self):
        try:
            with open(self.word_list, 'r') as f:
                for line in f.readlines():
                    url = urllib.parse.urljoin(self.target_url, line.strip())
                    self.request_handler(url)
                    time.sleep(2)
        except KeyboardInterrupt:
            print("\n Exiting the program")
            sys.exit()
        

        
if __name__ == "__main__":
    admin_panel_finder = AdminPanelFinder()
    admin_panel_finder.run()

 

这篇关于利用Python编写网站管理入口穷举测试工具的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!