-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirp.ps1
1790 lines (1448 loc) · 57.9 KB
/
firp.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Function Get-bruteforce {
<#
.SYNOPSIS
The 'Get-bruteforce' use case is designed to extract failed logon attempts that may indicate a brute force attack.
.DESCRIPTION
Query the event log to detect more than 20 failed logons in a short timeframe.
The output log is one of the brute-force attempts.
.PARAMETER
Please provide start time : -StartTime and end time: -EndTime
.EXAMPLE
Get-bruteforce -StartTime '2023-02-10T12:00:00' -EndTime '2023-02-15T21:58:00'
.NOTES
#>
param (
[parameter(Mandatory = $true)]
[DateTime]$StartTime,
[parameter(Mandatory = $true)]
[DateTime]$EndTime
)
$EventIds = @("4625")
$FailedLogons = Get-WinEvent -FilterHashTable @{LogName='Security';StartTime=$StartTime; EndTime=$EndTime; ID=4625} |
Where-Object {
$_.Properties[5].Value -notmatch '^(S-1-5-21-\d+-\d+-\d+-\d+|S-1-5-18|S-1-5-19)$'
}
$BruteForceAttempts = @()
for ($i = 0; $i -lt $FailedLogons.Count; $i++) {
$FailedLogon = $FailedLogons[$i]
$FailedAttempts = 1
for ($j = $i + 1; $j -lt $FailedLogons.Count; $j++) {
$NextFailedLogon = $FailedLogons[$j]
$TimeDiff = New-TimeSpan -Start $FailedLogon.TimeCreated -End $NextFailedLogon.TimeCreated
if ($TimeDiff.TotalMinutes -le 5) {
$FailedAttempts++
} else {
break
}
}
if ($FailedAttempts -ge 20) {
$BruteForceAttempts += $FailedLogon
}
$i += $FailedAttempts - 1
}
if ($BruteForceAttempts.Count -gt 0) {
Write-Output "Brute Force Attempts detected with more of 20 failed logons :"
$BruteForceAttempts | Format-List
} else {
Write-Output "No Brute Force Attempts found."
}
}
Function Get-FailedAndSuccessLogons {
<#
.SYNOPSIS
The 'Get-FailedAndSuccessLogons' use case is designed to extract failed and success Logons.
.DESCRIPTION
FailedAndSuccessLogons: queries the Windows Security event log to retrieve both successful and failed logon events
(with event IDs 4624 and 4625) for a specific time frame, and excludes logon events for system accounts.
.PARAMETER
You can write the output of a PowerShell command to a file and filter by a specific time frame.
.EXAMPLE
Get-FailedAndSuccessLogons -StartTime '2023-02-12 00:00:00' -EndTime '2023-02-13 23:24:00'
.NOTES
#>
param (
[parameter(Mandatory = $true)]
[DateTime]$StartTime,
[parameter(Mandatory = $true)]
[DateTime]$EndTime
)
$EventIds = @("4624", "4625")
Get-WinEvent -FilterHashTable @{LogName='Security';StartTime=$StartTime; EndTime=$EndTime; ID=$EventIds} |
Where-Object {
$_.Properties[5].Value -notmatch '^(S-1-5-21-\d+-\d+-\d+-\d+|S-1-5-18|S-1-5-19)$'
} |
Select-Object * -ExcludeProperty Description |
Format-List
}
function Get-ScheduledTaskEventLogs4698 {
<#
.SYNOPSIS
The Get-ScheduledTaskEventLogs4698 function is a PowerShell function that retrieves Windows event logs related to the creation of scheduled tasks with the Event ID 4698
.DESCRIPTION
The function takes three parameters:
$EventId: This is the ID of the event log that the function should search for. In this case, it is set to 4698, which corresponds to the creation of a scheduled task.
$StartTime: This is the start time of the window within which the function should search for event logs.
$EndTime: This is the end time of the window within which the function should search for event logs.
.PARAMETER
It filters the event logs by log name, event ID, start time, and end time.
.EXAMPLE
Get-ScheduledTaskEventLogs4698 -StartTime '2021-02-14 00:00:00' -EndTime '2023-02-17 23:59:59
.NOTES
#>
param(
[Parameter(Mandatory = $true)]
[datetime]$StartTime,
[Parameter(Mandatory = $true)]
[datetime]$EndTime
)
$LogName = 'Security'
$EventId = 4698
$events = Get-WinEvent -FilterHashtable @{
LogName = $LogName
ID = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$result = @()
$events | ForEach-Object {
$event = $_.ToXml()
$xml = [xml]$event
$properties = @{}
foreach ($property in $xml.Event.EventData.Data) {
$name = $property.Name
$value = $property.'#text'
if ($properties.Contains($name)) {
$index = 1
while ($properties.Contains("$name$index")) {
$index++
}
$name = "$name$index"
}
$properties[$name] = $value
}
$result += New-Object -TypeName PSObject -Property $properties
}
return $result
}
Function Get-FailedRDP {
<#
.SYNOPSIS
This is a PowerShell function named Get-FailedRDP which retrieves failed RDP login attempts
from the Windows Security event log within a specified timeframe.
.DESCRIPTION
The function accepts two mandatory parameters: $StartTime and $EndTime, which specify the start and end time for the log search.
The function filters events with ID 4625 (indicating a failed login attempt) and logon type 10 (indicating an RDP login attempt).
.PARAMETER
"Get-FailedRDP" is a PowerShell function that extracts information about failed logon attempts from the Security event logs.
It specifically targets event ID 4625, which is generated when a logon attempt fails
.EXAMPLE
Get-FailedRDP -StartTime '2023-02-12 00:00:00' -EndTime '2023-02-13 23:24:00'
.NOTES
#>
param (
[parameter(Mandatory = $true)]
[DateTime]$StartTime,
[parameter(Mandatory = $true)]
[DateTime]$EndTime
)
$EventIds = @("4625")
Get-WinEvent -FilterHashTable @{LogName='Security';StartTime=$StartTime; EndTime=$EndTime; ID=$EventIds} |
Where-Object {
$_.Properties[5].Value -notmatch '^(S-1-5-21-\d+-\d+-\d+-\d+|S-1-5-18|S-1-5-19)$'
} |
Where-Object {
$_.Id -eq 4625 -and $_.Properties[8].Value -eq 10
} |
Select-Object -Property TimeCreated, @{Name='Logon Type';Expression={$_.Properties[8].Value}}, @{Name='Status';Expression={$_.Properties[3].Value}}, @{Name='Substatus';Expression={$_.Properties[4].Value}}, @{Name='Target User Name';Expression={$_.Properties[5].Value}}, @{Name='Workstation Name';Expression={$_.Properties[12].Value}}, @{Name='IP Address';Expression={$_.Properties[13].Value}} |
Format-List
}
Function Get-FailedNetworkLogons {
<#
.SYNOPSIS
This is a PowerShell function that retrieves failed logon events from the Windows Security event log within a specified time range.
.DESCRIPTION
The function takes two parameters: $StartTime and $EndTime, both of which are mandatory and must be of type DateTime.
The function then uses the Get-WinEvent cmdlet to filter the Security event log for event ID 4625 (failed logon events)
that have a logon type of 3 (network logon) and a non-zero status code.
.PARAMETER
"Get-FailedNetworkLogons" is a PowerShell function that extracts information about failed logon attempts from the Security event logs.
It specifically targets event ID 4625 and filters for events that have a non-zero status code.
.EXAMPLE
Get-FailedNetworkLogons -StartTime '2023-02-12 00:00:00' -EndTime '2023-02-13 23:24:00'
.NOTES
#>
param (
[parameter(Mandatory = $true)]
[DateTime]$StartTime,
[parameter(Mandatory = $true)]
[DateTime]$EndTime
)
Get-WinEvent -FilterHashTable @{LogName='Security';StartTime=$StartTime; EndTime=$EndTime; ID=4625} |
Where-Object {
($_.Properties[10].Value -eq "3")
} | Format-List
}
Function Get-SuccessNetworkLogons {
<#
.SYNOPSIS
This is a PowerShell function that retrieves failed logon events from the Windows Security event log within a specified time range.
.DESCRIPTION
The function takes two parameters: $StartTime and $EndTime, both of which are mandatory and must be of type DateTime.
The function then uses the Get-WinEvent cmdlet to filter the Security event log for event ID 4624 (successful logon events)
that have a logon type of 3 (network logon).
.PARAMETER
"Get-SuccessNetworkLogons" is a PowerShell function that extracts information about failed logon attempts from the Security event logs.
It specifically targets event ID 4624,It also filters for events that have a non-zero status code
.EXAMPLE
Get-SuccessNetworkLogons -StartTime '2023-02-12 00:00:00' -EndTime '2023-02-13 23:24:00'
.NOTES
#>
param (
[parameter(Mandatory = $true)]
[DateTime]$StartTime,
[parameter(Mandatory = $true)]
[DateTime]$EndTime
)
Get-WinEvent -FilterHashTable @{LogName='Security';StartTime=$StartTime; EndTime=$EndTime; ID=4624} |
Where-Object {
($_.Properties[8].Value -eq "3")
} | Format-List
}
Function Get-LogonInfo {
<#
.SYNOPSIS
Get-LogonInfo extracts all Loon Events [Evt 4624] from the Security Event log for a specified timeframe
.DESCRIPTION
Query the event log and pull back all Logon Events.
Event 4624
Query and filter
.PARAMETER
Specifies the start time to search for logon events.
.PARAMETER
Specifies the end time to search for logon events.
.EXAMPLE
Get-LogonInfo -StartTime "2023-02-15T00:00:00" -EndTime "2023-02-16T00:00:00"
.NOTES
#>
[cmdletbinding()]
param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$True,
HelpMessage="Enter the start time")]
[datetime]$StartTime,
[Parameter(Mandatory=$true,
ValueFromPipeline=$True,
HelpMessage="Enter the end time")]
[datetime]$EndTime
)
$RawEvents = Get-WinEvent -FilterHashtable @{Logname="Security"; ID=4624} | Where-Object {$_.TimeCreated -ge $StartTime -and $_.TimeCreated -le $EndTime}
$RawEvents | ForEach-Object {
$SelectorStrings = [string[]]@(
'Event/EventData/Data[@Name="TargetUserName"]',
'Event/EventData/Data[@Name="TargetDomainName"]',
'Event/EventData/Data[@Name="TargetLogonId"]',
'Event/EventData/Data[@Name="LogonType"]',
'Event/EventData/Data[@Name="WorkstationName"]',
'Event/EventData/Data[@Name="ProcessId"]',
'Event/EventData/Data[@Name="ProcessName"]',
'Event/EventData/Data[@Name="IpAddress"]',
'Event/EventData/Data[@Name="IpPort"]'
)
$PropertySelector = [System.Diagnostics.Eventing.Reader.EventLogPropertySelector]::new($SelectorStrings)
$UserName,$Domain,$LogonId,$LogonType,$ComputerName,$ProcessId,$ProcessName,$IPAddress,$Port = $_.GetPropertyValues($PropertySelector)
[PSCustomObject]@{
TimeCreated = $_.TimeCreated
UserName = $UserName
Domain = $Domain
LogonId = $LogonId
LogonType = $LogonType
ComputerName = $ComputerName
ProcessId = $ProcessId
ProcessName = $ProcessName
IPAddress = $IPAddress
Port = $Port
Message = ($_.Message).split(".")[0]
}
}
}
function Get-PowerShellLog {
<#
.SYNOPSIS
The function Get-PowerShellLog retrieves events with ID 4104 from the Microsoft-Windows-PowerShell
provider within a specified time frame,and filters the events based on one or more provided keywords.
.DESCRIPTION
The function returns the log messages that contain at least one of the provided keywords.
.EXAMPLE
Get-PowerShellLog -Keywords "HTTP://" -StartTime '2023-02-10T12:00:00' -EndTime '2023-02-15T21:58:00'
.NOTES
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string[]]$Keywords,
[DateTime]$StartTime,
[DateTime]$EndTime
)
$events = Get-WinEvent -FilterHashtable @{
ProviderName='Microsoft-Windows-PowerShell'
ID=4104
StartTime=$StartTime
EndTime=$EndTime
}
$events | ForEach-Object {
$message = $_.Properties[2].Value
foreach ($keyword in $Keywords) {
if ($message -like "*$keyword*") {
$message
break
}
}
}
}
function Get-PowerShellLogb64 {
<#
.SYNOPSIS
The function Get-PowerShellLog retrieves events with ID 4104 from the Microsoft-Windows-PowerShell
provider within a specified time frame,and filters the events based on base64 encode.
.DESCRIPTION
The function returns the base64 encoded code from the log messages that contain at least one base64-encoded string.
.EXAMPLE
Get-PowerShellLogb64 -StartTime '2023-02-10T12:00:00' -EndTime '2023-02-15T21:58:00'
.NOTES
#>
[CmdletBinding()]
param(
[DateTime]$StartTime,
[DateTime]$EndTime
)
$events = Get-WinEvent -FilterHashtable @{
ProviderName='Microsoft-Windows-PowerShell'
ID=4104
StartTime=$StartTime
EndTime=$EndTime
}
$base64Regex = '\-[Ee^]{1,2}[NnCcOoDdEeMmAa^]+ [A-Za-z0-9+/=]{5,}'
$events | ForEach-Object {
$message = $_.Properties[2].Value
$base64Matches = [regex]::Matches($message, $base64Regex)
foreach ($match in $base64Matches) {
$match.Value
}
}
}
function Get-PowerShellMaldev {
<#
.SYNOPSIS
The function Get-PowerShellMaldev retrieves events with ID 4104 from the Microsoft-Windows-PowerShell
provider within a specified time frame,and filters the events based on database of malicious keywords.
.DESCRIPTION
The function returns the log messages that contain at least one log where is detected the key.
.EXAMPLE
Get-PowerShellMaldev -StartTime '2023-02-10T12:00:00' -EndTime '2023-02-15T21:58:00'
.NOTES
#>
[CmdletBinding()]
param(
[DateTime]$StartTime,
[DateTime]$EndTime
)
$events = Get-WinEvent -FilterHashtable @{
ProviderName='Microsoft-Windows-PowerShell'
ID=4104
StartTime=$StartTime
EndTime=$EndTime
}
$maliciousKeywords = Get-Content -Path ".\keywords.txt"
#$maliciousKeywords = @()
$events | ForEach-Object {
$message = $_.Properties[2].Value
foreach ($keyword in $maliciousKeywords) {
if ($message -like "*$keyword*") {
$message -replace $keyword, "$(Write-Host $keyword -ForegroundColor Red)"
break
}
}
}
}
function Get-SysmonProcess {
<#
RuleName: The name of the rule that triggered the process creation event.
UtcTime: The UTC timestamp when the process was created.
ProcessGuid: A unique identifier for the process.
ProcessId: The process ID of the created process.
Image: The full path of the executable file that was launched.
FileVersion: The version of the executable file.
Description: A description of the executable file.
Product: The name of the product associated with the executable file.
Company: The name of the company that produced the executable file.
OriginalFileName: The original name of the executable file.
CommandLine: The command line arguments used to launch the executable file.
CurrentDirectory: The current working directory of the launched process.
User: The username of the user that launched the process.
LogonGuid: A unique identifier for the user's logon session.
LogonId: A numerical identifier for the user's logon session.
TerminalSessionId: A numerical identifier for the user's terminal services session.
IntegrityLevel: The integrity level of the process (e.g. low, medium, high).
Hashes: The SHA-256 hash of the launched executable file.
ParentProcessGuid: A unique identifier for the parent process that launched the process.
ParentProcessId: The process ID of the parent process.
ParentImage: The full path of the executable file for the parent process.
ParentCommandLine: The command line arguments used to launch the parent process.
Example : Get-SysmonProcess -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 1
)
$ErrorActionPreference = 'SilentlyContinue'
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime.AddMinutes(-5)
EndTime = $EndTime.AddMinutes(5)
}
$suspiciousEvents = foreach ($event in $events) {
$Properties = [xml]$event.ToXml()
$User = $Properties.Event.EventData.Data | where {$_.Name -eq 'User'} | select -ExpandProperty '#text'
$Product = $Properties.Event.EventData.Data | where {$_.Name -eq 'Product'} | select -ExpandProperty '#text'
$Description = $Properties.Event.EventData.Data | where {$_.Name -eq 'Description'} | select -ExpandProperty '#text'
$Company = $Properties.Event.EventData.Data | where {$_.Name -eq 'Company'} | select -ExpandProperty '#text'
$ProcessId = $Properties.Event.EventData.Data | where {$_.Name -eq 'ProcessId'} | select -ExpandProperty '#text'
$Image = $Properties.Event.EventData.Data | where {$_.Name -eq 'Image'} | select -ExpandProperty '#text'
$OriginalFilename = $Properties.Event.EventData.Data | where {$_.Name -eq 'OriginalFilename'}
if ($OriginalFilename) {$OriginalFilename = $OriginalFilename.'#text'}
$CommandLine = $Properties.Event.EventData.Data | where {$_.Name -eq 'CommandLine'} | select -ExpandProperty '#text'
$CurrentDirectory = $Properties.Event.EventData.Data | where {$_.Name -eq 'CurrentDirectory'} | select -ExpandProperty '#text'
$ParentProcessGuid = $Properties.Event.EventData.Data | where {$_.Name -eq 'ParentProcessGuid'} | select -ExpandProperty '#text'
$ParentProcessId = $Properties.Event.EventData.Data | where {$_.Name -eq 'ParentProcessId'} | select -ExpandProperty '#text'
$ParentImage = $Properties.Event.EventData.Data | where {$_.Name -eq 'ParentImage'} | select -ExpandProperty '#text'
$ParentCommandLine = $Properties.Event.EventData.Data | where {$_.Name -eq 'ParentCommandLine'} | select -ExpandProperty '#text'
$ImageSuspicious = $false
if ($Image -match 'Temp' -or $Image -match 'ProgramData' -or $Image -match 'Users' -or $Image -match 'Downloads' -or $Image -match 'Documents' -or $Image -match 'Roaming') {
$ImageSuspicious = $true
}
$CurrentDirectorySuspicious = $false
if ($CurrentDirectory -match 'Temp' -or $CurrentDirectory -match 'ProgramData' -or $CurrentDirectory -match 'Roaming' -or $CurrentDirectory -match 'Users' -or $CurrentDirectory -match 'Downloads' -or $CurrentDirectory -match 'Documents') {
$CurrentDirectorySuspicious = $true
}
$CommandLineSuspicious = $false
if ($CommandLine -match 'AppData' -or $CommandLine -match 'Roaming' -or
$CommandLine -match 'Temp' -or $CommandLine -match 'Users' -or $CommandLine -match 'ProgramData' -or $CommandLine -match 'Downloads'-or $CommandLine -match 'Documents') {
$CommandLineSuspicious = $true
}
if ($ImageSuspicious -or $CommandLineSuspicious -or $CurrentDirectorySuspicious) {
$Hash = (Get-FileHash -Algorithm MD5 (Resolve-Path $Image -ErrorAction SilentlyContinue).Path).Hash
[PSCustomObject]@{
TimeCreated = $event.TimeCreated
ProcessId = $ProcessId
User = $User
Product = $Product
Description = $Description
Company = $Company
Image = $Image
ImageSuspicious = $ImageSuspicious
OriginalFilename = $OriginalFilename
OriginalFilenameSuspicious = $OriginalFilenameSuspicious
CommandLine = $CommandLine
CommandLineSuspicious = $CommandLineSuspicious
CurrentDirectory = $CurrentDirectory
CurrentDirectorySuspicious = $CurrentDirectorySuspicious
ParentProcessGuid = $ParentProcessGuid
ParentProcessId = $ParentProcessId
ParentImage = $ParentImage
ParentCommandLine = $ParentCommandLine
Hash = $Hash
}
}
}
return $suspiciousEvents
}
Function Get-SysmonNetwork {
<#
.SYNOPSIS
Retrieves Sysmon network event logs within a specified time range
RuleName : technique_id=T1021,technique_name=Remote Services
HostName : LAPTOP-HAK\Andrea
DateUTC : 2023-02-18 11:01:08.365
ProcessGuid : 6c4ade50-aff2-63f0-f95b-00000000ad00
ProcessId : 14108
Image : C:\Program Files\RealVNC\VNC Viewer\vncviewer.exe
User : LAPTOP-HAK\Andrea
Protocol : tcp
Initiated : True
SourceIsIpv6 : False
SourceIp : 192.168.1.34
SourceHostname : -
SourcePort : 4861
SourcePortName : -
DestinationIsIpv6 : False
DestinationIp : 212.119.29.177
DestinationHostname : -
DestinationPort : 443
DestinationPortName : -
.EXAMPLE
Get-SysmonNetwork -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 3
)
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$events | ForEach-Object {
$PropertyBag = @{
HostName = $_.Properties[1].Value
DateUTC = $_.Properties[2].Value
ProcessGuid = $_.Properties[2].Value
ProcessId = $_.Properties[3].Value
Image = $_.Properties[4].Value
User = $_.Properties[5].Value
Protocol = $_.Properties[6].Value
Initiated = $_.Properties[7].Value
SourceIsIpv6 = $_.Properties[8].Value
SourceIp = $_.Properties[9].Value
SourceHostname = $_.Properties[10].Value
SourcePort = $_.Properties[11].Value
SourcePortName = $_.Properties[12].Value
DestinationIsIpv6 = $_.Properties[13].Value
DestinationIp = $_.Properties[14].Value
DestinationHostname = $_.Properties[15].Value
DestinationPort = $_.Properties[16].Value
DestinationPortName = $_.Properties[17].Value
}
$Output = New-Object -TypeName PSCustomObject -Property $PropertyBag
$Output | Select-Object RuleName, HostName, DateUTC, ProcessGuid, ProcessId, Image, User, Protocol, Initiated, SourceIsIpv6, SourceIp, SourceHostname, SourcePort, SourcePortName, DestinationIsIpv6, DestinationIp, DestinationHostname, DestinationPort, DestinationPortName
}
}
Function Get-SysmonFileStreamCreate {
<#
.SYNOPSIS
Get-SysmonFileStreamCreate extracts all Sysmon File Stream Create Events [Evt 15] from the Sysymon Operational Event log for a specified timeframe
.DESCRIPTION
Query the event log and pull back all Sysmon File Stream Creation events.
Event 15 or downloaded files the content field would be empty and only the hashes can be checked against virus total to identify if the FileStreamHash is malicious or clean.
For events where the system creates Zone Identifier files and Content field is completely appended with all details, it should be parsed properly and Referral URL and Host URL should be checked for maliciousness.
RuleName : -
HostName : LAPTOP-HDFRT
DateUTC : 2023-02-18 12:34:24.347
ProcessGuid : 6c4ade50-c5c8-63f0-375d-00000000ad00
ProcessId : 11420
Image : C:\Program Files\Mozilla Firefox\firefox.exe
TargetFilename : D:\mimikatz.exe
CreationUTC : 2023-02-18 12:34:24.056
SHA1 : {SHA1=D1F7832035C3E8A73CC78AFD28CFD7F4CECE6D20, MD5=E930B05EFE23891D19BC354A4209BE3E, SHA256=92804FAAAB2175DC501D73E814663058C78C0A042675A8937266357BCFB96C50, IMPHASH=1355327F6CA3430B3DDBE6E0ACDA71EA}
User : LAPTOP-HDFRT\Andrea
.EXAMPLE
Get-SysmonFileStreamCreate -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 15
)
$ErrorActionPreference = 'SilentlyContinue'
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$SHA1 = (Get-FileHash -Algorithm MD5 (Resolve-Path $SHA1 -ErrorAction SilentlyContinue).Path).SHA1
$events | ForEach-Object {
$PropertyBag = @{
HostName = $_.MachineName
User = $_.Properties[9].Value
EventID = $_.Id
DateUTC = $_.Properties[1].Value
ProcessGuid = $_.Properties[2].Value
ProcessId = $_.Properties[3].Value
Image = $_.Properties[4].Value
TargetFilename = $_.Properties[5].Value
CreationUTC = $_.Properties[6].Value
SHA1 = ($_.Properties[7].Value.ToString().Split(","))
RuleName = $_.Properties[0].Value
}
$Output = New-Object -TypeName PSCustomObject -Property $PropertyBag
$Output | Select-Object RuleName, HostName, DateUTC, ProcessGuid, ProcessId, Image, TargetFilename, CreationUTC, SHA1, User
}
}
Function Get-SysmonCreateRemoteThread {
<#
.SYNOPSIS
The function Get-SysmonCreateRemoteThread retrieves Sysmon Create Remote Thread Events [Evt 8] within a specified timeframe from the Sysmon Operational Event log.
.DESCRIPTION
Query the event log and pull back all Sysmon File Stream Creation events. Event 8
RuleName : technique_id=T1055,technique_name=Process Injection
DateUTC : 2023-02-18 16:54:03.874
SourceProcessId : 24040
ProcessGuid : 6c4ade50-02ab-63f1-5e60-00000000ad00
SourceImage : C:\Users\Andrea\Desktop\Injector.exe
TargetImage : C:\Windows\System32\notepad.exe
SourceUser : LAPTOP-HL1G97FB\Andrea
TargetUser : LAPTOP-HL1G97FB\Andrea
StartFunction : LoadLibraryW
StartModule : C:\WINDOWS\System32\KERNEL32.DLL
.EXAMPLE
Get-SysmonCreateRemoteThread -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 8
)
$ErrorActionPreference = 'SilentlyContinue'
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$SHA1 = (Get-FileHash -Algorithm MD5 (Resolve-Path $SHA1 -ErrorAction SilentlyContinue).Path).SHA1
$events | ForEach-Object {
$PropertyBag = @{
RuleName = $_.Properties[0].Value
DateUTC = $_.Properties[1].Value
SourceProcessId = $_.Properties[3].Value
SourceImage = $_.Properties[4].Value
TargetImage = $_.Properties[7].Value
CreationUTC = $_.Properties[2].Value
SourceUser = $_.Properties[12].Value
TargetUser = $_.Properties[13].Value
User = $_.Properties[9].Value
TargetProcessId = $_.Properties[7].Value
NewThreadId = $_.Properties[9].Value
ProcessGuid = $_.Properties[2].Value
StartModule = $_.Properties[10].Value
StartFunction = $_.Properties[11].Value
}
$Output = New-Object -TypeName PSCustomObject -Property $PropertyBag
$Output | Select-Object RuleName, DateUTC, SourceProcessId, ProcessGuid, SourceImage, TargetImage , SourceUser,
SourceUser, TargetUser, StartFunction, StartModule
}
}
Function Get-SysmonFileCreate {
<#
.SYNOPSIS
Get-SysmonFileCreate extracts all Sysmon File Create Events [Evt 11] from the Sysymon Operational Event log for a specified timeframe
.DESCRIPTION
RuleName : technique_id=T1574.010,technique_name=Services File Permissions Weakness
DateUTC : 2023-02-18 10:53:00.499
SourceProcessId : 4740
ProcessGuid : 6c4ade50-3808-63dd-5e00-00000000ad00
Image : C:\WINDOWS\System32\svchost.exe
TargetFilename : C:\Windows\System32\sru\SRUtmp.log
CreationUtcTime : 2020-08-26 12:32:09.752
User : NT AUTHORITY\LOCAL SERVICE
.EXAMPLE
Get-SysmonFileCreate -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 11
)
$ErrorActionPreference = 'SilentlyContinue'
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$SHA1 = (Get-FileHash -Algorithm MD5 (Resolve-Path $SHA1 -ErrorAction SilentlyContinue).Path).SHA1
$events | ForEach-Object {
$PropertyBag = @{
RuleName = $_.Properties[0].Value
DateUTC = $_.Properties[1].Value
ProcessGuid = $_.Properties[2].Value
SourceProcessId = $_.Properties[3].Value
Image = $_.Properties[4].Value
TargetFilename = $_.Properties[5].Value
CreationUtcTime = $_.Properties[6].Value
User = $_.Properties[7].Value
}
$Output = New-Object -TypeName PSCustomObject -Property $PropertyBag
$Output | Select-Object RuleName, DateUTC, SourceProcessId, ProcessGuid,Image, TargetFilename, CreationUtcTime,User
}
}
Function Get-SysmonProcessTerminate {
<#
.SYNOPSIS
The function Get-SysmonProcessTerminate retrieves Sysmon File Create Events [Evt 5] within a specified timeframe from the Sysmon Operational Event log.
.DESCRIPTION
RuleName : technique_id=T1574.010,technique_name=Services File Permissions Weakness
DateUTC : 2023-02-18 10:53:00.499
SourceProcessId : 4740
ProcessGuid : 6c4ade50-3808-63dd-5e00-00000000ad00
Image : C:\WINDOWS\System32\svchost.exe
TargetFilename : C:\Windows\System32\sru\SRUtmp.log
CreationUtcTime : 2020-08-26 12:32:09.752
User : NT AUTHORITY\LOCAL SERVICE
.EXAMPLE
Get-SysmonProcessTerminate -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 5
)
$ErrorActionPreference = 'SilentlyContinue'
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$events | ForEach-Object {
$PropertyBag = @{
RuleName = $_.Properties[0].Value
DateUTC = $_.Properties[1].Value
ProcessGuid = $_.Properties[2].Value
ProcessId = $_.Properties[3].Value
Image = $_.Properties[4].Value
User = $_.Properties[5].Value
}
$Output = New-Object -TypeName PSCustomObject -Property $PropertyBag
$Output | Select-Object RuleName, DateUTC, ProcessGuid, ProcessId,Image, User
}
}
Function Get-SysmonRegAddDelete {
<#
.SYNOPSIS
The function Get-SysmonRegAddDelete retrieves Sysmon File Create Events [Evt 12] within a specified timeframe from the Sysmon Operational Event log.
.DESCRIPTION
RuleName : technique_id=T1553.004,technique_name=Install Root Certificate
EventType : CreateKey
ProcessGuid : 6c4ade50-aeae-63f0-e05b-00000000ad00
ProcessId : 13240
Image : C:\Program Files\Mozilla Firefox\firefox.exe
TargetObject : HKU\S-1-5-21-3292112416-2004140554-2480127568-1001\SOFTWARE\Microsoft\SystemCertificates\CA\Certificates
User : LAPTOP-HL1G97FB\Andrea
.EXAMPLE
Get-SysmonRegAddDelete -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 12
)
$ErrorActionPreference = 'SilentlyContinue'
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$events | ForEach-Object {
$PropertyBag = @{
RuleName = $_.Properties[0].Value
EventType = $_.Properties[1].Value
UtcTime = $_.Properties[2].Value
ProcessGuid = $_.Properties[3].Value
ProcessId = $_.Properties[4].Value
Image = $_.Properties[5].Value
TargetObject = $_.Properties[6].Value
User = $_.Properties[7].Value
}
$Output = New-Object -TypeName PSCustomObject -Property $PropertyBag
$Output | Select-Object RuleName, EventType, ProcessGuid, ProcessId,ProcessId,Image,TargetObject, User
}
}
Function Get-SysmonReg {
<#
.SYNOPSIS
Get-SysmonReg extracts all Sysmon Registry Value Set Events [Evt 13] from the Sysymon Operational Event log for a specified timeframe
.DESCRIPTION
Query the event log and pull back all Sysmon Process Creation events.
.EXAMPLE
Get-SysmonReg -StartTime '2023-02-18T08:06:00' -EndTime '2023-02-19T11:57:00'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[DateTime]$StartTime = (Get-Date).AddMinutes(-5),
[Parameter(Mandatory=$false)]
[DateTime]$EndTime = (Get-Date).AddMinutes(5),
[Parameter(Mandatory=$false)]
[int]$EventId = 13
)
$ErrorActionPreference = 'SilentlyContinue'
$events = Get-WinEvent -FilterHashtable @{
LogName = 'Microsoft-Windows-Sysmon/Operational'
Id = $EventId
StartTime = $StartTime
EndTime = $EndTime
}
$events | ForEach-Object {
$PropertyBag = @{
RuleName = $_.Properties[0].Value
EventType = $_.Properties[1].Value
UtcTime = $_.Properties[2].Value
ProcessGuid = $_.Properties[3].Value
ProcessId = $_.Properties[4].Value
Image = $_.Properties[5].Value
TargetObject = $_.Properties[6].Value
User = $_.Properties[7].Value
}
$Output = New-Object -TypeName PSCustomObject -Property $PropertyBag