MLT

Windows Password Cracking - Breaking the NTLM Hash

MLT
Nov 10th, 2013
1,009
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.21 KB | None | 0 0
  1. ############################################################
  2. # Article: Windows Password Cracking: Breaking NTLM Hashes #
  3. # Author: MLT #
  4. ############################################################
  5. # #
  6. # BREAKING THE NTLM HASH: #
  7. # #
  8. ############################################################
  9. # T A B L E O F C O N T E N T S : #
  10. ############################################################
  11. # 1 - What is NTLM? #
  12. # 2 - How does NTLM work? #
  13. # 3 - Windows Integrated Authentication #
  14. # 4 - Pass the Hash #
  15. # 5 - NTLM Relaying Methods (including EXTERNAL relaying) #
  16. # 6 - Security Implications #
  17. ############################################################
  18.  
  19. -- What is NTLM? --
  20.  
  21. NTLM is a protocol used within windows for password storage
  22. and network authenication, NTLM hashes use MD4 encryption
  23. and when used for network authentication the hashed NTLM
  24. string is used rather than the original plaintext password.
  25.  
  26. A typical NTLM hash is case sensitive, has an unlimited length
  27. and is a stronger networking hashing algorithm than its
  28. counterpart LM network hash. NTLM is the protocol used
  29. specifically for password hashing whereas NTLM-AUTH is used
  30. for network-based remote authentication requests when interacting
  31. with services. There are various different flavours of NTLM, such
  32. as NTLM-AUTH, NTLM-V1, NTLM-V2, NTLM2, and flavours can vary based
  33. on whether they are signed or not.
  34.  
  35.  
  36. -- How does NTLM work? --
  37.  
  38. NTLM authenticates with remote services through a 'handshake' that
  39. consists of three messages being sent, known as type1, type2, and
  40. type3.
  41.  
  42. typical type1 message (handshake initiation/NTLMSSP_NEGOTIATE):
  43.  
  44. NTLMSSP identifier: NTLMSSP
  45. NTLM Message Type: NTLMSSP_NEGOTIATE (0x00000001)
  46. Flags: 0x00088207
  47. Calling workstation domain: NULL
  48. Calling workstation name: NULL
  49.  
  50.  
  51. What is happening here is that the client is interacting with the
  52. server, initiating a 'handshake' listing which flags it supports,
  53. and the name of the workstation and the domain in which it belongs
  54. to.
  55.  
  56. typical type2 message (Sever Response/NTLMSSP_CHALLENGE):
  57.  
  58. NTLMSSP identifier: NTLMSSP
  59. NTLM Message Type: NTLMSSP_CHALLENGE (0x00000002)
  60. Domain: DOMAIN
  61. Flags: 0x62818215
  62. NTLM Challenge: 1122334455667788
  63. Reserved: 0000000000000000
  64. Address List
  65. Length: 102
  66. Maxlen: 102
  67. Offset: 68
  68. Domain NetBIOS Name: DOMAIN
  69. Server NetBIOS Name: HOSTNAME
  70. Domain DNS Name: DOMAIN.TLD
  71. Server DNS Name: SEVER.DOMAIN.TLD
  72. List Terminator
  73.  
  74.  
  75. in a type1 message the server does not yet know who the person
  76. initiating the handshake is as no informantion about that has
  77. been sent (other that domain info which is not of much use).
  78. In the type2 message, the server responds with its supported
  79. flags and domain information. It also responds with the NTLM
  80. Challenge string. This string has a unique dynamic value and
  81. it is used to salt the password hash to add an extra layer of
  82. security. The client then authenticates and completes the
  83. handshake with a type3 message.
  84.  
  85. typical type3 message (final auth/NTLMSSP_AUTH):
  86. NTLMSSP identifier: NTLMSSP
  87. NTLM Message Type: NTLMSSP_AUTH (0x00000003)
  88. Lan Manager Response: 74795D4390C7DDEFB7DAD5D4373066CBF05D633F47F4F12B
  89. NTLM Response: 74795D4390C7DDEFB7DAD5D4374066CBF05D633F47F4F12B
  90. Domain name: DOMAIN
  91. User name: USERNAME
  92. Host name: HOSTNAME
  93. Session Key: Empty
  94. Flags: 0x00008205
  95.  
  96.  
  97. The NTLM response is generated due to the server challenge being
  98. hashed with the password challenge. The username and workstation
  99. name for the domain it belongs to are also sent, alongside a
  100. session key if session signing is supported for the authentication.
  101. The examples above are typical for NTLM-1, NTLM-2 is different in
  102. the sense that it uses a client challenge as a form of mitigation
  103. against attempted rainbow table attacks. NTLM-2 also has additional
  104. paramaters added into the password response.
  105.  
  106.  
  107. - Windows Integrated Authentication -
  108.  
  109. Windows integrated authentication is a method of network authentication
  110. that is used to prevent the user from having to re-enter their password
  111. when connecting to different services. For example, when you connect to
  112. a domain you are connecting to a network share and other services, but
  113. windows will not ask you to re-enter your password to authenticate the
  114. connection to each individual service, instead it just queries the API
  115. and gets the information back that is used to automatically authenticate,
  116. HTTP is used in the context of local security, "trusted site zones" are
  117. used as a form of security allowing this to only take place with a local
  118. one-word domain name. It then performs a DNS query relating to the domain
  119. name and queries the DNS hostname, then sends a broadcast request across
  120. the local network for the domain info.
  121.  
  122.  
  123. - Pass The Hash -
  124.  
  125. Pass The Hash is a well known attack-vector that exploits NTLM by allowing
  126. the attacker to successfully authenticate to a remote service without needing
  127. the plaintext password, it instead authenticates using the NTLM hash. This
  128. bypasses the need to crack the NTLM hashes in order to require the password, as
  129. it allows practically the same level of access that would be obtained by doing so.
  130. This attack generally is used after the hashes have been obtained from local storage
  131. within volatile memory (for example the result of a cold-boot attack). The problem
  132. with this attack method is that it generally requires local admin access on the
  133. system so that the level of privelege escalation isn't much.
  134.  
  135.  
  136. - NTLM Relaying + Methods -
  137.  
  138. NTLM relaying is a less-known attack method which does not require existing admin
  139. access to be performed, but instead can be performed from a guest account as long
  140. as a connection can be made to the network on which the attack is being performed.
  141. An issue with NTLM as shown within the packet handshake is that there is no kind
  142. of verification that the destination host is the host that you are supposed to
  143. authenticate to, yet the authentication is made anyway. NTLM Relaying works by
  144. setting up a rogue server which takes in the authentication requests and relays
  145. them to another target server. In 2008 windows patched the vulnerability where an
  146. attacker could bounce an NTLM request back to themselves (via SMB or even telnet
  147. through the use of the IE telnet:// exploit), but due to the way that the protocol
  148. is designed they could still be bounced to other hosts. There are many different
  149. protocols in which NTLM can be relayed to, besides the obvious protocols which are
  150. affected such as SMB and HTTP, other protocols include MSSQL, LDAP, RDP, PPTP, and
  151. many other protocols.
  152.  
  153. In order to exploit NTLM efficiently using this method, a HTTP and SMB Rogue Server
  154. needs to be setup on a remote connection. The rogue server needs to keep the user
  155. authenticating as much as possible (rather than disconnecting after a single auth,
  156. on Windows LAN for SMB you can make it authenticate around 30 times in total before
  157. terminating the connection). In order to do this we need to figure out who the user
  158. is in order to keep them authenticating (something which generally isn't known until
  159. the type3 handshake response). This can sometimes be tricky to do, as within SMB the
  160. source IP and Port is not enough information if the attack is being performed externally,
  161. within HTTP, WPAD and similar requests do not always support cookies. The rogue HTTP
  162. server should use a HTTP-302 Redirect with Keep-Alive in order to keep the socket open,
  163. preventing the ession from closing, meaning that once the authentication is complete, we
  164. know who the target user is for the rest of that session due to the connection remaining
  165. open. As for controlling authentication with the rogue SMB server before bouncing them
  166. to other services, some payloads need to be added. WPAD implementation is a must as it
  167. will check DNS and then check broadcasting to the network. By default Windows will
  168. automatically authenticate to the WPAD sever over HTTP using the currently logged in
  169. user credentials which can then be spoofed and responded to (although there are limitations
  170. as you would have to typically be internal to the network or would have to spoof NBNS or DNS).
  171.  
  172. Social Engineering can be used by including a UNC network path within image tags for example,
  173. the browser would automatically connect back to windows and then authenticate with the network
  174. share and attempt to grab the image or whatever it may be, ranging from javascript to iframes.
  175. Some browsers attempt to mitigate this by checking to see whether the network share is within
  176. the file security context - this can easily be bypassed by setting headers for a forced download,
  177. which is then opened from the download location resulting in access to the file security context
  178. which will lead to automatic authentication to the SMB share which will then authenticate to the
  179. rogue server. There are still problems with this method as it relies on the victim downloading
  180. something, although a way around these problems are the use of commonly-used browser plugins in
  181. order to establish the authentication to the rogue server via SMB. Common plugins such as iTunes
  182. and Quicktime are easily affected as you can create a playlist with a UNC network path which will
  183. automatically authenticate and bypass the local security context.
  184.  
  185. Another method that can be used for automatic authentication to the rogue server is through the
  186. use of vulnerable email clients. For example if an HTML email which contains a network share
  187. is read using Outlook then it will automatically authenticate. desktop.ini files can also be
  188. generated to say that the icon resource or wallpaper for that folder is a network share, resulting
  189. in automatic authentication with the credentials, this method also works with .lnk files.
  190.  
  191. The final method I will cover that can be used for automatic authentication to the rogue
  192. server is the traditional man-in-the-middle attack used to redirect NTLM-AUTH requests or to
  193. inject the HTML content previously covered into webpages viewed by the victim.
  194.  
  195.  
  196. -- Security Implications --
  197.  
  198. Within MSSQL:
  199. - Potential database access (read, write, modify, etc..)
  200.  
  201. Within SMB:
  202. - Enumerate users/groups
  203. - Access File Shares
  204. - Execute Commands
  205. - Cannot connect to Domain Controllers unless SMB Signing bypass is written
  206.  
  207. LDAP:
  208. - Emumerate domain users/group memberships
  209. - Change Passwords
  210. - Add users to groups
  211. - Relay domain admin to user workstation
  212. - Authenticate to Domain Controller
  213.  
  214. Exchange Web Services (used by most organisations, allowing external NTLM relaying):
  215. - Get email contacts
  216. - Setup email rules
  217.  
  218. Vulnerable Systems:
  219.  
  220. NTLM is used by default in all versions of windows, including windows 8 and
  221. windows 2012. It is also used massively within corporate environments.
  222. Many protocols are vulnerable (practically any vulnerable that has NTLM support
  223. is vulnerable to local NTLM relaying and certain protocols are even vulnerable
  224. to external NTLM relaying using some of the described methods).
Advertisement
Comments
  • Comment was deleted
Add Comment
Please, Sign In to add comment