-
Notifications
You must be signed in to change notification settings - Fork 89
Suricate Package Addition #1375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PrajeetGuha
wants to merge
1
commit into
mandiant:main
Choose a base branch
from
PrajeetGuha:update-common
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd"> | ||
| <metadata> | ||
| <id>suricata.vm</id> | ||
| <version>7.0.10</version> | ||
| <authors>Open Information Security Foundation</authors> | ||
| <description>Suricata is a network IDS, IPS and NSM engine developed by the OISF and the Suricata community.</description> | ||
| <dependencies> | ||
| <dependency id="common.vm" version="0.0.0.20250206" /> | ||
| <dependency id="npcap.vm" version="1.80.20250219" /> | ||
| </dependencies> | ||
| <tags>Networking</tags> | ||
| </metadata> | ||
| </package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| $ErrorActionPreference = 'Stop' | ||
| Import-Module vm.common -Force -DisableNameChecking | ||
|
|
||
| try{ | ||
| $toolName = 'suricata' | ||
| $category = VM-Get-Category($MyInvocation.MyCommand.Definition) | ||
| $toolDir = Join-Path ${Env:ProgramFiles} $toolName | ||
| $executablePath = Join-Path $toolDir "$toolName.exe" | ||
| $exeUrl = "https://www.openinfosecfoundation.org/download/windows/Suricata-7.0.10-1-64bit.msi" | ||
| $sha256 = "b32a6ca8a793a603a23de307c83831c874099f50bbcd2710ee8325d69a49fb44" | ||
|
|
||
| $packageArgs = @{ | ||
| toolName = $toolName | ||
| category = $category | ||
| filetype = "MSI" | ||
| silentArgs = "/qn /norestart" | ||
| executablePath = $executablePath | ||
| url = $exeUrl | ||
| sha256 = $sha256 | ||
| consoleApp = $true | ||
| } | ||
|
|
||
| VM-Install-With-Installer @packageArgs | ||
|
|
||
| # Delete default desktop shortcut | ||
| $desktopShortcutPath = "${Env:HomeDrive}\Users\*\Desktop\$toolName*.lnk" | ||
| Remove-Item -Path $desktopShortcutPath -ErrorAction SilentlyContinue | ||
|
|
||
| # Rules configuration and download | ||
| $rulesXmlPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)/rules.xml" | ||
| $rulesXml = [xml](Get-Content $rulesXmlPath) | ||
| $rulesDir = Join-Path $toolDir "rules" -Resolve | ||
| $rules = $rulesXml.rules.rule | ||
|
|
||
| # Tempdir for rules been added | ||
| # Rules are added to tempdir before been added to default rule folder as other default rules exist in default folder | ||
| # Rules filenames are needed for adding to config files | ||
| $tempToolDir = Join-Path ${Env:TEMP} "$toolName.vm" | ||
| $tempRuleDir = Join-Path $tempToolDir "rules" | ||
|
|
||
| foreach ($rule in $rules) { | ||
| VM-Write-Log "INFO" "Attempting to install rule: $($rule.name)" | ||
| $filePath = Join-Path $tempToolDir ([System.IO.Path]::GetFileName($rule.url)) | ||
|
|
||
| # Create rule specific temp folder | ||
| $tempRuleSpecificFolder = Join-Path $tempRuleDir $rule.name | ||
| New-Item $tempRuleSpecificFolder -ItemType Directory -Force | ||
| try{ | ||
| Invoke-WebRequest -Uri $rule.url -OutFile $filePath -ErrorAction Stop | ||
| # If the rule URL is a ZIP archive (collection of multiple rule files) | ||
| if ($filePath -like '*.zip') { | ||
| VM-Write-Log "INFO" "ZIP file detected." | ||
| Get-ChocolateyUnzip -FileFullPath $filePath -Destination $tempRuleSpecificFolder | Out-Null | ||
|
|
||
| # If the rule URL is one rules file | ||
| } elseif ($filePath -like '*.rules') { | ||
| VM-Write-Log "INFO" "Rules file detected. Moving to $tempRuleSpecificFolder..." | ||
| Move-Item -Path $filePath -Destination $tempRuleSpecificFolder | ||
|
|
||
| # Any other types of url resource is unsupported | ||
| } else { | ||
| throw "Unsupported file type: '$filePath'. Only .zip and .rule are allowed." | ||
| } | ||
| } catch { | ||
| VM-Write-Log "WARN" "Failed rule: $filePath. Cause: $($_.Exception.Message)" | ||
| } | ||
| } | ||
|
|
||
| $allRuleFiles = Get-ChildItem -Path $tempRuleDir -Recurse -File -Filter *.rules | ||
|
|
||
| $rulesConfigPath = Join-Path $toolDir "suricata.yaml" -Resolve | ||
| $rulesConfigLines = Get-Content -Path $rulesConfigPath | ||
|
|
||
| # Index of the location in the yaml where `rule-files:` is specified | ||
| # Also collect all rules references in the config file | ||
| $ruleFilesIndex = $null | ||
| $rulesList = @() | ||
| for ($i = 0; $i -lt $rulesConfigLines.Count; $i++) { | ||
| $line = $rulesConfigLines[$i].Trim() | ||
|
|
||
| # Set ruleFilesIndex when `rule-files:` found | ||
| if ($line -match '^rule-files:$') { | ||
| $ruleFilesIndex = $i | ||
| continue | ||
| } | ||
|
|
||
| # Only when `rule-files` found, collect the rules references | ||
| if ($null -ne $ruleFilesIndex){ | ||
|
|
||
| # Break rules reference search if the line does not start with '- .*' | ||
| if ($line -notmatch "- .*"){ | ||
| break | ||
| } | ||
| else{ | ||
| if ($line -match '\.rules$'){ | ||
| $cleanLine = $line.TrimStart('- ') | ||
| $rulesList += $cleanLine | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # The config file must have `rule-files:`, throw an error if not found | ||
| if ($null -eq $ruleFilesIndex) { | ||
| throw "Line with 'rule-files:' string not found in the config file." | ||
| } | ||
|
|
||
| # Move all rule files in temp rule folder to the suricata rule folder | ||
| # Add rules to `suricata.yaml` | ||
| VM-Write-Log "INFO" "Moving rule-files to $rulesDir..." | ||
| foreach ($ruleFile in $allRuleFiles){ | ||
| Move-Item -Path $ruleFile.FullName -Destination $rulesDir -Force | ||
| if (-not ($rulesList -contains $ruleFile.Name)){ | ||
| $newRuleLine = " - $($ruleFile.Name)" | ||
| # Add rule to config file | ||
| $rulesConfigLines = $rulesConfigLines[0..$ruleFilesIndex] + $newRuleLine + $rulesConfigLines[($ruleFilesIndex + 1)..($rulesConfigLines.Length - 1)] | ||
| VM-Write-Log "INFO" "[+] Rule-file $($ruleFile.Name) added to $rulesDir. Added rule-file reference to config file." | ||
| } | ||
| else{ | ||
| VM-Write-Log "INFO" "[+] Rule-file $($ruleFile.Name) added to $rulesDir. Rule-file reference already exist in config file." | ||
| } | ||
| } | ||
|
|
||
| # Save the updated content back to the file | ||
| $rulesConfigLines | Set-Content -Path $rulesConfigPath | ||
| } | ||
| catch{ | ||
| VM-Write-Log-Exception $_ | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| $ErrorActionPreference = 'Continue' | ||
| Import-Module vm.common -Force -DisableNameChecking | ||
|
|
||
| $toolName = 'suricata' | ||
| $category = VM-Get-Category($MyInvocation.MyCommand.Definition) | ||
|
|
||
| VM-Uninstall-With-Uninstaller $toolName $category "MSI" "/qn /norestart" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <rules> | ||
| <rule name="emerging-all" url="https://rules.emergingthreats.net/open/suricata-7.0.3/emerging.rules.zip" innerFolder="rules"/> | ||
| </rules> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand this change. 😕 Can you please explain me why this is needed @PrajeetGuha?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VM-Packages/packages/common.vm/tools/vm.common/vm.common.psm1
Line 115 in 73997f2
has $level=FATAL but the ValidateSet does not have it. This change is not related to this package implementation though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] It is a good practice to not commit unrelated changes in the same commit. But I see why this is an enhancement now. 😉