Skip to content

Commit 0ab30cc

Browse files
author
ionstorm
committed
Add NerbalOne's Powershell Sysmon Installer, add exclusions for asus firmware bin file
1 parent 30c2337 commit 0ab30cc

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

Sysmon_Installer.ps1

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#Author: NerbalOne
2+
#This PowerShell script will first create the Sysmon folder if it does not exist. It will then identify which OS architecture the endpoint is running and download the appropriate Sysmon version along with the Sysmon config and Sysmon Update script. It will then install Sysmon with the config and create a Scheduled Task to run hourly to update the Sysmon config.
3+
#You may have issues while running this script on Windows Server 2012 R2 servers as it seems this server version only works with the Sysmon.exe and not the Sysmon64.exe with the newer Sysmon versions.
4+
5+
# Define Sysmon URLs
6+
$sysmon32URL = "https://live.sysinternals.com/sysmon.exe"
7+
$sysmon64URL = "https://live.sysinternals.com/sysmon64.exe"
8+
$sysmonConfigURL = "https://raw.githubusercontent.com/ion-storm/sysmon-config/master/sysmonconfig-export.xml"
9+
$sysmonUpdateConfig = "https://raw.githubusercontent.com/ion-storm/sysmon-config/master/SysmonUpdateConfig.ps1"
10+
11+
# Define Local Path for Sysmon File and Sysmon Config
12+
$sysmon32Path = "C:\Programdata\Sysmon\sysmon.exe"
13+
$sysmon64Path = "C:\Programdata\Sysmon\sysmon64.exe"
14+
$sysmonConfigPath = "C:\Programdata\Sysmon\sysmonconfig-export.xml"
15+
$sysmonUpdatePath = "C:\Programdata\Sysmon\SysmonUpdateConfig.ps1"
16+
$sysmonFolderPath = "C:\ProgramData\Sysmon\"
17+
18+
# Create Sysmon Folder if it Doesn't Exist
19+
if (-not (Test-Path $sysmonFolderPath)) {
20+
# Create the Folder
21+
try {
22+
New-Item -ItemType Directory -Path $sysmonFolderPath -Force
23+
Write-Host "Folder created successfully at $folderPath"
24+
}
25+
catch {
26+
Write-Host "Error creating the folder: $_"
27+
}
28+
}
29+
else {
30+
Write-Host "The folder already exists at $folderPath"
31+
}
32+
33+
# Check OS Architecture
34+
$OSArchitecture = (Get-WmiObject -Query "Select * from Win32_OperatingSystem").OSArchitecture
35+
36+
# Download Sysmon Update Script
37+
Invoke-WebRequest -Uri $sysmonUpdateConfig -OutFile $sysmonUpdatePath
38+
39+
# Download Sysmon Config
40+
Invoke-WebRequest -Uri $sysmonConfigURL -OutFile $sysmonConfigPath
41+
42+
# Depending on the OS Architecture, Download and Install Sysmon
43+
if ($OSArchitecture -eq "32-bit") {
44+
# Download Sysmon 32 bit
45+
Invoke-WebRequest -Uri $sysmon32URL -OutFile $sysmon32Path
46+
47+
# Install Sysmon with Config
48+
Start-Process -FilePath $sysmon32Path -ArgumentList "-accepteula -i $sysmonConfigPath" -NoNewWindow -Wait
49+
50+
} elseif ($OSArchitecture -eq "64-bit") {
51+
# Download Sysmon 64 bit
52+
Invoke-WebRequest -Uri $sysmon64URL -OutFile $sysmon64Path
53+
54+
# Install Sysmon with Config
55+
Start-Process -FilePath $sysmon64Path -ArgumentList "-accepteula -i $sysmonConfigPath" -NoNewWindow -Wait
56+
57+
} else {
58+
Write-Output "Unsupported architecture: $OSArchitecture"
59+
}
60+
61+
# Create a New Scheduled Task
62+
Start-Process schtasks.exe -ArgumentList '/Create /RU SYSTEM /RL HIGHEST /SC HOURLY /TN Update_Sysmon_Rules /TR "powershell.exe -ExecutionPolicy Bypass -File "C:\Programdata\Sysmon\SysmonUpdateConfig.ps1"" /f' -Wait -WindowStyle Hidden
63+
Start-Process schtasks.exe -ArgumentList '/Run /TN Update_Sysmon_Rules' -Wait -WindowStyle Hidden
64+
65+
# Define Sysmon service Name Based on OS Architecture
66+
$sysmonServiceName = if ($OSArchitecture -eq "64-bit") { "Sysmon64" } else { "Sysmon" }
67+
68+
# Check if Sysmon Service Exists
69+
try {
70+
$service = Get-Service -Name $sysmonServiceName -ErrorAction Stop
71+
Write-Output "Sysmon service exists"
72+
} catch {
73+
Throw "Sysmon service does not exist"
74+
}
75+
76+
# Check if Scheduled Task is Created Successfully
77+
try {
78+
$task = Get-ScheduledTask -TaskName "Update_Sysmon_Rules" -ErrorAction Stop
79+
Write-Output "Scheduled task created successfully"
80+
} catch {
81+
Throw "Scheduled task creation failed"
82+
}

sysmonconfig-export.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5302,6 +5302,7 @@
53025302
</Rule>
53035303
<Rule name="Attack=T1059,Technique=Command and Scripting Interpreter,Tactic=Execution,DS=File: File Creation,Level=0,Desc=BIN file created" groupRelation="and">
53045304
<TargetFilename condition="end with">.bin</TargetFilename>
5305+
<Image condition="excludes any">C:\Windows\System32\WUDFHost.exe</Image>
53055306
</Rule>
53065307
<Rule name="Attack=T1059,Technique=Command and Scripting Interpreter,Tactic=Execution,DS=File: File Creation,Level=0,Desc=WMI Shell artifacts" groupRelation="and">
53075308
<TargetFilename condition="begin with">C:\Windows\SysWOW64\Wbem</TargetFilename>
@@ -5677,6 +5678,7 @@
56775678
</Rule>
56785679
<Rule name="Attack=T1036,Technique=Masquerading,Tactic=Defense Evasion,Risk=20,DS=File: File Creation,Level=0,Desc=Monitor Common Masquarading Locations" groupRelation="and">
56795680
<TargetFilename condition="begin with">C:\Users\Public\</TargetFilename>
5681+
<Image condition="excludes any">C:\Windows\System32\WUDFHost.exe</Image>
56805682
</Rule>
56815683
<Rule name="Attack=T1036,Technique=Masquerading,Tactic=Defense Evasion,Risk=20,DS=File: File Creation,Level=0,Desc=Monitor Common Masquarading Locations" groupRelation="and">
56825684
<TargetFilename condition="begin with">C:\Windows\Temp\</TargetFilename>
@@ -5886,6 +5888,7 @@
58865888
</Rule>
58875889
<Rule name="Attack=T1560,Technique=Archive Collected Data,Tactic=Collection,DS=File: File Creation,Level=0,Desc=BIN" groupRelation="and">
58885890
<TargetFilename condition="end with">.bin</TargetFilename>
5891+
<Image condition="excludes any">C:\Windows\System32\WUDFHost.exe</Image>
58895892
</Rule>
58905893
<Rule name="Attack=T1560,Technique=Archive Collected Data,Tactic=Collection,DS=File: File Creation,Level=0,Desc=CAB Archive" groupRelation="and">
58915894
<TargetFilename condition="end with">.cab</TargetFilename>

0 commit comments

Comments
 (0)