HackTheBox WeakRsa Walkthrough

Please Share this Post

HackTheBox Challenge
Difficulty: Easy
Category: Crypto
Challenge Link: Hack The Box

This HackTheBox Challenge description asked us if we can decrypt the files and get the flag. Let’s give it a try.

First of all, we download the zip file. Now after that we will unzip the zip file with the password given. And then make our way to the unzipped directory where the files are located and behold here, we are in the image below. We have a flag.enc file and a key.pub. Now let’s move to the next one.

Unzipped Files

After we unzipped the zip file and found 2 files in the directory, we analyzed the 2 files and found out that the flag.enc file is a flag, but it is encoded and the key.pub file is an RSA public key file which is encoded using the ASCII Text format.

File analysis

ASCII text refers to text that is encoded using the American Standard Code for Information Interchange (ASCII), a character encoding standard that represents text in computers and other digital devices.

  1. Encoding Basics:
    • ASCII uses 7 bits to represent each character, allowing for 128 unique characters.
    • These characters include:
      • Printable characters: Letters (A-Z, a-z), digits (0-9), punctuation, and symbols.
      • Control characters: Non-printable codes used for controlling devices (e.g., newline \n, tab \t).
  2. Extended ASCII:
    • Some systems expanded ASCII to 8 bits, allowing for 256 characters, which include additional symbols and characters for other languages.
  3. File Format:
    • ASCII text files (.txt) contain plain text without any formatting, making them lightweight and universally readable.
  4. Example Mapping:
    • The ASCII value of ‘A’ is 65, ‘a’ is 97, ‘0’ is 48, and so on.
    • Example: The string “Hello” in ASCII is represented as:
      • H = 72, e = 101, l = 108, l = 108, o = 111.
  • ASCII text is used for basic data storage, programming, and communication protocols.
  • It forms the foundation for many modern text encoding schemes like UTF-8.

After we did some deep research about how we could decrypt the encoded flag file (flag.enc) and get the flag using the weak rsa public key, we found a tool that could help us do that. The (RSACTFTOOL).
Note: This is the simplest way to go about it.

According to the GitHub repository, this tool is a utility designed to decrypt data from weak public keys and attempt to recover the corresponding private key. Also, this tool offers a comprehensive range of attack options, enabling users to apply various strategies to crack the encryption. The RSA security, at its core, relies on the complexity of the integer factorization problem. This project serves as a valuable resource by combining multiple integer factorization algorithms, effectively enhancing the overall decryption capabilities. Please note that this tool is primarily intended for educational purposes. It is essential to manage your expectations, as not every key can be broken within a reasonable timeframe. The complexity of the encryption algorithm may present significant challenges. It is essential to highlight that the tool, exclusively supports the RSA textbook semiprime composite modulus rather than composite multiprimes. This constraint is embedded upstream in the pycrypto library (see TODO). While this limitation exists, the tool still offers a powerful set of features for attacking RSA keys with semiprime composite modulus.

So, we can install the tool on our machine by following the rules on the repository then we can decrypt our flag using the key.pub key to decrypt the flag.enc file to get the flag like as shown below.

Flag

Another way to get the flag is we can use the key.pub key to generate the private key inorder to decrypt the flag. We got the RSA private key and save it in a file, then used both the public key and the private key to decrypt the flag.enc file as shown in the video below. And finally after that we got the flag.

Thank you.

Please Share this Post