Blogs & Stories

SpiderLabs Blog

Attracting more than a half-million annual readers, this is the security community's go-to destination for technical breakdowns of the latest threats, critical vulnerability disclosures and cutting-edge research.

Tutorial for NTDS goodness (VSSADMIN, WMIS, NTDS.dit, SYSTEM)

I recently performed an internal penetration test where the NTDS.dit file got me thousands of password hashes. After compromising unpatched Microsoft Windows computers on the client's domain, I gained access to a number of domain accounts. Below I'll explain how I did it.

The client had two domain controllers, one Windows 2003 and one Windows 2008. One of the domain accounts obtained via other means (not described by this post) had rights to log-on locally on both domain controllers.

I attempted to dump the Active Directory database, but I couldn't get the SAM file through my usual methods. Eventually, and after much effort, I got the SAM file but found it only contained one hash.

The following actions allowed me to obtain the Active Directory password hashes. This method will work on Windows 2003, Windows 2008 and Windows 2012 servers.

The NTDS.dit file is the Active Directory database. It stores all Active Directory information including password hashes.

I recreated the scenario, to demonstrate it on a Windows 2012 server.

Screen Shot 2013-11-06 at 10.55.47

There are various ways of accessing the NTDS.dit file. It can't just be copied when it is in use (similar to a SAM file).

A technology that is included in Microsoft Windows itself is the Volume Snapshot Service or Volume Shadow Copy Service. It requires the partition to run NTFS, and it is the same technology used to
create a Windows backup or automatic system restore point.

The command line utility I used was VSSADMIN.

The command determines whether there are current volume shadow copies that exist or if we need to create one:

Screen Shot 2013-11-06 at 10.56.14

As you can see, no shadow copy existed yet. So I created one.

The default path is c:\windows\ntds\ntds.dit. But it could be on any other drive, for example I found it on d:\NTDS\ntds.dit in my test.

Screen Shot 2013-11-06 at 10.56.57

I also created the SYSTEM file in path c:\windows\system32\.

Screen Shot 2013-11-06 at 10.58.50

A shadow copy of the c: drive had been created.

Screen Shot 2013-11-06 at 10.59.43

Next I copied the NTDS.dit file to a place where it could be retrieved on the main (non-shadowed) drive.

Screen Shot 2013-11-06 at 11.01.47

Then I did the same with the SYSTEM file.

Screen Shot 2013-11-06 at 11.02.43

The two files were then copied to the root of the c: drive.

Screen Shot 2013-11-06 at 11.03.18

I used Kali 1.0.5 as my attack platform.

Screen Shot 2013-11-06 at 11.13.19

To use the mount command to mount to the default Windows share, I needed cifs-utils on Kali.

Screen Shot 2013-11-06 at 11.37.41

Then I mounted the network share.

Screen Shot 2013-11-06 at 11.41.30

Next I copied the two files to the attack system.

Screen Shot 2013-11-06 at 11.42.12

This can be done remotely without interactively logging-on to the server by using the "wmic" command from any Windows computer. Kali's WMIS package allowed me to do the same.

Screen Shot 2013-11-06 at 16.19.28

Next, I ran the VSSADMIN command to list shadows remotely with WMIS.

Screen Shot 2013-11-06 at 16.28.32

Next I checked the output.txt file to see what happened.

Screen Shot 2013-11-06 at 16.55.04

Then I checked that the root was empty and deleted the previous NTDS.dit and SYSTEM files I copied.

Screen Shot 2013-11-06 at 17.38.56

I copied the NTDS.dit file, using WMIS.

Screen Shot 2013-11-06 at 17.03.07

Note that the shadow copy folder has three slashes ('\\\').

Next I copied the SYSTEM file using WMIS.

Screen Shot 2013-11-06 at 17.04.24

Then I checked whether the files were copied on the previously mounted drive.

Screen Shot 2013-11-06 at 17.04.51

My next step was to get the password hashes.

First I needed to download and unzip ntdsxtract_v1_0.zip from http://www.ntdsxtract.com/.

Screen Shot 2013-11-06 at 11.43.07

Screen Shot 2013-11-06 at 12.17.28

Second, I needed to download and unzip ntds_dump_hash.zip from http://www.ntdsxtract.com/.

Screen Shot 2013-11-06 at 12.16.59

Screen Shot 2013-11-06 at 12.18.11

Then I compiled and made libesedb.

Screen Shot 2013-11-06 at 12.19.32

Screen Shot 2013-11-06 at 12.21.45

Here I exported tables from NTDS.dit, using the command esedbdumphash.

Screen Shot 2013-11-06 at 12.30.15

Other information could also be exported using esedbexport, but I was only interested in Table 4 where the password hashes are.

Screen Shot 2013-11-06 at 15.04.55

This took some time and resulted in the creation of a folder called ntds.dit.export containing a file called datatable.

Screen Shot 2013-11-06 at 15.19.12

Then I went to the creddump folder to run the dsdump python script.

Screen Shot 2013-11-06 at 15.21.16

Screen Shot 2013-11-06 at 17.22.16

From there, I could output the hashes into a file and use my favorite password-cracking tool to recover the passwords.