Hackfinity Battle Vault

From the Hackfinity Battle CTF event. -by munra, hadrian3689 and h4sh3m00

The following post by 0xb0b is licensed under CC BY 4.0


Heist

BlockChain

The challenge provides us with the functions required for the solution on the web server running on the machine. We can use the Foundry to solve the challenge.

To solve this challenge using Foundry, we write a script where the contract first calls changeOwnership() to become the new owner, then calls withdraw() to drain the contract balance. The isSolved() function will return true once the balance is 0, confirming success.

We run our script and provide the machines IP.

We were able to change the owner and withdraw the contracts balance. We visit the web page again and request the flag.

PassCode

BlockChain

The challenge provides us with the functions required for the solution on the web server running on the machine. We can use the Foundry to solve the challenge.

In order to solve this challenge, we need to call the unlock() function using the correct code. We can then request the flag via the getFlag() function. There is a hint() function that provides a string. Upon testing this manually, it becomes clear that the result of hint() is the code. To solve the challenge, we write a script that performs the aforementioned steps.

We run our script and provide the machines IP. The flag gets printed.

A Bucket of Phish

Cloud

We initally try to access the provided website directly to see what it serves. Requesting a nonexistent key in an S3-backed website helps us determine if it's misconfigured. In this case, the error message shows that the backend is an S3 bucket and confirms that keys are being served directly.

Next, we use the AWS CLI with unauthenticated access to list the bucket's files.

Some S3 buckets are public and allow listing without credentials. This shows all stored objects. Here, we discover index.html and a file named captured-logins-093582390.

Next, we download the suspicious file to check for compromised credentials and find the flag.


Cipher's Secret Message

Crypto

In Cipher's Secret Message, we are given a cipher text and the corresponding encryption script. Our task is to decrypt the message.

Message:

Given encryption script:

The given encryption script is a Caesar cipher with a twist.

If the character is uppercase, the shift value is based on the position of c in the string, starting from 0. The shift for lowercase characters is similarly based on their position. Non-alphabetic characters are not modified.

To revert the encrpytion we reverse the Caesar cipher shift by using the negative of the position-based shift to decode the characters.

Cryptosystem

Crypto

Given script:

The challenge is about the RSA Cryptosystem. We are given the algorithm and a ciphertext as well as the modulus.

In the script we have a function primo(n) that returns the next prime greater than n. This is used to determine q, which is a prime number larger than p.

If the primes p and q are generated using weak or small methods (such as picking primes close to each other), they may be easier to factor.

RSA Setup:

  • p and q are prime numbers

  • n = p * q is the modulus for the RSA encryption

  • e is the public exponent, which is 0x10001

  • d is the private exponent, computed as the modular inverse of e modulo (p-1)*(q-1)

The flag is encrypted using the RSA encryption formula:

ciphertext=plaintexte  mod  nciphertext=plaintext^e\;mod\;n

To decrypt the ciphertext we need to be in possession of the inversed of e which is d.

plaintext=ciphertextd  mod  nplaintext=ciphertext^d\; mod\; n

To calculate d we need first to factories given n to apply inverse(e, (p-1) * (q-1)). With that d we are able to calculate the plaintext message from the given ciphertext.

DarkMatter

Crypto

In DarkMatter we are face with DarkInjector's ransomware, and some files have been encrypted. From the challeng description we know that RSA is used and we need to find the private key to restore the files.

After some research and reverse engineering, you discover they have forgotten to remove some debugging from their code. The ransomware saves this data to the tmp directory.

We make use of our script from Cyptosystem and just factor the modulus nto calculate the private key d.

We issue the decryption key...

... and are able to read the encrypted files on the desktop. The file student_grades.docxcontains the flag.

Order

Crypto

In this task we are challenged to decrypt a message that is encrypted using a repeating-key XOR cipher.

Given ciphers:

To decrypt the message encrypted with a repeating-key XOR cipher, we can take advantage of the fact that the message always starts with the header ORDER:. This header is unencrypted and gives us a clue to help recover the repeating key used for encryption.

The header ORDER: is always present in the encrypted message, and we can use it to help determine the repeating key by XORing it with the corresponding encrypted bytes. Once we find the repeating key, we can apply it to the rest of the message to decrypt it. By using the recovered repeating key, we can decrypt the message and reveal Cipher's next target.

Evil-GPT

LLM

In Evil-GPT we have an AI agent that evaluates terminal commmandos. However, these are checked against misuse beforehand - This only emerged in subsequent analyses. However, the filter seems to be very limited. We try it directly with a reverse shell and use busybox.

We receive a connection on our listner and a root on the system.

We find the flag at /root/flag.txt.

At /home/ubuntu we find the scrit behind the Ai agent.

The sanitize_input() call only strips characters that don’t match the regex [a-zA-Z0-9\s\-_./]. That blocks obvious shell-meta characters like |, ;, &, $, ` and >

Evil-GPT v2

LLM

In Evil-GPT v2 we have an Agent that answers us questions about ciphers that is not supposed to reveal the flag. This can be specified in the context set before. To leak those initial instructions or a so called system prompt, prompt leaking can be used. The technique is briefly described here:

With the following examples we should be able to leak the system prompt, which also includes the flag.


Royal Router

by hadrian3689 and h4sh3m00

IoT

You will learn how to compromise an IoT device

We are attempting to solve this challenge using Exegol. I broke my Kali machine some time ago, so it's time to try something new. This is a freshly setup CachyOs on my old Lady X220T. Only the .zshrc is modified to not show the current time.

Exegol is a pre-configured offensive security Docker environment that provides a ready-to-use, portable toolkit for hacking and penetration testing.

Instructions on how to set it up can be found here: https://docs.exegol.com/first-install

Exegol is not required to solve this challenge. Kali or Burp Suite is sufficient. It is only a showcase.

We start exegol and chose our prepared container called 0xb0b. It's a free image, that is equivalent to the Full image but a few versions behind.

We run an Nmap scan and identify several ports. A service and script scan reveals that it is a D-Link wireless router on port 80.

We start Firefox in our container and, thanks to X11, it pops up immediately.

We visit the page on port 80 and are greeted with a login to a D-Link router. In the header we see that we are dealing with the product DIR-615. With hardware version C2 and firmware 3.03WW.

We research potential CVEs and find what we are looking for regarding the firmware.

This is a buffer overflow.

A buffer overflow in D-Link DIR-615 C2 3.03WW. The ping_ipaddr parameter in ping_response.cgi POST request allows an attacker to crash the webserver and might even gain remote code execution.

Reference is also made to a PoC.

But unfortunately this is no longer available.

We use the Wayback Machine and head back to 2021, there we can visit the repository. And a PoC that does not lead to RCE.

We continue and first research the default credentials.

The default Login for admin is actually a blank password:

Also in this case.

Next, we research for other PoCs and potentials flaws and find the following resource with the query below.

Google Search: dir-615 hack

Tomorrwisnew is a real treasure. With some valuable content on real targets including the DIR-615. TomorrowNews has a five-part series on the DIR-615, explaining the approaches taken to identify CVEs through reverse engineering of the firmware.

On part three a possible Command Injection on endpoint do_wps.asp (set_sta_enrollee_pin.cgi) at parameter set_sta_enrollee_pin is depicted.

We visit the endpoint, prepare a pin, and spin up Burp Suite.

We capture the request with Burp Suite and send it to the repeater module.

First, we attempted to gain a reverse shell, but were unsuccessful. Next, we tried to find out what was on the system. To do this, we tried to exfiltrate the information using a web server.

We spin up a Python web server.

And inject the following command using command substition to see if wget is available on the system. Unfortunately there seems to be no cURL available with which we would have more freedom..

We make the request.

And receive a connection back.

Next, we try to read some files. Unfortunately we are very limited, cause the new line breaks our get request, and base64 seems not available on the target to circumvent it by encoding the output of our commands made. But we are able to read some files.

We may have to log in again using the browser between requests to renew the "session". The request and set_sta_enrollee_pin.cgi does not need to be recaptured.

We find what we are looking for in the /root directory. This is where the flag is located.

Next we try to read it using cat and are successful.

We try further to get a reverse shell and check for binaries available. But there seems to be none there we could use.

We checked for nc, perl, python, ruby.

I didn't think about it at the time of writing the write-up. I got the tip from my colleague Enrico aka Shamollash right after I released it. MIPS is a simple and efficient RISC architecture, why not create a reverse shell binary using MSFVenom for that architecture.

I don't want to withhold Shamollash's solution from you, so I'll show it to you here. All credits to Shamollash.

We create the MIPS binary using MSFVenom.

Setup a listener in Metasploit Framework.

Use a Python webserver to deliver the payload...

... and use the found command injection endpoint to download, change the permission and execute the binary.

We see the binary gets downloaded.

And we receive our reverse shell.

Multiple other endpoints with command injection leading to RCE are depicted in the fifth part too to try out:


Last updated

Was this helpful?