JerryTok

Description

Welcome to JerryTok, your portal to the nearest jerryboree, where mediocrity is celebrated! Dive into the daily escapades of the wonderfully average, from mundane mishaps to modest triumphs. Share your moments, connect, and laugh as you find glory in the ordinary. Join now and embrace the delightfully dull at your local jerryboree!

Source

entrypoint.sh

#!/bin/ash

# Secure entrypoint
chmod 600 /entrypoint.sh

# Secure PHP Installation
mkdir -p /etc/php82/conf.d
mkdir -p /run/apache2

echo "disable_functions = exec, system, popen, proc_open, shell_exec, passthru, ini_set, putenv, pfsockopen, fsockopen, socket_create, mail" >> /etc/php82/conf.d/disablefns.ini
echo "open_basedir = /www" >> /etc/php82/conf.d/openbdir.ini

# Run supervisord
/usr/bin/supervisord -c /etc/supervisord.conf

src/Controller/DefaultController.php

Solution

JerryTok.png

The default controller class allows us to pass parameter location which is later rendered as template string.

https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection#twig-phparrow-up-right

SSTI is confirmed:

SSTI works, but we can't use system commands because they are disabled (entrypoint.sh)

The Apache server has cgi-bin enabled.

cyberlibrary.fr > disable_functions bypass - mod_cgiarrow-up-right

ctf flask SSTI template injection payload classification listarrow-up-right

I wasn't able to get cgi-bin to work and most probably it's because of "open_basedir = /www" restriction, meaning we can't write anything outside /www

Note: Checking the directory via Docker showed that it didn't exist? or this location was correct /var/www/localhost/cgi-bin, but it wouldn't update scripts.

official docsarrow-up-right says that ScriptAlias /cgi-bin /usr/bin is the location of cgi binaries that can be executed, but basedir prevents that.

Most system commands are disable, by PHP has tilde just like bash which can be used to bypass the filters. Upload the webshell:

Oddly enough this works on local instance, but not remote... wot...

The file is definitely written, but it's not able to execute on Remote

Back to CGI thingy, in the docs I saw .htaccess tutorial

Pasted_image_20240907194421.png

.htaccess files provide a way to make configuration changes on a per-directory basis. srcarrow-up-right

JerryTok-2.png

Note: 0o777 in integer is 511 for chmod.


Second way is to use mb_send_mail for RCE 👀

Last updated