import optparse
import requests
import sys


def send_url_payload(target):
    with open('url_payloads.txt', 'r') as f:
        url_payloads = f.read().splitlines()
        for payload in url_payloads:
            req = requests.get(target + payload)
            if req.status_code == 200:
                print(f'[{req.status_code}]\t' + str(len(req.text)) + f'\t{payload}')


def send_header_payload(target):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Language": "en-US,en;q=0.5",
        "Accept-Encoding": "gzip, deflate",
        "DNT": "1",
        "Connection": "close",
        "Upgrade-Insecure-Requests": "1"}
    with open('header_payloads.txt', 'r') as f:
        header_payloads = f.read().splitlines()
        for payload in header_payloads:
            header = payload.split(':')
            headers[header[0]] = header[1].strip()
            req = requests.post(target, headers=headers)
            if req.status_code == 200:
                print(f'[{req.status_code}]\t' + str(len(req.text)) + f'\t{payload}')



def main():
    parser = optparse.OptionParser(usage=f"{sys.argv[0]} URL")
    #parser.add_option("-u", "--url", dest="url", help="URL to bypass")

    (options, args) = parser.parse_args()

    if len(args) == 0:
        print("Target is missing")
        print(parser.usage)
    else:
        targetURL = sys.argv[1]
        try:
            print("Starting test ...")
            #Testing using url payloads
            send_url_payload(targetURL)

            #Testing using header payloads
            send_header_payload(targetURL)
            print("Test done!")
        except KeyboardInterrupt:
            print("Ctrl-C pressed. Exiting")
            sys.exit()


if __name__ == "__main__":
    main()
