def checkUrlsForVuln(filenameRawUrl):
    print(('\n\n\n' + bcolors.HEADER))
    print('  #===============================#')
    print('  #                               #')
    print('  #   Check if urls is vuln for   #')
    print('  #         SQL injection         #')
    print('  #                               #')
    print('  #===============================#')
    print(('\n' + bcolors.ENDC))
    if (filenameRawUrl != '0'):
        print(('  Filepath from run is still in memory: ' + filenameRawUrl))
        urlfileChoose = input(((bcolors.ENDC + '  (i)nput new filename, or (u)se from memory (i/U): ') + bcolors.OKBLUE))
        if (urlfileChoose not in ('i', 'u')):
            print((bcolors.WARNING + '  - Using from memory'))
            urlfileChoose = 'u'
        if (urlfileChoose == 'u'):
            urlfile = filenameRawUrl
        else:
            urlfile = input(((bcolors.ENDC + '  Filename with urls: ') + bcolors.OKBLUE))
    else:
        urlfile = input(((bcolors.ENDC + '  Filename with urls: ') + bcolors.OKBLUE))
    if (not os.path.isfile(urlfile)):
        print((bcolors.FAIL + '  Specified file does not exist.'))
        print((bcolors.FAIL + '  Exiting'))
        sys.exit()
    verboseactive = input(((bcolors.ENDC + '  Verboselevel (0, 1, 2): ') + bcolors.OKBLUE))
    if (not verboseactive):
        print((bcolors.WARNING + '  - Wrong input - only numeric values allowed. Using 0'))
        verboseactive = '0'
    savesearch = input(((bcolors.ENDC + '  Save search (y/N): ') + bcolors.OKBLUE))
    if (savesearch.lower() not in ('', 'y', 'n')):
        print((bcolors.WARNING + "  - Wrong input - only 'y' and 'n' allowed. Using 'y'"))
        savesearch = 'y'
    if (savesearch == 'y'):
        filename = input(((bcolors.ENDC + '  Filename for results: ') + bcolors.OKBLUE))
        if (not filename):
            print((bcolors.WARNING + "  - Wrong input - using 'vulnurls' as filename"))
            filename = 'vulnurls'
        if (not os.path.isfile(filename)):
            os.mknod(filename)
        else:
            appendtofile = input(((bcolors.ENDC + '  File exists, append (Y/n): ') + bcolors.OKBLUE))
            if (appendtofile == 'n'):
                print('  User disallowed appending to resultfile')
                print('  Please try again with another filename')
                print('  Exiting')
                sys.exit()
    else:
        filename = '0'
    print((bcolors.ENDC + '\n  [*]::Reading file\n'))
    print('  [*]  Connecting\n')
    with open(urlfile) as fileorg:
        for line in fileorg:
            checkMY1 = 0
            checkMY2 = 0
            checkMY3 = 0
            checkMY4 = 0
            checkMS1 = 0
            checkMS2 = 0
            checkMS3 = 0
            checkOR1 = 0
            checkOR2 = 0
            checkOR3 = 0
            checkPO1 = 0
            checkPO2 = 0
            try:
                url = (line + "'")
                print(((('  [' + time.strftime('%H:%M:%S')) + ']  [*]  ') + line.strip('\n')))
                uas = LoadUserAgents()
                ua = random.choice(uas)
                headers = {'Connection': 'close', 'User-Agent': ua}
                r = requests.get(url, headers=headers)
                soup = BeautifulSoup(r.text, 'lxml')
                checkMY1 = len(soup.find_all(text=re.compile('check the manual that corresponds to your MySQL')))
                checkMY2 = len(soup.find_all(text=re.compile('SQL syntax')))
                checkMY3 = len(soup.find_all(text=re.compile('server version for the right syntax')))
                checkMY4 = len(soup.find_all(text=re.compile('expects parameter 1 to be')))
                checkMS1 = len(soup.find_all(text=re.compile('Unclosed quotation mark before the character string')))
                checkMS2 = len(soup.find_all(text=re.compile('An unhanded exception occurred during the execution')))
                checkMS3 = len(soup.find_all(text=re.compile('Please review the stack trace for more information')))
                checkOR1 = len(soup.find_all(text=re.compile('java.sql.SQLException: ORA-00933')))
                checkOR2 = len(soup.find_all(text=re.compile('SQLExceptionjava.sql.SQLException')))
                checkOR3 = len(soup.find_all(text=re.compile('quoted string not properly terminated')))
                checkPO1 = len(soup.find_all(text=re.compile('Query failed:')))
                checkPO2 = len(soup.find_all(text=re.compile('unterminated quoted string at or near')))
                if (verboseactive == '1'):
                    print(('  [V]  Check1 MySQL found:    ' + str(checkMY1)))
                    print(('  [V]  Check2 MySQL found:    ' + str(checkMY2)))
                    print(('  [V]  Check3 MySQL found:    ' + str(checkMY3)))
                    print(('  [V]  Check4 MySQL found:    ' + str(checkMY4)))
                    print(('  [V]  Check5 MS SQL found:   ' + str(checkMS1)))
                    print(('  [V]  Check6 MS SQL found:   ' + str(checkMS2)))
                    print(('  [V]  Check7 MS SQL found:   ' + str(checkMS3)))
                    print(('  [V]  Check8 Oracle found:   ' + str(checkOR1)))
                    print(('  [V]  Check9 Oracle found:   ' + str(checkOR2)))
                    print(('  [V]  Check10 Oracle found:  ' + str(checkOR3)))
                    print(('  [V]  Check11 Postgre found: ' + str(checkPO1)))
                    print(('  [V]  Check12 Postgre found: ' + str(checkPO2)))
                if (verboseactive == '2'):
                    checkverMY1 = soup.find(text=re.compile('check the manual that corresponds to your MySQL'))
                    checkverMY2 = soup.find(text=re.compile('SQL syntax'))
                    checkverMY3 = soup.find(text=re.compile('server version for the right syntax'))
                    checkverMY4 = soup.find(text=re.compile('expects parameter 1 to be'))
                    print(('  [V]  Check1 MySQL found:    ' + str(checkverMY1).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check2 MySQL found:    ' + str(checkverMY2).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check3 MySQL found:    ' + str(checkverMY3).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check4 MySQL found:    ' + str(checkverMY4).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    checkverMS1 = soup.find(text=re.compile('Unclosed quotation mark before the character string'))
                    checkverMS2 = soup.find(text=re.compile('An unhanded exception occurred during the execution'))
                    checkverMS3 = soup.find(text=re.compile('Please review the stack trace for more information'))
                    print(('  [V]  Check5 MS SQL found:   ' + str(checkverMS1).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check6 MS SQL found:   ' + str(checkverMS2).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check7 MS SQL found:   ' + str(checkverMS3).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    checkverOR1 = soup.find(text=re.compile('java.sql.SQLException: ORA-00933'))
                    checkverOR2 = soup.find(text=re.compile('SQLExceptionjava.sql.SQLException'))
                    checkverOR3 = soup.find(text=re.compile('quoted string not properly terminated'))
                    print(('  [V]  Check8 Oracle found:   ' + str(checkverOR1).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check9 Oracle found:   ' + str(checkverOR2).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check10 Oracle found:  ' + str(checkverOR3).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    checkverPO1 = soup.find(text=re.compile('Query failed:'))
                    checkverPO2 = soup.find(text=re.compile('unterminated quoted string at or near'))
                    print(('  [V]  Check11 Postgre found: ' + str(checkverPO1).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                    print(('  [V]  Check12 Postgre found: ' + str(checkverPO2).replace('\n', ' ').replace('\r', '').replace('\t', '').replace('  ', '')))
                if ((checkMY1 > 0) or (checkMY2 > 0) or (checkMY3 > 0) or (checkMY4 > 0) or (checkMS1 > 0) or (checkMS2 > 0) or (checkMS3 > 0) or (checkOR1 > 0) or (checkOR2 > 0) or (checkOR3 > 0) or (checkPO1 > 0) or checkPO2):
                    print((((((((((bcolors.OKGREEN + '\n') + '                   Possible vuln url!') + '\n') + '  [') + time.strftime('%H:%M:%S')) + ']  [+]  ') + line) + bcolors.ENDC) + '\n'))
                    if (savesearch == 'y'):
                        with open(filename, 'a') as file:
                            file.write(line)
                else:
                    print((((((bcolors.WARNING + '  [') + time.strftime('%H:%M:%S')) + ']  [-]  ') + line) + bcolors.ENDC))
            except KeyboardInterrupt:
                print((((bcolors.FAIL + '  [X]  ') + line) + bcolors.ENDC))
                quitnow = input((((bcolors.ENDC + bcolors.BOLD) + '  Exit program (y/N): ') + bcolors.OKBLUE))
                if (quitnow == 'y'):
                    print((bcolors.ENDC + '  // Exiting\n\n'))
                    try:
                        os.remove('tmpurllist')
                    except OSError:
                        pass
                    sys.exit()
                else:
                    print((bcolors.ENDC + '  // Continuing\n\n'))
            except:
                print((((bcolors.FAIL + '  [X]  ') + line) + bcolors.ENDC))
    print('\n  Done scanning urls')
    if (savesearch == 'y'):
        with open(filename) as f:
            resultsnumber = sum((1 for _ in f))
        print(('  Scraping saved in file: ' + filename))
        print(('  Total saved urls:  ' + str(resultsnumber)))
        if (resultsnumber == 0):
            print('  No vuln urls, exiting\n\n')
            try:
                os.remove('tmpurllist')
            except OSError:
                pass
            sys.exit()
    checkurls = input(((bcolors.ENDC + '\n  Would you like to run the urls through sqlmap (y/N): ') + bcolors.OKBLUE))
    if (checkurls == 'y'):
        try:
            os.remove('tmpurllist')
        except OSError:
            pass
        scanUrlsSQLmap(filename)
    else:
        print((bcolors.ENDC + '  // Exiting\n\n'))
        try:
            os.remove('tmpurllist')
        except OSError:
            pass
        sys.exit()
def checkUrlsForVuln(filenameRawUrl):
    print(('\n\n\n' + bcolors.HEADER))
    print('  #===============================#')
    print('  #                               #')
    print('  #   Check if urls is vuln for   #')
    print('  #         SQL injection         #')
    print('  #                               #')
    print('  #===============================#')
    print(('\n' + bcolors.ENDC))
    if (filenameRawUrl != '0'):
        print(('  Filepath from run is still in memory: ' + filenameRawUrl))
        urlfileChoose = input(((bcolors.ENDC + '  (i)nput new filename, or (u)se from memory (i/U): ') + bcolors.OKBLUE))
        if (urlfileChoose not in ('i', 'u')):
            print((bcolors.WARNING + '  - Using from memory'))
            urlfileChoose = 'u'
        if (urlfileChoose == 'u'):
            urlfile = filenameRawUrl
        else:
            urlfile = input(((bcolors.ENDC + '  Filename with urls: ') + bcolors.OKBLUE))
    else:
        urlfile = input(((bcolors.ENDC + '  Filename with urls: ') + bcolors.OKBLUE))
    if (not os.path.isfile(urlfile)):
        print((bcolors.FAIL + '  Specified file does not exist.'))
        print((bcolors.FAIL + '  Exiting'))
        sys.exit()
    verboseactive = input(((bcolors.ENDC + '  Verboselevel (0, 1, 2): ') + bcolors.OKBLUE))
    if (not verboseactive):
        print((bcolors.WARNING + '  - Wrong input - only numeric values allowed. Using 0'))
        verboseactive = '0'
    savesearch = input(((bcolors.ENDC + '  Save search (y/N): ') + bcolors.OKBLUE))
    if (savesearch.lower() not in (, 'y', 'n')):
        print((bcolors.WARNING + "  - Wrong input - only 'y' and 'n' allowed. Using 'y'"))
        savesearch = 'y'
    if (savesearch == 'y'):
        filename = input(((bcolors.ENDC + '  Filename for results: ') + bcolors.OKBLUE))
        if (not filename):
            print((bcolors.WARNING + "  - Wrong input - using 'vulnurls' as filename"))
            filename = 'vulnurls'
        if (not os.path.isfile(filename)):
            os.mknod(filename)
        else:
            appendtofile = input(((bcolors.ENDC + '  File exists, append (Y/n): ') + bcolors.OKBLUE))
            if (appendtofile == 'n'):
                print('  User disallowed appending to resultfile')
                print('  Please try again with another filename')
                print('  Exiting')
                sys.exit()
    else:
        filename = '0'
    print((bcolors.ENDC + '\n  [*]::Reading file\n'))
    print('  [*]  Connecting\n')
    with open(urlfile) as fileorg:
        for line in fileorg:
            checkMY1 = 0
            checkMY2 = 0
            checkMY3 = 0
            checkMY4 = 0
            checkMS1 = 0
            checkMS2 = 0
            checkMS3 = 0
            checkOR1 = 0
            checkOR2 = 0
            checkOR3 = 0
            checkPO1 = 0
            checkPO2 = 0
            try:
                url = (line + "'")
                print(((('  [' + time.strftime('%H:%M:%S')) + ']  [*]  ') + line.strip('\n')))
                uas = LoadUserAgents()
                ua = random.choice(uas)
                headers = {'Connection': 'close', 'User-Agent': ua}
                r = requests.get(url, headers=headers)
                soup = BeautifulSoup(r.text, 'lxml')
                checkMY1 = len(soup.find_all(text=re.compile('check the manual that corresponds to your MySQL')))
                checkMY2 = len(soup.find_all(text=re.compile('SQL syntax')))
                checkMY3 = len(soup.find_all(text=re.compile('server version for the right syntax')))
                checkMY4 = len(soup.find_all(text=re.compile('expects parameter 1 to be')))
                checkMS1 = len(soup.find_all(text=re.compile('Unclosed quotation mark before the character string')))
                checkMS2 = len(soup.find_all(text=re.compile('An unhanded exception occurred during the execution')))
                checkMS3 = len(soup.find_all(text=re.compile('Please review the stack trace for more information')))
                checkOR1 = len(soup.find_all(text=re.compile('java.sql.SQLException: ORA-00933')))
                checkOR2 = len(soup.find_all(text=re.compile('SQLExceptionjava.sql.SQLException')))
                checkOR3 = len(soup.find_all(text=re.compile('quoted string not properly terminated')))
                checkPO1 = len(soup.find_all(text=re.compile('Query failed:')))
                checkPO2 = len(soup.find_all(text=re.compile('unterminated quoted string at or near')))
                if (verboseactive == '1'):
                    print(('  [V]  Check1 MySQL found:    ' + str(checkMY1)))
                    print(('  [V]  Check2 MySQL found:    ' + str(checkMY2)))
                    print(('  [V]  Check3 MySQL found:    ' + str(checkMY3)))
                    print(('  [V]  Check4 MySQL found:    ' + str(checkMY4)))
                    print(('  [V]  Check5 MS SQL found:   ' + str(checkMS1)))
                    print(('  [V]  Check6 MS SQL found:   ' + str(checkMS2)))
                    print(('  [V]  Check7 MS SQL found:   ' + str(checkMS3)))
                    print(('  [V]  Check8 Oracle found:   ' + str(checkOR1)))
                    print(('  [V]  Check9 Oracle found:   ' + str(checkOR2)))
                    print(('  [V]  Check10 Oracle found:  ' + str(checkOR3)))
                    print(('  [V]  Check11 Postgre found: ' + str(checkPO1)))
                    print(('  [V]  Check12 Postgre found: ' + str(checkPO2)))
                if (verboseactive == '2'):
                    checkverMY1 = soup.find(text=re.compile('check the manual that corresponds to your MySQL'))
                    checkverMY2 = soup.find(text=re.compile('SQL syntax'))
                    checkverMY3 = soup.find(text=re.compile('server version for the right syntax'))
                    checkverMY4 = soup.find(text=re.compile('expects parameter 1 to be'))
                    print(('  [V]  Check1 MySQL found:    ' + str(checkverMY1).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check2 MySQL found:    ' + str(checkverMY2).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check3 MySQL found:    ' + str(checkverMY3).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check4 MySQL found:    ' + str(checkverMY4).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    checkverMS1 = soup.find(text=re.compile('Unclosed quotation mark before the character string'))
                    checkverMS2 = soup.find(text=re.compile('An unhanded exception occurred during the execution'))
                    checkverMS3 = soup.find(text=re.compile('Please review the stack trace for more information'))
                    print(('  [V]  Check5 MS SQL found:   ' + str(checkverMS1).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check6 MS SQL found:   ' + str(checkverMS2).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check7 MS SQL found:   ' + str(checkverMS3).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    checkverOR1 = soup.find(text=re.compile('java.sql.SQLException: ORA-00933'))
                    checkverOR2 = soup.find(text=re.compile('SQLExceptionjava.sql.SQLException'))
                    checkverOR3 = soup.find(text=re.compile('quoted string not properly terminated'))
                    print(('  [V]  Check8 Oracle found:   ' + str(checkverOR1).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check9 Oracle found:   ' + str(checkverOR2).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check10 Oracle found:  ' + str(checkverOR3).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    checkverPO1 = soup.find(text=re.compile('Query failed:'))
                    checkverPO2 = soup.find(text=re.compile('unterminated quoted string at or near'))
                    print(('  [V]  Check11 Postgre found: ' + str(checkverPO1).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                    print(('  [V]  Check12 Postgre found: ' + str(checkverPO2).replace('\n', ' ').replace('\r', ).replace('\t', ).replace('  ', )))
                if ((checkMY1 > 0) or (checkMY2 > 0) or (checkMY3 > 0) or (checkMY4 > 0) or (checkMS1 > 0) or (checkMS2 > 0) or (checkMS3 > 0) or (checkOR1 > 0) or (checkOR2 > 0) or (checkOR3 > 0) or (checkPO1 > 0) or checkPO2):
                    print((((((((((bcolors.OKGREEN + '\n') + '                   Possible vuln url!') + '\n') + '  [') + time.strftime('%H:%M:%S')) + ']  [+]  ') + line) + bcolors.ENDC) + '\n'))
                    if (savesearch == 'y'):
                        with open(filename, 'a') as file:
                            file.write(line)
                else:
                    print((((((bcolors.WARNING + '  [') + time.strftime('%H:%M:%S')) + ']  [-]  ') + line) + bcolors.ENDC))
            except KeyboardInterrupt:
                print((((bcolors.FAIL + '  [X]  ') + line) + bcolors.ENDC))
                quitnow = input((((bcolors.ENDC + bcolors.BOLD) + '  Exit program (y/N): ') + bcolors.OKBLUE))
                if (quitnow == 'y'):
                    print((bcolors.ENDC + '  // Exiting\n\n'))
                    try:
                        os.remove('tmpurllist')
                    except OSError:
                        pass
                    sys.exit()
                else:
                    print((bcolors.ENDC + '  // Continuing\n\n'))
            except:
                print((((bcolors.FAIL + '  [X]  ') + line) + bcolors.ENDC))
    print('\n  Done scanning urls')
    if (savesearch == 'y'):
        with open(filename) as f:
            resultsnumber = sum((1 for _ in f))
        print(('  Scraping saved in file: ' + filename))
        print(('  Total saved urls:  ' + str(resultsnumber)))
        if (resultsnumber == 0):
            print('  No vuln urls, exiting\n\n')
            try:
                os.remove('tmpurllist')
            except OSError:
                pass
            sys.exit()
    checkurls = input(((bcolors.ENDC + '\n  Would you like to run the urls through sqlmap (y/N): ') + bcolors.OKBLUE))
    if (checkurls == 'y'):
        try:
            os.remove('tmpurllist')
        except OSError:
            pass
        scanUrlsSQLmap(filename)
    else:
        print((bcolors.ENDC + '  // Exiting\n\n'))
        try:
            os.remove('tmpurllist')
        except OSError:
            pass
        sys.exit()