import requests

def GetHtml(url):
    try:
        r = requests.get(url,timeout=10)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        return r.text
    except:
        return "error!"

from bs4 import BeautifulSoup

def GetUrl():
    return input("input url:")
def TransHtml(txt):
    return BeautifulSoup(txt,"html.parser")

from urllib.parse import urljoin
from urllib.parse import urlparse
from urllib.parse import urlunparse
from posixpath import normpath

def LinkUrl(base,url):
    a_url = urljoin(base,url)
    arr = urlparse(a_url)
    path = normpath(arr[2])
    return urlunparse((arr.scheme,arr.netloc,path,arr.params,arr.query,arr.fragment))

import re
import subprocess

def cmdLine():
    level = input("execute level:")
    level = " --level=" + level
    risk = input("execute risk:")
    risk = " --risk=" + risk
    thread = input("run threads:")
    thread = " --threads=" + thread

    cmd = level + risk + thread + " -o"
    return cmd

def GetLink(obj,url):
    cmd1 = cmdLine()
    allink = set()
    for link in obj.find_all(re.compile('^a')):
        new_url = LinkUrl(url,link.get("href"))
        allink.add(new_url)
    for i in allink:
        cmd = "sqlmap -u " + i + " --batch --output-dir=~" + cmd1 + " > result.txt"
        subprocess.run(cmd,shell=True)
        print("testing " + i)
        with open("result.txt","r") as f:
            total = f.readlines()
            for item in total:
                if item.count("Type:")!=0:
                    print("exsit injection" + item)
                    with open("final.txt","a") as res:
                        info = i + item
                        res.write(info)
                    tmp = item
                if item.count("Payload")!=0:
                    with open("payload.txt","a") as payload:
                        p = i + tmp + item
                        payload.write(p)
    print("test over!")
    display_menu()

import sys

def choices():
    op = int(input("your option:"))
    if op == 1:
        url = GetUrl()
        demo = GetHtml(url)
        soup = TransHtml(demo)
        GetLink(soup,url)
    if op == 2:
        userinput = input("input params:")
        cmd = "sqlmap " + userinput
        subprocess.run(cmd,shell=True)
    if op == 3:
        sys.exit()

def display_menu():
    print("1.auto test")
    print("2.manual test")
    print("3.exit")
    choices()

if __name__=="__main__":
    display_menu()
posted on 2021-01-07 21:48  Asuhe  阅读(164)  评论(0编辑  收藏  举报