Showing posts with label passwords. Show all posts
Showing posts with label passwords. Show all posts

Wednesday, July 3, 2013

Get-GPPPassword Redux

Its been over a year since I threw together the original Get-GPPPassword on a short flight and I was really having a hard time even looking at the code. In addition to a nagging bug, it needed to be rewritten and updated to include all the great recommendations from you guys. Its amazing how often I still see local passwords being enforced with Group Policy preferences. For some reason it actually feels like the problem is getting worse even with Microsoft's blatant warnings in Server 2012. The other issue that I have seen is that when administrators stop using preferences, the old XML file is not deleted. On more than one engagement I have found an old password which helped me guess the current one. We need to keep hammering at this poor practice.

Additionally, one of the things that jumped out at me while reworking this script is the simplicity of this task in PowerShell. Compared to accomplishing the same task in Ruby, PowerShell's XML parsing really gives it an edge. A lot of security professionals could benefit by spending a few days to learn it and Carlos Perez is teaching an awesome class at Derbycon!

Updates:

General flow, performance and bug fixes including better error handling and a fix for the problem with how the base64-encoded string was being padded.

Support for parsing not only groups.xml,  but also scheduledtasks.xml, services.xml and datasources.xml. The original post that inspired me to write the function appears to be down, but there have been other posts that point out that passwords can be stored in other Group Policy preference files as well. I attempted to create each one of those XML files and created logic for the 4 that seem used.

Ryan Ries pointed out that the script could easily be pointed at the domain controller which removes the need for any parameters and makes the script easier to run:


I broke out the decryption function (Get-DecryptedCPassword) If you want to decrypt a password offline, you can use that.

As always, the most current version of the Get-GPPPassword is available from the PowerSploit Github page. Thanks for reading, keep the comments and recommendations coming and join Skip Duckwall and I at BlackHat where we will briefly discuss Group Policy preferences in relation to the Pass-the-Hash attack with practical mitigation techniques.

-Chris

Monday, June 11, 2012

SHA-1 Password Cracking

In the last week, there have been several major compromises resulting in the leak of password hashes to the internet.  Some of the major sites that were hit are Linkedin, Eharmony and Last.fm. Although there are many others that have cracked more than I have or will, armed with an older video card and an extra laptop I was able to crack around 3 million of the exposed SHA1 hashes utilizing Hashcat,  John and dictionaries that I have collected over the years.  The professionals at KoreLogic tweeted this within a day of the hashes being released:



If you would like to safely check to see if your password was included in the Linkedin compromise, you can download the file "combo_not.txt".  I believe it is probably still being hosted in a few places but you'll probably have to do a bit of searching to find it.

I threw together a PowerShell function for others to check to see if their passwords were included.  It is horribly slow and could definitely be improved, but I don't think it will be useful for long.  I really don't like the idea of utilizing any online look-up services (despite the obvious speed benefit from storing the data in a true database) because of the obvious social-engineering implications.


Get-LNPasswordMatch
A special version of Hashcat was released to handle the zeroed hashes which paired with a large dictionary is very effective:


The Hashcat syntax can be tricky, but there is a lot of great documentation out there.


Next, I reran the same dictionary with a mangle rule in John which got quite a few of the longer passwords due to the 15 character limitation imposed by CudaHashcat.  There are lots of usage guides and cheat-sheets out there for John.



The final result was over 3 million hashes cracked in less than 24 hours. KoreLogic has been able to crack 4.92 million in just a few days so it seems that very few of the original passwords are safe: 


I recommend using the publicity around these major breaches to remind your managers, users, friends and family about passwords.  The following is what I try to stress, but there are certainly lots of other great ideas on how to improve password security:

1. Never reuse passwords between web sites or systems.
2. Change your passwords as often as its reasonable.
3. Choose longer passwords such as  (complex) passphrases to increase the difficulty of cracking.
4. Have a plan to quickly and securely change your passwords if they become compromised.
5. Consider a common password manager for web sites.
 
Finally, since there aren't public details as to how Linkedin was compromised, its safe to assume that they are still compromised or could be again.  Take that into consideration when you are planning on how to change your passwords.  Even if Linkedin takes steps to properly salt the hashes, its not unreasonable to think that they could be quickly cracked again.

***Update 16 June 2012***
Changed the name of the function to be inline with the PowerShell way.  Changed the way to the password is read in to be more secure as requested by the first comment below. 


-Chris

Thursday, May 24, 2012

GPP Password Retrieval with PowerShell

Last week, I read a great post entitled "Exploiting Windows 2008 Group Policy Preferences" that I wish I saw sooner.  The article included a nice Python script to accomplish the task of decrypting passwords that were set using the GPP feature in Windows 2008 domains.  However, it looked like something that would be handy to have in a PowerShell script.  Before I continue, I would like to point out the updated disclaimer, it certainly applies to this post.

You should read the original article, but the quick summary is that its possible for any authenticated user (this includes machine accounts) on the domain to decrypt passwords that are enforced with Windows 2008 Group Policy Preferences.  From my experience, this practice is common for larger domains which need to set different local administrator ("500" account) passwords for different OUs.

Python is an excellent scripting language, but PowerShell has two notable advantages in this specific use-case.  First, PowerShell does not require any additional libraries since it has access to the entire .NET framework.  Second, PowerShell is installed by default on all modern Windows systems to include Windows Server 2008 so it can be used right from the machine you are on.

The following Get-GPPPassword PowerShell script can be used by penetration testers to elevate to local administrator privileges (on your way to Domain Admin) by downloading the "groups.xml" file from the domain controller and passing it to the script.  The files are typically found in:

\\domain\SYSVOL\domain\Policies\{*}\Machine\Preferences\Groups\Groups.xml

Get-GPPPassword (Use Updated Version)


To run the function, just copy and paste the text into powershell and type 'Get-GPPPassword'. This will in effect bypass the ExecutionPolicy.

Writing this script ended up not being as easy as I originally thought mostly due to never dealing with .NET and crypto before.  I would like to thank Matt Graeber for solving the null IV issue, Mike Santiago for general code improvements and of course Emilien Giraul (and the Sogeti ESEC Pentest team for their detailed writeup).



Try it out and let me know what you think.

***Update 26 May 2012***
You can also download the maintained version of the script from the PowerSploit repository on GitHub.  It already has some great scripts for Windows post-exploitation on it!

***Update 16 June 2012***
Updated the script block with the improvements from Matt Graeber.  Matt wrapped it into a function and apparently saved a puppy by creating a new object (avoiding the use of write-host).

***Update 3 July 2013***
I have reorganized and rewritten the script. You can find the updated version and read about it here.
-Chris

Wednesday, May 9, 2012

PowerShell Password Fun

Yesterday, there was a bit of hype about five pastebin posts that appeared to be 55K twitter usernames and passwords.  The passwords turned out to be old, repetitive and mostly available in other dumps. However, as explained in a previous post, all passwords are important.

Here are the links in case you would like to look at them:


In order to analyze these passwords, I downloaded the five lists into a single file named twitter_passwords.txt.  Next, I used the following PowerShell one-liner to output the more complex passwords in the list:

((gc .\twitter_passwords.txt | %{$_.split(':')[1]} | sort -unique) -cmatch "^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]).{10,50}$")


First, we use the get-content cmdlet (gc is an alias) to pipe the contents of twitter_passwords.txt to foreach ("%" is an alias) which is splitting based on ":".  The results are then sorted with only unique strings (this should be moved to the end for larger lists to avoid the issues described here).  The next bit uses regular expressions to trim the list to those strings that are at least 10 characters (less than 50) with at least one upper, one lower, one number and a special character. Thanks Matt for suggesting the use of hex to save a lot of time and headache.

The disappointing output:
88455036.Ass
Bolinha@2008
Bruno&58236280
Cristal!89
F@tern2010
FLLAvyio@123
Frida2009$
Luis_carlos9
Mayr@2829
UNC**lab2007

Looking at these passwords, the only useable pattern that jumps out is the use of years.  I added them to my dictionary, but hopefully the one-liner is useful in the future.  Of note, some applications like OpManager don't allow special characters in passwords so this list might be useful.

-Chris

Tuesday, February 28, 2012

Password Porn

Large password leaks are important for security professionals to study.  Aside from the struggle to create your own passwords, analyzing them can provide insight into how people create passwords. I am surprised at the number of people who don't realize these types of leaks affect them or their organization.
  
One recent leak was especially noteworthy because it involved plaintext passwords.  Plaintext passwords are extremely easy to analyze.  It did not take long for analysis to be done on the leaked credentials and powerful visual graphs to be released.

Even though there has been a considerable amount of work done on these accounts, most of it doesn't apply directly to me.  I (hopefully) don't assess organizations that would ever allow 99% of the passwords found in online dumps.  For that reason, I like to weed out the simple passwords and look at the complex ones (<1%) for discernible patterns.

A friend of mine has been talking this concept up for what seems like years. As I have seen his dictionaries consistently crack over 50% of complex NT domain hashes, I have become a believer. We apply these same concepts to all passwords that are found.  Passwords found in a random text document in one organization can help you crack hashes in another.

Hashes don't need to be cracked (they can be passed), but there is nothing like including a graph that shows how quickly they were cracked.  Also, there is no way to use old hashes to figure out what a new hash will be.  Passwords with a discernible pattern equate to months or years of persistent access which is a concept that is easy to explain to most C-level decision-makers.


The first step in this case is to get to the actual passwords. For our purposes, we don't really care about tying the passwords to any other information.  The leak is just a bunch of log files:


Disclaimer: I am using PowerShell for the sake of using PowerShell.  The cmdlets that I chose to use really aren't suited for handling large data sets and I am by no means an expert.  If you plan on querying the raw data more than once, you should probably create a database.  If you don't have at least 8Gb of RAM, I would not recommend using the "Sort-Object -Unique" like I do below.  It would probably be a good idea to save any other work to be safe.

Lets look at how the log files are structured so that we can trim them:


So it seems pretty safe to target the lines with "password=" in them.  We can pipe the contents of the log files through "Where-Object -match":

PS> get-content *.log | where {$_ -match "password="} > where.txt


After a few minutes (hours) we are down to 5,836,719 lines that contain the string "password=" and a potential password.  Next we need to cut out the passwords.

PS> get-content ./where.txt | foreach{$_.split('=')[1]} > cut.txt



I am trying to avoid the use of aliases for those that are unfamiliar with PowerShell.  I found it easier to learn the actual cmdlet names before using aliases.  We are piping the contents of the file into a foreach loop (typically expressed with the "%" alias) using the pipeline ($_) and the split method with '=' as the argument. We want the second field, so we use [1] (array starts at 0).  I chose "=" for simplicity's sake, but it will affect the accuracy of the final list.

Now we have a list of all the passwords, but the list contains a large amount of duplicates.  It is easy to sort by unique lines with PowerShell using the "Sort-Object" cmdlet with the "-unique" argument, but PowerShell doesn't do any of this voodoo so you will see a major spike in memory usage as it reads all of those objects and methods into memory. If you do decide to do this (you were warned), just exit PowerShell to get your RAM back.

PS> get-content ./cut.txt | sort -unique > unique.txt


At this point, I part ways with Windows and PowerShell (UPDATE: You don't have to!) to use a great tool included with THC-Hydra.  Pw-Inspector can be used to trim this list to only the passwords that meet our complexity requirements (thanks Matt).  Once we have transferred the files to our Linux distro, we need to convert the files from Unicode (thanks Skip):

# strings -el unique.txt > youpornpasswords.txt

Now we can pipe them into pw-inspector to see what meets a generic complexity rule-set:

# cat youpornpasswords.txt | pw-inspector -m 12 -l 2 -u 2 -p 2 > youporncomplex.txt

If you want to save some time, a similar list is on pastebin.

I don't have time to write about every password trend, but let's look at a few examples and see if we can find anything useful:

!QAZ@WSX1qaz2wsx

This is a typical waterfall keyboard pattern.  These patterns are actually quite commonly used by administrators.  They are easy to remember and meet the most stringent complexity requirements.  What people (who use these patterns) don't realize is that it's quite simple to generate a dictionary which includes most keyboard patterns.  There is a perl script which can be piped directly into John to test for this. A friend of mine wrote a similar script to generate nearly every 2x2, 3x3, 4x4, 5x4 keyboard pattern and piped them into several sizable dictionaries.  They are surprisingly effective on administrative and service account hashes.  

!@#123QWEqweASDasd     --This is a 3 character pattern
!@QWASZX12qwaszx          --This is a 2 character pattern
!QAZ@WSX1qaz2wsx          --This is a 4 character pattern

Lets look at some other patterns that can be used to generate useful dictionaries with simple changes to the layout array:

6yhnji9)IJNHY&                     --This is a V pattern
A!S@D#F$g5h6j7k8               --This is a variation of the 2 character pattern

Dictionaries based on the word "password" have always been effective.  The following two examples would most likely already be included in a substitution, toggle and append dictionary with the word "password":

PA$$word4321
PASSW0rd1234!@#$

A good example of the types of passwords I am looking for is:

Amanda161083**                  --NameDate**

This password only has one capital letter, but with a last name it would have 2.  I added this pattern to my list to generate at some point later.

Another interesting pattern:

PUmpkins2@2@2@        --Dictionary word with first 2 letters UC, 1 character pattern

This type of password can be the most significant when dumping hashes and histories from a large domain.  This user "may" utilize "PUmpkins3#3#3#" next.  Knowing a user's future password equates to months of possible access to a domain.

There are lots of other interesting patterns, but realize that every string that we pulled out wasn't an actual valid password.  Many of the logs were generated with errors, but it would be interesting if people were actually using their email address as their password or "www..youporn.com."

Please comment if you see anything I missed or have any questions.

-Chris