黑帽子工具编写(python)

渗透测试python代码

子域名扫描

# python subdomain_enumeration.py -w subdomain.txt -d baidu.com
import argparse
import requests
import concurrent.futures


def get_word_list(file_path):
    with open(file_path, 'r' ,encoding='utf-8') as r:
        word_list = [i.strip() for i in r.readlines()]
    return word_list

def subdomain_enumeration(domain, word_list, thread):
    def subdomain_enum(sub, domain):
        sub_domains = f"http://{sub}.{domain}"
        try:
            requests.get(sub_domains)
        except requests.ConnectionError: 
            pass
        else:
            print("Valid domain: ",sub_domains)
  
    with concurrent.futures.ThreadPoolExecutor(max_workers=int(thread)) as executor:
        futures = [executor.submit(subdomain_enum, sub, domain) for sub in word_list]
        concurrent.futures.wait(futures)

  
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="subdomain enumeration")
    parser.add_argument("-w", "--word", help="Specify the dictionary file path", required=True)
    parser.add_argument("-d", "--domain", help="Specify the primary domain", required=True)
    parser.add_argument("-t", "--thread", help="Specify the thread number", required=False, default="20")
    args = parser.parse_args()
    word_list = get_word_list(args.word)
    subdomain_enumeration(args.domain, word_list, args.thread)

目录扫描

import argparse
import requests
import concurrent.futures


def get_word_list(file_path):
    with open(file_path, 'r' ,encoding='utf-8') as r:
        word_list = [i.strip() for i in r.readlines()]
    return word_list

def directory_enumeration(url, word_list, prefix="", suffix="", thread="20"):
    def dir_enum(url, prefix, dir_str, suffix):
        dir_enum = f"{url}/{prefix}{dir_str}{suffix}"
        r = requests.get(dir_enum)
        if r.status_code==404: 
            pass
        else:
            print("Valid directory:" ,dir_enum, r.status_code)

    url = url.rstrip("/")
    with concurrent.futures.ThreadPoolExecutor(max_workers=int(thread)) as executor:
        futures = [executor.submit(dir_enum, url, prefix, dir_str, suffix) for dir_str in word_list]
        concurrent.futures.wait(futures)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="directory enumeration")
    parser.add_argument("-w", "--word", help="Specify the dictionary file path", required=True)
    parser.add_argument("-u", "--url", help="Specify the url", required=True)
    parser.add_argument("-pf", "--prefix", help="Specify the prefix", required=False, default="")
    parser.add_argument("-sf", "--suffix", help="Specify the suffix", required=False, default="")
    parser.add_argument("-t", "--thread", help="Specify the thread number", required=False, default="20")
    args = parser.parse_args()
    word_list = get_word_list(args.word)
    directory_enumeration(args.url, word_list, args.prefix, args.suffix, args.thread)

网络扫描

from scapy.all import Ether, ARP, srp
import argparse
import concurrent.futures

def network_scanner(ip_range, interface, broadcastMac, thread):
    packet = Ether(dst=broadcastMac)/ARP(pdst = ip_range) 
    ans, _ = srp(packet, timeout =2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值