Skip to content

Commit 6d93772

Browse files
committed
suricata package addition
1 parent 211e08f commit 6d93772

File tree

6 files changed

+141
-2
lines changed

6 files changed

+141
-2
lines changed

packages/common.vm/common.vm.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
33
<metadata>
44
<id>common.vm</id>
5-
<version>0.0.0.20250423</version>
5+
<version>0.0.0.20250502</version>
66
<description>Common libraries for VM-packages</description>
77
<authors>Mandiant</authors>
88
</metadata>

packages/common.vm/tools/vm.common/vm.common.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ function VM-Get-MSIInstallerPathByProductName {
17871787

17881788
try {
17891789
# Get a list of all installed MSI products
1790-
$installedProducts = Get-CimInstance -Class Win32_Product | Where-Object { $_.Name -like $ProductName }
1790+
$installedProducts = Get-CimInstance -Class Win32_Product | Where-Object { $_.Name -match $ProductName }
17911791

17921792
if (-not $installedProducts) {
17931793
VM-Write-Log "WARN" "No product found with name like '$ProductName'"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
3+
<metadata>
4+
<id>suricata.vm</id>
5+
<version>7.0.8</version>
6+
<authors>Open Information Security Foundation</authors>
7+
<description>Suricata is a network IDS, IPS and NSM engine developed by the OISF and the Suricata community</description>
8+
<dependencies>
9+
<dependency id="common.vm" version="0.0.0.20250206" />
10+
<dependency id="npcap.vm" version="1.80.20250219" />
11+
</dependencies>
12+
<tags>Networking</tags>
13+
</metadata>
14+
</package>
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
$ErrorActionPreference = 'Stop'
2+
Import-Module vm.common -Force -DisableNameChecking
3+
Import-Module powershell-yaml
4+
5+
# set configurations
6+
$toolName = "Suricata"
7+
$category = VM-Get-Category($MyInvocation.MyCommand.Definition)
8+
$filetype = "MSI"
9+
$toolDir = Join-Path ${Env:ProgramFiles} $toolName
10+
$executablePath = Join-Path $toolDir "suricata.exe"
11+
$url = "https://www.openinfosecfoundation.org/download/windows/Suricata-7.0.8-1-64bit.msi"
12+
$sha256 = "8bdd78d2978e4efc6d23ab1ced024342cac7d38afb152a6e3f70ac5182bd8cd4"
13+
$silentArgs = "/qn /norestart"
14+
15+
$packageArgs = @{
16+
toolName = $toolName
17+
category = $category
18+
filetype = $filetype
19+
silentArgs = $silentArgs
20+
executablePath = $executablePath
21+
url = $url
22+
sha256 = $sha256
23+
consoleApp = $true
24+
}
25+
26+
# download msi file
27+
VM-Install-With-Installer @packageArgs
28+
VM-Assert-Path $executablePath
29+
30+
# delete default desktop shortcut
31+
try{
32+
$desktopShortcutPath = "${Env:HomeDrive}\Users\*\Desktop\$toolName*.lnk"
33+
Remove-Item -Path $desktopShortcutPath -ErrorAction SilentlyContinue
34+
}
35+
catch{
36+
VM-Write-Log-Exception $_
37+
}
38+
39+
# rules configuration and download
40+
$rulesXmlPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)/rules.xml"
41+
$rulesXml = [xml](Get-Content $rulesXmlPath)
42+
43+
$rulesDir = Join-Path $toolDir "rules" -Resolve
44+
$rulesConfigPath = Join-Path $toolDir "suricata.yaml" -Resolve
45+
46+
$rulesConfig = ConvertFrom-Yaml (Get-Content -Raw -Path $rulesConfigPath)
47+
48+
$failures = @()
49+
$rules = $rulesXml.rules.rule
50+
51+
$tempToolDir = Join-Path ${Env:TEMP} $toolName
52+
$tempToolDir += ".vm"
53+
$tempRuleDir = Join-Path $tempToolDir "rules"
54+
55+
foreach ($rule in $rules) {
56+
57+
Write-Host "[+] Attempting to install rule: $($rule.name)"
58+
59+
$filePath = Join-Path $tempToolDir ([System.IO.Path]::GetFileName($rule.url))
60+
61+
try{
62+
Invoke-WebRequest -Uri $rule.url -OutFile $filePath
63+
64+
# If the file ends in .zip, unzip it
65+
if ($filePath -like '*.zip') {
66+
67+
Write-Host "ZIP file detected."
68+
69+
Get-ChocolateyUnzip -FileFullPath $filePath -Destination $tempRuleDir
70+
71+
# if rules are present in innerFolder of zip archive
72+
if ($rule.innerFolder){
73+
$innerFolder = Join-Path $tempRuleDir $rule.innerFolder
74+
75+
Get-ChildItem -Path $innerFolder -File | ForEach-Object {
76+
Copy-Item -Path $_.FullName -Destination $tempRuleDir -Force
77+
}
78+
}
79+
80+
} elseif ($filePath -like '*.rules') {
81+
82+
Write-Host "Rules file detected. Moving to $tempRuleDir..."
83+
84+
Move-Item -Path $filePath -Destination $tempRuleDir
85+
86+
} else {
87+
throw "`t[!] Unsupported file type: '$filePath'. Only .zip and .rule are allowed."
88+
}
89+
} catch {
90+
$failures += $rule.name
91+
}
92+
}
93+
94+
$allRuleFiles = Get-ChildItem -Path $tempRuleDir -Recurse -File -Filter *.rules
95+
96+
# move all rule files in temp rule folder to the suricata rule folder
97+
# add rules to `suricata.yaml`
98+
foreach ($ruleFile in $allRuleFiles){
99+
Move-Item -Path $ruleFile.FullName -Destination $rulesDir -Force
100+
if (-not ($rulesConfig.'rule-files' -contains $ruleFile.Name)){
101+
$rulesConfig.'rule-files' += $ruleFile.Name
102+
}
103+
Write-Host "`t[+] Rule $($ruleFile.Name) added to $rulesDir..."
104+
}
105+
106+
$rulesConfig | ConvertTo-Yaml | Set-Content -Path $rulesConfigPath
107+
108+
# display all errors
109+
if ($failures.Count -gt 0) {
110+
foreach ($module in $failures) {
111+
VM-Write-Log "ERROR" "Failed to install rule: $($rule.name)"
112+
}
113+
exit 1
114+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$ErrorActionPreference = 'Continue'
2+
Import-Module vm.common -Force -DisableNameChecking
3+
4+
$toolName = 'Suricata'
5+
$category = VM-Get-Category($MyInvocation.MyCommand.Definition)
6+
7+
VM-Uninstall $toolName $category
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<rules>
3+
<rule name="emerging-all" url="https://rules.emergingthreats.net/open/suricata-7.0.3/emerging.rules.zip" innerFolder="rules"/>
4+
</rules>

0 commit comments

Comments
 (0)