Skip to content

Commit 4dee3a2

Browse files
committed
suricata package addition
1 parent 211e08f commit 4dee3a2

6 files changed

Lines changed: 132 additions & 2 deletions

File tree

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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
$ErrorActionPreference = 'Stop'
2+
Import-Module vm.common -Force -DisableNameChecking
3+
Import-Module powershell-yaml
4+
5+
# need to install yaml handling module 'Install-Module -Name powershell-yaml'
6+
7+
$toolName = "Suricata"
8+
$category = VM-Get-Category($MyInvocation.MyCommand.Definition)
9+
$filetype = "MSI"
10+
$toolDir = Join-Path ${Env:ProgramFiles} $toolName
11+
$executablePath = Join-Path $toolDir "suricata.exe"
12+
$url = "https://www.openinfosecfoundation.org/download/windows/Suricata-7.0.8-1-64bit.msi"
13+
$sha256 = "8bdd78d2978e4efc6d23ab1ced024342cac7d38afb152a6e3f70ac5182bd8cd4"
14+
$silentArgs = "/qn /norestart"
15+
16+
$packageArgs = @{
17+
toolName = $toolName
18+
category = $category
19+
filetype = $filetype
20+
silentArgs = $silentArgs
21+
executablePath = $executablePath
22+
url = $url
23+
sha256 = $sha256
24+
consoleApp = $true
25+
}
26+
27+
VM-Install-With-Installer @packageArgs
28+
29+
try{
30+
$desktopShortcutPath = "${Env:HomeDrive}\Users\*\Desktop\$toolName*.lnk"
31+
Remove-Item -Path $desktopShortcutPath -ErrorAction SilentlyContinue
32+
}
33+
catch{
34+
VM-Write-Log-Exception $_
35+
}
36+
37+
$rulesXmlPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)/rules.xml"
38+
$rulesXml = [xml](Get-Content $rulesXmlPath)
39+
40+
$rulesDir = Join-Path $toolDir "rules"
41+
$rulesConfigPath = Join-Path $toolDir "suricata.yaml"
42+
43+
$rulesConfig = ConvertFrom-Yaml (Get-Content -Raw -Path $rulesConfigPath)
44+
45+
$failures = @()
46+
$rules = $rulesXml.rules.rule
47+
48+
$tempToolDir = Join-Path ${Env:TEMP} $toolName
49+
$tempToolDir += ".vm"
50+
$tempRuleDir = Join-Path $tempToolDir "rules"
51+
52+
foreach ($rule in $rules) {
53+
54+
Write-Host "[+] Attempting to install rule: $($rule.name)"
55+
56+
$filePath = Join-Path $tempToolDir ([System.IO.Path]::GetFileName($rule.url))
57+
58+
try{
59+
Invoke-WebRequest -Uri $rule.url -OutFile $filePath
60+
61+
# If the file ends in .zip, unzip it
62+
if ($filePath -like '*.zip') {
63+
64+
Write-Host "ZIP file detected."
65+
66+
Get-ChocolateyUnzip -FileFullPath $filePath -Destination $tempRuleDir
67+
68+
if ($rule.innerFolder){
69+
$innerFolder = Join-Path $tempRuleDir $rule.innerFolder
70+
71+
Get-ChildItem -Path $innerFolder -File | ForEach-Object {
72+
Copy-Item -Path $_.FullName -Destination $tempRuleDir -Force
73+
}
74+
}
75+
76+
} elseif ($filePath -like '*.rules') {
77+
78+
Write-Host "Rules file detected. Moving to $tempRuleDir..."
79+
80+
Move-Item -Path $filePath -Destination $tempRuleDir
81+
82+
} else {
83+
throw "`t[!] Unsupported file type: '$filePath'. Only .zip and .rule are allowed."
84+
}
85+
} catch {
86+
$failures += $rule.name
87+
}
88+
}
89+
90+
$allRuleFiles = Get-ChildItem -Path $tempRuleDir -Recurse -File -Filter *.rules
91+
92+
foreach ($ruleFile in $allRuleFiles){
93+
Move-Item -Path $ruleFile.FullName -Destination $rulesDir -Force
94+
$rulesConfig.'rule-files' += $ruleFile.Name
95+
Write-Host "`t[+] Rule $($ruleFile.Name) added to $rulesDir..."
96+
}
97+
98+
$rulesConfig | ConvertTo-Yaml | Set-Content -Path $rulesConfigPath
99+
100+
if ($failures.Count -gt 0) {
101+
foreach ($module in $failures) {
102+
VM-Write-Log "ERROR" "Failed to install rule: $($rule.name)"
103+
}
104+
exit 1
105+
}
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-broken" url="https://rules.emergingthreats.net/open/suricata-7.0.3/emerging.rules.zip" innerFolder="rules"/>
4+
</rules>

0 commit comments

Comments
 (0)