forked from securityjoes/MasterParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMasterParser.ps1
More file actions
221 lines (164 loc) · 5.9 KB
/
MasterParser.ps1
File metadata and controls
221 lines (164 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
param(
# Options
[Parameter(Mandatory = $true)]
[ValidateSet('Start','Menu','Update','Purge')]
[string]$Option,
# Type
[Parameter(Mandatory = $false)]
[ValidateSet('All','Raw','Statistics')]
[string]$Type
)
if ($Option -eq 'Start' -and -not $Type) {
Write-Output ""
Write-Output "[!] You cannot run MasterParser without choosing a -Type option."
Write-Output ""
Write-Output "[!] This is your -Type value options: ( All / Raw / Statistics )"
Write-Output ""
Write-Output "[!] If you don't know what to choose, view the the MasterParser Menu."
Write-Output ""
Write-Output "[!] View the Menu like this: .\MasterParser.ps1 -Option Menu"
Write-Output ""
$Type = Read-Host "What -Type do you choose to run"
if ($Type -match "All" -or $Type -match "Raw" -or $Type -match "Statistics") {
}
else {
Write-Output "[!] You clearly don't know what you doing."
Write-Output ""
Write-Output "[!] Please view the Menu before executing MasterParser again."
Write-Output ""
Write-Output "[!] You can view the Menu like this: .\MasterParser.ps1 -Option Menu"
Write-Output ""
exit
}
}
# current script version
$CurrentVersion = "v2.4"
# tool running path.
$RunningPath = Get-Location
# Dot Sourcing -> 00-Banner.ps1
. "$RunningPath\03-Options\00-Banner.ps1"
# space
Write-Output ""
switch ($Type) {
'All' {
$TypeFlag = "All"
}
'Raw' {
$TypeFlag = "Raw"
}
'Statistics' {
$TypeFlag = "Statistics"
}
}
switch ($Option) {
'Start' {
# HashTable to store all the $Log names that was analysed by the ParserMaster
$AnalysedLog = @{}
# HashTable to store all the $Log names that are not supported by ParserMaster
$UnsupportedLog = @{}
# Log Types HashTable.
$LogTypeList = @{
'Auth.Log' = 'Empty'
}
# variable to store all the files under 01-Logs folder.
$Logs = Get-Item -Path "$RunningPath\01-Logs\*" | Select-Object -ExpandProperty Name
# variable to store 0 in it.
$LogFileCount = 0
# iterate file names under 01-Logs.
foreach ($Log in $Logs) {
# clean the flag in each foreach iteration
$WasExtracted = $null
# each $Log add 1 to $LogFileCount flag.
$LogFileCount++
# foreach statment to iterate on each key under $LogTypeList hashtable.
foreach ($Key in $LogTypeList.Keys) {
# clean this flag each iteration
$WasExtracted = $null
# statment to execute if a log file under 01-Logs was found uner $LogTypeList hashtable.
if ($Log -match $Key) {
# execute this on .gz files.
if ($Log -like "*.gz") {
# flag to state that the log was extracted from a GZip
$WasExtracted = "True"
# Save GZip file name in a variable
$GZipName = $Log
# Specify the .gz file paths
$archivePath = "$RunningPath\01-Logs\$Log"
$destinationPath = "$RunningPath\01-Logs\"
# Create a FileStream to read the .gz file
$fileStream = [System.IO.File]::OpenRead($archivePath)
# Create a GZipStream to decompress the file
$gzipStream = New-Object IO.Compression.GZipStream $fileStream,([IO.Compression.CompressionMode]::Decompress)
# Create a FileStream to write the decompressed data to
$destFilePath = Join-Path $destinationPath (Get-Item $archivePath).BaseName
$destFileStream = [System.IO.File]::Create($destFilePath)
# Copy data from the compressed stream to the destination file
$gzipStream.CopyTo($destFileStream)
# Close the streams
$gzipStream.Close()
$fileStream.Close()
$destFileStream.Close()
# End of GZip Extraction
# execute MasterParser on the GZip output file.
$Log = $Log -replace '\.gz',''
. "$RunningPath\02-LogModules\$Key\$Key.ps1"
$LogMatchFlag = "True"
# add log names to this hashtable list
$AnalysedLog[$Log] = "- $Log [Seconds: $($AuthLogTimeInSeconds)] (Extracted From: $GZipName)"
}
# execute this on non .gz files.
else {
. "$RunningPath\02-LogModules\$Key\$Key.ps1"
$LogMatchFlag = "True"
# add log names to this hashtable list
$AnalysedLog[$Log] = "- $Log [Seconds: $($AuthLogTimeInSeconds)]"
}
}
# execute if the the $Log name is not found under $LogTypeList hashtable list
else {
$UnsupportedLog[$Log] = "- $Log"
}
}
}
# if statment to write message if 01-Logs is empty.
if ($LogFileCount -eq 0) {
Write-Output "Logs Folder is Empty"
Write-Output "+------------------+"
Write-Output "[!] Error: Folder -> $RunningPath\01-Logs is empty!"
Write-Output "[!] Insert logs into the '01-Logs' folder for the MasterParser to function properly."
Write-Output ""
}
else {
# print the hashtable of logs that been analyzed by MasterParser
Write-Output "List of Successfully Analyzed Logs"
Write-Output "+--------------------------------+"
$AnalysedLog.Values
Write-Output ""
}
# statment to execute if a log file under 01-Logs NOT found uner $LogTypeList hashtable.
if ($UnsupportedLog.Values.Count -ge 1) {
Write-Output "List of Unsupported Logs"
Write-Output "+----------------------+"
$UnsupportedLog.Values
Write-Output ""
}
}
'Update' {
# Dot Sourcing -> 01-Update.ps1
. "$RunningPath\03-Options\01-Update.ps1"
# stop the script here
exit
}
'Menu' {
# Dot Sourcing -> 03-Menu.ps1
. "$RunningPath\03-Options\03-Menu.ps1"
# stop the script here
exit
}
'Purge' {
# Dot Sourcing -> 03-Menu.ps1
. "$RunningPath\03-Options\04-Purge.ps1"
# stop the script here
exit
}
}