1
+ <#
2
+ ScipUtilities provides various utility commandlets.
3
+
4
+ Author: Eleanore Young, Michael Schneider, scip AG
5
+ License: MIT
6
+ Copyright: 2017 Eleanore Young, Michael Schneider, scip AG
7
+ Required Dependencies: None
8
+ Optional Dependencies: None
9
+ #>
10
+
11
+ # Requires -Version 2
12
+ Set-StrictMode - Version 2
13
+
14
+ function Select-MimikatzPasswords {
15
+ <#
16
+ . SYNOPSIS
17
+ Extract passwords or password hashes from Mimikatz log files. Developed for Mimikatz version 2.0 alpha.
18
+
19
+ . PARAMETER Path
20
+ Choose the path or GLOB pattern that tells the function which files to search.
21
+
22
+ . PARAMETER FindData
23
+ Choose to look for either passwords or hashes (ntlm and sha1).
24
+
25
+ . PARAMETER OutputTo
26
+ Output the results either to the console, to a format parseable in hashcat, or to CSV.
27
+ #>
28
+ [CmdletBinding ()]
29
+ Param (
30
+ [ValidateNotNullOrEmpty ()]
31
+ [String ]
32
+ $Path = " *.log" ,
33
+
34
+ [ValidateSet (" passwords" , " ntlm" , " sha1" )]
35
+ [String ]
36
+ $FindData = " passwords" ,
37
+
38
+ [ValidateSet (" console" , " hashcat" , " csv" )]
39
+ [String ]
40
+ $OutputTo = " console"
41
+ )
42
+
43
+ $PasswordRegex = " \s+\*\sUsername\s+:\s(?<username>[a-zA-Z0-9]+)[\r\n]+\s+\*\sDomain\s+:\s(?<domain>[a-zA-Z0-9]+)[\r\n]+\s+\*\sPassword\s+:\s(?<password>(?!\(null\)).*)[\r\n]+"
44
+ $HashRegex = " \s+\*\sUsername\s+:\s(?<username>[a-zA-Z0-9]+)[\r\n]+\s+\*\sDomain\s+:\s(?<domain>[a-zA-Z0-9]+)[\r\n]+\s+\*\sFlags\s+:\s.*[\r\n]+\s+\*\sNTLM\s+:\s(?<ntlm>[0-9a-fA-F]+)[\r\n]+\s+\*\sSHA1\s+:\s(?<sha1>[0-9a-fA-F]+)[\r\n]+"
45
+
46
+ $PasswordOutput = New-Object System.Collections.Generic.List[System.Object ]
47
+ $HashOutput = New-Object System.Collections.Generic.List[System.Object ]
48
+ Foreach ($LogFile in Get-ChildItem - Recurse $Path ) {
49
+ $Content = Get-Content - Raw - Path $LogFile
50
+ $PasswordMatches = Select-String - InputObject $Content - AllMatches - Pattern $PasswordRegex
51
+
52
+ Foreach ($Match in $PasswordMatches.Matches ) {
53
+ $SearchEntry = New-Object System.Object
54
+ $SearchEntry | Add-Member - NotePropertyName " Username" - NotePropertyValue $Match.Groups [" username" ].Value
55
+ $SearchEntry | Add-Member - NotePropertyName " Domain" - NotePropertyValue $Match.Groups [" domain" ].Value
56
+ $SearchEntry | Add-Member - NotePropertyName " Password" - NotePropertyValue $Match.Groups [" password" ].Value
57
+ $PasswordOutput.Add ($SearchEntry )
58
+ }
59
+
60
+ $HashMatches = Select-String - InputObject $Content - AllMatches - Pattern $HashRegex
61
+ Foreach ($Match in $HashMatches.Matches ) {
62
+ $SearchEntry = New-Object System.Object
63
+ $SearchEntry | Add-Member - NotePropertyName " Username" - NotePropertyValue $Match.Groups [" username" ].Value
64
+ $SearchEntry | Add-Member - NotePropertyName " Domain" - NotePropertyValue $Match.Groups [" domain" ].Value
65
+ $SearchEntry | Add-Member - NotePropertyName " NTLM" - NotePropertyValue $Match.Groups [" ntlm" ].Value
66
+ $SearchEntry | Add-Member - NotePropertyName " SHA1" - NotePropertyValue $Match.Groups [" sha1" ].Value
67
+ $HashOutput.Add ($SearchEntry )
68
+ }
69
+ }
70
+
71
+ $PasswordOutput = ($PasswordOutput | Sort-Object - Property Username - Unique)
72
+ $HashOutput = ($HashOutput | Sort-Object - Property Username - Unique)
73
+
74
+ if ($OutputTo -eq " csv" ) {
75
+
76
+ if ($FindData -in (" ntlm" , " sha1" )) {
77
+ $HashOutput | ConvertTo-Csv - NoTypeInformation
78
+ } elseif ($FindData -eq " passwords" ) {
79
+ $PasswordOutput | ConvertTo-Csv - NoTypeInformation
80
+ } else {
81
+ throw " Format '$FindData ' doesn't make sense for CSV output."
82
+ }
83
+ } elseif ($OutputTo -eq " hashcat" ) {
84
+ if ($FindData -eq " ntlm" ) {
85
+ Foreach ($Entry in $HashOutput ) {
86
+ $Entry.Username + " :" + $Entry.NTLM
87
+ }
88
+ } elseif ($FindData -eq " sha1" ) {
89
+ Foreach ($Entry in $HashOutput ) {
90
+ $Entry.Username + " :" + $Entry.SHA1
91
+ }
92
+ } else {
93
+ throw " Format '$FindData ' doesn't make sense for hashcat output."
94
+ }
95
+ } else {
96
+ if ($FindData -eq " passwords" ) {
97
+ $PasswordOutput
98
+ } else {
99
+ $HashOutput
100
+ }
101
+ }
102
+ }
0 commit comments