> For the complete documentation index, see [llms.txt](https://angellm.gitbook.io/hacknotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angellm.gitbook.io/hacknotes/thm/2025/agentsudo.md).

# AgentSudo

\#brute-force, #cracking, #linux, #steganography, #sudo

## Agent Sudo - Writeup

**Date**: 12/01/2025

**Difficulty**: Easy

**CTF**: <https://tryhackme.com/r/room/agentsudoctf>

***

You found a secret server located under the deep sea. Your task is to hack inside the server and reveal the truth.

## Enumerate

Let’s start by checking the connection with the machine:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-8d28b6ed5cfe473862ec1304d598065b8b12abfe%2Fagentsudo0.png?alt=media" alt=""><figcaption></figcaption></figure>

We got the ping back, the TTL has a value of 63 so we are against a Linux machine probably.

Now let’s do a port scan using nmap:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-9296e74cb39a285ebd0926f8ef88aff0bf4d8359%2Fagentsudo2.png?alt=media" alt=""><figcaption></figcaption></figure>

nmap has discovered 3 open ports: 21 (FTP), 22 (SSH) and 80 (HTTP).

Now we can get more info of this ports using nmap:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-f43d266bd9830b1ab7160f75f3139f8e851a76b7%2Fagentsudo3.png?alt=media" alt=""><figcaption></figcaption></figure>

* port 21 (FTP): vsftpd 3.0.3
* port 22 (SSH): OpenSSH 7.6p1 → Ubuntu Bionic 18.04 (Launchpad)
* port 80 (HTTP): Apache httpd 2.4.29

Let’s take a look to the web page:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-17017142f5312c47c60a6aab8476a3e2bf07493e%2Fagentsudo4.png?alt=media" alt=""><figcaption></figcaption></figure>

Seems like we have to use a “codename” as user-agent. I checked the webpage source code but there is nothing interesting there.

To manipulate the user-agent parameter, I’ll intercept the web petition with BurpSuite and sent it to the Repeater:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-dc73f8a88782b0902f69fcac35ef44257c42ef7f%2Fagentsudo5.png?alt=media" alt=""><figcaption></figcaption></figure>

When I use “R” as the user-agent, I get this response:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-0aabd7a8817a4adcd222e19f79f58dc08a1175d2%2Fagentsudo6.png?alt=media" alt=""><figcaption></figcaption></figure>

Now we know that there are 25 employees.

Maybe the codename of each agent is a single letter. Let’s send the petition to the Intruder and set the payload:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-c5da6d234d3fe872ddae4c99ecfb87873f0e9570%2Fagentsudo7.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-471dd638d4b4fc8ac36807aefbb515548e1a016c%2Fagentsudo8.png?alt=media" alt=""><figcaption></figcaption></figure>

Now, let’s start the attack:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-9333cb3e02428df4c164f226328e874eda5f9548%2Fagentsudo9.png?alt=media" alt=""><figcaption></figcaption></figure>

We can see that the status code of the request with the payload “C” as user-agent is different (302) which means that the page is redirecting us to “agent\_C\_attention.php” page. Let’s take a look:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-9a24a2dd455e9ad9b49c52cfe7272c87b7d711df%2Fagentsudo10.png?alt=media" alt=""><figcaption></figcaption></figure>

## Hash cracking and brute-force

Seems to be a message sent by Agent R to Agent C telling him that his password is weak. Knowing that, let’s see if we can guess the password of “chris” username for FTP or SSH services using hydra:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-0c2477d1f29c106b61f787226a27f6dc78381d4c%2Fagentsudo11.png?alt=media" alt=""><figcaption></figcaption></figure>

First I tried with the 100 most used passwords dictionary for both FTP and SSH services. After not getting a match, I used the 1000 most common one and… we have a match!

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-6d916537f88fb17df5350f62e4060792e06bfe50%2Fagentsudo1.png?alt=media" alt=""><figcaption></figcaption></figure>

Now we have a valid credentials for the FTP service. Let’s see if it works for SSH also:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-551763cd4e68aa05c8f2e178e5a9c648bc3a5686%2Fagentsudo12.png?alt=media" alt=""><figcaption></figcaption></figure>

Nope, it doesn’t. Let’s take a look to the FTP:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-0540121ae1e0708d12cecbed371bd6ad0a265424%2Fagentsudo13.png?alt=media" alt=""><figcaption></figcaption></figure>

There are some files inside, I downloaded them all.

There are 2 images:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-1656c0654bf5f6733cc2f0ce1d50bf11e9b983af%2Fagentsudo14.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-f629a560ad640fd7b6e16759089b9645593885a8%2Fagentsudo15.png?alt=media" alt=""><figcaption></figcaption></figure>

I’ll check the EXIF info just in case:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-123d8131da7da8f76ad1737aa27d72999d60230b%2Fagentsudo16.png?alt=media" alt=""><figcaption></figcaption></figure>

Nothing seems interesting there.

Let’s check the text file:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-083b43e0c78dae82f8e866a98d00b4e9259652a3%2Fagentsudo17.png?alt=media" alt=""><figcaption></figcaption></figure>

So… There is a password and we are being asked for a ZIP password and a steg password… maybe one of this downloaded images has a zip inside it? Let’s use binwalk to investigate them further:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-155ef260290ce3568d8d92448c317de1b0f36113%2Fagentsudo18.png?alt=media" alt=""><figcaption></figcaption></figure>

The cute-alien.jpg file seems to be a normal image, but the cuttie.png has something else! Let’s extract it:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-d791da549ca97d834987316e89620ef684edbc5c%2Fagentsudo19.png?alt=media" alt=""><figcaption></figcaption></figure>

If we attempt to decompress the ZIP file, we are asked for a password:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-3c39b9ac73fb6a1a4bea09d3c75faecf261f5c84%2Fagentsudo20.png?alt=media" alt=""><figcaption></figcaption></figure>

Let’s try to use JohnTheRipper to crack the password. First we have to use **zip2john** tool, and then **john**:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-4594b445b19768ad5ba848dce40dd21a5417b1af%2Fagentsudo25.png?alt=media" alt=""><figcaption></figcaption></figure>

And we get the password! Let’s decompress the ZIP file:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-96d82b8383de372f8298c43ac9a23bae557a6903%2Fagentsudo26.png?alt=media" alt=""><figcaption></figcaption></figure>

Now we can read another message wrote by Agent R, and a code. It looks weird, so let’s use Cyberchef to check if it is encoded:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-e6e5864f778b9428b673b951268e87bee5955d88%2Fagentsudo27.png?alt=media" alt=""><figcaption></figcaption></figure>

Seems to be encoded in Base64, and decoded it shows a clear text.

Let’s try to use it as the password to decode the image cute-alien.jpg using an online tool for steganography:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-52fd094916dfd567925adb1f4f635ec9a0fa8bc1%2Fagentsudo28.png?alt=media" alt=""><figcaption></figcaption></figure>

So, it reveals a message wrote by Chris, telling James its login password, so we now have a new credentials.

Let’s see if we can connect to FTP or SSH using this credentials:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-36ff255f94a43d8d2e9095d23338f1c5cec3c887%2Fagentsudo21.png?alt=media" alt=""><figcaption></figcaption></figure>

## Capture the user flag

The credentials are not valid for FTP, but they are for SSH! Now we are logged as james at the target machine!

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-2082acd12fc578fe0b1d582e56e2aa8a263bad55%2Fagentsudo29.png?alt=media" alt=""><figcaption></figcaption></figure>

At the home folder of the current user we found the user flag and an image. Let’s download the image using **scp**:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-8568137afc443c474c171e5e065a166a1175be4b%2Fagentsudo22.png?alt=media" alt=""><figcaption></figcaption></figure>

I know that there is something related to the Rosswell incident, but after a reverse image search using tineye website, the photo is called “Rosswell Alien Autopsy”

## Privilege escalation

Now, let’s look for privilege escalation. Let’s check the sudoers first:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-baa1c49f127460f6333eb0a2903a09d672363ffc%2Fagentsudo23.png?alt=media" alt=""><figcaption></figcaption></figure>

It looks interesting, let’s search what does it mean. After a quick search it seems that the user james can execute /bin/bash as any user except as root. It also redircts me to a ExploitDB page, where I can see that there is a vulnerability (CVE-2019-14287) that allows privilege escalation:

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-8c1490e2c4668f1160d6ac0bc5a911aee4d9cb15%2Fagentsudo24.png?alt=media" alt=""><figcaption></figcaption></figure>

> Sudo doesn't check for the existence of the specified user id and executes the with arbitrary user id with the sudo priv -u#-1 returns as 0 which is root's id

As it’s explained on the exploit description, there is a vulnerability where, in this conditions where the active user can execute a bash as any other user except as root, the command `sudo -u#-1 /bin/bash` can be executed to gain a root bash.

<figure><img src="https://3648139271-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDU2KcTfFp1xEzUDMyoAe%2Fuploads%2Fgit-blob-04973011b997cd57765d9e99b252b569a583e5f9%2Fagentsudo30.png?alt=media" alt=""><figcaption></figcaption></figure>

That’s how we gain root privileges and the root flag.
