import subprocess\nimport sys, getopt\nimport time\n\nclass bcolors:\n    HEADER = '\033[95m'\n    OKBLUE = '\033[94m'\n    OKCYAN = '\033[96m'\n    OKGREEN = '\033[92m'\n    WARNING = '\033[93m'\n    FAIL = '\033[91m'\n    ENDC = '\033[0m'\n    BOLD = '\033[1m'\n    UNDERLINE = '\033[4m'\ndef runCurl(username, password, failure, success, curlCommand):\n    curlCommandMod = curlCommand.replace("^USER^", username)\n    curlCommandMod = curlCommandMod.replace("^PASS^", password)\n    #result = subprocess.check_output(curlCommandMod, shell=True)\n\n    #print(curlCommandMod)\n    #result = os.system(curlCommandMod)\n\n    result = subprocess.run(curlCommandMod, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, text=True)\n    #se non metto text=True devo decodificare lo stdout con .decode('ascii')\n    output = result.stdout\n    #print("RESULT: %s" % (output))\n    if len(failure) > 0:\n        if failure not in output:\n\n            string = "SUCCESS: " + username + ":" + password\n            print(f"{bcolors.OKGREEN}%s{bcolors.OKGREEN}" %(string))\n            return True\n    elif len(success) > 0:\n        if success in output:\n            string = "SUCCESS: " + username + ":" + password\n            print(f"{bcolors.OKGREEN}%s{bcolors.OKGREEN}" % (string))\n            return True\n\n    return False\n\n\ndef main(argv):\n    username = ''\n    wordlist = ''\n    curlCommand = ''\n    failure = ""\n    success = ""\n    opts, args = getopt.getopt(argv,"hu:w:F:S:c:",["username=","wlfile=","failure=","success=","curlCommand="])\n    for opt, arg in opts:\n        if opt == '-h':\n            print ('python3 CurlIterator.py -u username <-F failureString or -S SuccessString> -w <wordlist> -c curlCommand /nUse ^USER^ for username and ^PASS^ for password')\n            sys.exit()\n        elif opt in ("-u", "--username"):\n            username = arg\n        elif opt in ("-w", "--wordlist"):\n            wordlist = arg\n        elif opt in ("-F", "--failure"):\n            failure = arg\n        elif opt in ("-S", "--success"):\n            success = arg\n        elif opt in ("-c", "--curlCommand"):\n            curlCommand = arg\n\n    #load password file\n    arrayLines = []\n    with open(wordlist) as file:\n        for line in file:\n            arrayLines.append(line.rstrip())\n    indexLines = 0\n    count = len(arrayLines)\n    for i in range(count):\n        outputString = "Password testate per %s: %d - Completetato %.1f %%" % (username, len(arrayLines),  (float(indexLines)/float(count)*100))\n        if indexLines < len(arrayLines):\n            password = arrayLines[indexLines]\n            founded = runCurl(username, password, failure, success, curlCommand)\n            if founded:\n                break\n        else:\n            print("Test completed!")\n            break\n        indexLines += 1\n        time.sleep(0.1)\n        if i == 9: #last try\n            print(outputString)\nif __name__ == "__main__":\n    main(sys.argv[1:])