Blog | G5 Cyber Security

Brute Force Encoding Attacks

TL;DR

This guide shows you how to try different encodings when trying to crack passwords or decrypt data. Many systems use simple encoding schemes, and knowing this can help you break them quickly.

What is Encoding?

Encoding changes text into a different format. Common examples include Base64, URL encoding, and hexadecimal. It’s not the same as encryption – it’s easily reversible. Attackers often try multiple encodings because weak systems might use them instead of proper security.

Steps to Brute Force Encodings

  1. Identify Potential Encodings: Think about where the data came from. Common encodings include:
    • Base64
    • Hexadecimal
    • URL encoding (%20 for spaces, etc.)
    • MD5 and SHA hashes (though these are one-way functions, not simple encodings)
    • ASCII85
  2. Try Base64 Decoding: This is a very common encoding. Use an online decoder or a command-line tool.
    echo "SGVsbG8gd29ybGQ=" | base64 --decode

    This will output ‘Hello world’. Many programming languages have built-in Base64 decoding functions.

  3. Try Hexadecimal Decoding: Hex uses characters 0-9 and A-F to represent bytes.
    echo -ne "48656c6c6f20776f726c64" | xxd -r -p

    This will output ‘Hello world’. Again, most languages have hex decoding functions.

  4. Try URL Decoding: This replaces special characters with % followed by a hexadecimal code.
    echo "Hello%20world" | sed 's/%([0-9A-Fa-f]{2})/x1/g'

    This will output ‘Hello world’. Online URL decoders are readily available.

  5. Try ASCII85 Decoding: A less common, but sometimes used encoding.
    echo "`~qPz" | base85 --decode
  6. Automate with a Script: For more complex cases, write a script to try multiple encodings in sequence. Python is well-suited for this.
    import base64
    import binascii
    import urllib.parse
    
    def decode_string(s):
        try:
            return base64.b64decode(s).decode('utf-8')
        except:
            pass
        try:
            return binascii.unhexlify(s).decode('utf-8')
        except:
            pass
        try:
            return urllib.parse.unquote(s)
        except:
            pass
        return None
    
    encoded_string = "SGVsbG8gd29ybGQ=" # Replace with your encoded string
    decoded_string = decode_string(encoded_string)
    if decoded_string:
        print("Decoded string: ", decoded_string)
    else:
        print("Decoding failed.")
  7. Consider Character Sets: Sometimes the encoding is combined with a specific character set (e.g., UTF-8, Latin-1). If decoding fails, try different character sets.
  8. Hash Attempts (MD5, SHA): While not encodings, systems sometimes store passwords as hashes without proper salting. Use online hash cracking tools or libraries like Hashcat to attempt to crack these.

Important Considerations

Exit mobile version