-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathUpdate_SavedSearches_From_Sigma_YML.ps1
200 lines (167 loc) · 5.62 KB
/
Update_SavedSearches_From_Sigma_YML.ps1
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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
function Get-Web-Download($url,$DownloadFolder)
{
# obtain download location
$download_filename = $url.Split("/")[-1]
$download_path = "$DownloadFolder\$download_filename"
# remove any previously downloaded fies
if (test-path $download_path) {
Remove-Item -Path $download_path -Force
}
# download the file
write-host "Downloading $url"
$client = new-object System.Net.WebClient
$client.DownloadFile($url, $download_path)
# return the path to file
return $download_path
}
function Expand-ZIPFile($file, $destination)
{
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
# remove previous downloads
if (test-path "$env:temp\master.zip") { Remove-Item "$env:temp\master.zip" -Force }
if (test-path "$env:temp\sigma-master") { Remove-Item "$env:temp\sigma-master" -Force -Recurse }
New-Item -ItemType Directory -Path "$env:temp\sigma-master"
Get-Web-Download -url "https://github.com/Neo23x0/sigma/archive/master.zip" -DownloadFolder "$env:temp"
Expand-ZIPFile -file "$env:temp\master.zip" -destination "$env:temp\sigma-master"
import-module powershell-yaml
# https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
# install-package powershell-yaml
# https://github.com/cloudbase/powershell-yaml
$RulePath = "$env:temp\sigma-master\sigma-master\rules\*.yml"
$SavedSearchesPath = "C:\Development\TA-Sigma-Searches\default\savedsearches.conf"
$RuleSet = Get-ChildItem $RulePath -Filter "*.yml" -Recurse
$PythonPath = "C:\Python36-32\python.exe"
$SigmacPath = "C:\Development\sigma-master\tools\sigmac.py"
$RulePath = "C:\Development\sigma-master\rules\windows\sysmon"
$env:PATHEXT += ";.py"
if (test-path $SavedSearchesPath) { remove-item $SavedSearchesPath -Force }
$SPL_critical = Out-Null
$SPL_high = Out-Null
$SPL_medium = Out-Null
$SPL_low = Out-Null
foreach ($Rule in $RuleSet)
{
$SPL= & $PythonPath $SigmacPath -t splunk $($Rule.FullName)
if (!($SPL))
{
continue
}
$RuleData = Get-Content $($Rule.FullName) -Raw
$obj = ConvertFrom-Yaml $RuleData
$product = $($obj.logsource.product)
$service = $($obj.logsource.service)
if (!($product)) { $product = "unknown" }
if (!($service)) { $service = "unknown" }
$prefix = "$product`:$service"
$level = $($obj.level)
if (!($level)) { $level = "unknown" }
switch -Wildcard ($prefix)
{
windows:sysmon {$SourceType="*WinEventLog:Microsoft-Windows-Sysmon/Operational"}
windows:security {$SourceType="*WinEventLog:Security"}
windows:powershell {$SourceType="*Microsoft-Windows-PowerShell/Operational"}
windows:system {$SourceType="*WinEventLog:System"}
windows:application {$SourceType="*WinEventLog:Application"}
windows:taskscheduler {$SourceType="*WinEventLog:Microsoft-Windows-TaskScheduler/Operational"}
default {$SourceType="*"}
}
$SPL = $SPL.Replace("EventID","EventCode")
$SPL = "sourcetype=`"$SourceType`" $SPL"
# append the critical multisearch
if ($level -eq "critical")
{
if (!($SPL_critical))
{
$SPL_critical = "($SPL)"
}
else
{
$SPL_critical = "$SPL_critical OR ($SPL)"
}
}
# append the high multisearch
if ($level -eq "high")
{
if (!($SPL_high))
{
$SPL_high = "($SPL)"
}
else
{
$SPL_high = "$SPL_high OR ($SPL)"
}
}
# append the medium multisearch
if ($level -eq "medium")
{
if (!($SPL_medium))
{
$SPL_medium = "($SPL)"
}
else
{
$SPL_medium = "$SPL_medium OR ($SPL)"
}
}
# append the medium multisearch
if ($level -eq "low")
{
if (!($SPL_low))
{
$SPL_low = "($SPL)"
}
else
{
$SPL_low = "$SPL_low OR ($SPL)"
}
}
$description = "$($obj.description). Author: $($obj.author) Status: $($obj.status) Level: $($obj.level) FalsePositives: $($obj.falsepositives)"
$section = @("
[$level`:$prefix - $($obj.title)]
search = $SPL
dispatch.earliest_time = -24h@h
description = $description")
write-host $section
$section | Out-File $SavedSearchesPath -Append
}
$section = @("
[All Critical Severity Signatures]
search = $SPL_critical
dispatch.earliest_time = -24h@h
description = combined search of critical severity signatures")
write-host $section
$section | Out-File $SavedSearchesPath -Append
$section = @("
[All High Severity Signatures]
search = $SPL_high
dispatch.earliest_time = -24h@h
description = combined search of high severity signatures")
write-host $section
$section | Out-File $SavedSearchesPath -Append
$section = @("
[All Medium Severity Signatures]
search = $SPL_medium
dispatch.earliest_time = -24h@h
description = combined search of medium severity signatures")
write-host $section
$section | Out-File $SavedSearchesPath -Append
$section = @("
[All Low Severity Signatures]
search = $SPL_low
dispatch.earliest_time = -24h@h
description = combined search of low severity signatures")
write-host $section
$section | Out-File $SavedSearchesPath -Append
Set-Location "C:\Development\TA-Sigma-Searches"
& git add C:\Development\TA-Sigma-Searches\default\savedsearches.conf
$shortdate = (Get-Date).ToString("yyyy.MM.dd.hh.mm.ss")
$comment = "update v$shortdate"
& git commit -m "$comment"
& git push origin master