-
Notifications
You must be signed in to change notification settings - Fork 4
Wazuh Setup, Misc. Container Creation Fixes + Other Small Bug Fixes #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fa12eda
wazuh agent creation script
maxklema 85764f9
register agent scripts and js runner
maxklema 0ce2a89
Wazuh Agent Automatic Registration on Container Creation
maxklema ade0e12
added wazuh deletion script + modularity changes
maxklema dc14fa6
random root password generation
maxklema ba97369
local bruteforce decoder/rules added
maxklema 18431ae
ssh bruteforce rule and active response to mitigate bruteforce attack…
maxklema 39293a4
custom firewall drop script
maxklema f6eb25e
local rules/decoders + custom firewall-drop script
maxklema 7ba3a99
updated firewall-block to block raw-traffic at PREROUTING; proxmox la…
maxklema 0f9bde0
Updated Wazuh Files
maxklema 47b8acb
Updated Wazuh Files
maxklema 7b2f107
Merge branch 'mieweb:main' into wazuh
maxklema c11f1c3
Merge branch 'main' into wazuh
maxklema e90de99
Merge pull request #4 from maxklema/wazuh
maxklema 0b336aa
updated README
maxklema bc27387
fixed co-pilot PR suggestions
maxklema 648c8cc
ip blacklist updated to use ip set
maxklema cc49770
added ossec.conf configurations for Wazuh
maxklema fd66640
whitelisted 10.15.0.0 class B DHCP subnet and removed email settings
maxklema 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Wazuh/node_modules/ | ||
| Wazuh/package-lock.json | ||
| Wazuh/package.json | ||
| Wazuh/.env | ||
| Wazuh/.gitignore | ||
|
|
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,86 @@ | ||
| #!/bin/bash | ||
| # Custom Firewall Drop Script for Wazuh | ||
| # Template Generated by Copilot | ||
| # Last Modified by Maxwell Klema on August 11th, 2025 | ||
| # --------------------------------------------------- | ||
|
|
||
| # Usage: This script reads JSON input from STDIN | ||
| # Expected JSON format: | ||
| # { | ||
| # "version": 1, | ||
| # "command": "add|delete", | ||
| # "parameters": { | ||
| # "alert": { | ||
| # "data": { | ||
| # "srcip": "IP_ADDRESS" | ||
| # } | ||
| # } | ||
| # } | ||
| # } | ||
| # Full list: https://documentation.wazuh.com/current/user-manual/capabilities/active-response/custom-active-response-scripts.html | ||
|
|
||
| # Set script name for logging | ||
| LOG_FILE="/var/ossec/logs/active-responses.log" | ||
|
|
||
| # Function to log messages | ||
| log_message() { | ||
| echo "[$(date '+%Y/%m/%d %H:%M:%S')] $1" >> "$LOG_FILE" | ||
| } | ||
|
|
||
| # Read JSON input from STDIN | ||
| read -r INPUT | ||
|
|
||
| # Parse JSON to extract command and srcip | ||
| COMMAND=$(echo "$INPUT" | jq -r '.command // empty') | ||
| SRCIP=$(echo "$INPUT" | jq -r '.parameters.alert.data.srcip // empty') | ||
|
|
||
| # Validate input | ||
| if [[ -z "$COMMAND" || -z "$SRCIP" ]]; then | ||
| log_message "ERROR: Invalid input - missing command or srcip" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Validate IP address format | ||
| if ! [[ "$SRCIP" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | ||
| log_message "ERROR: Invalid IP address format: $SRCIP" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Function to add firewall rule | ||
| add_rule() { | ||
| local ip="$1" | ||
| ipset add blacklist "$ip" 2>/dev/null | ||
| if [[ $? -eq 0 ]]; then | ||
| log_message "Successfully added $ip to blacklist" | ||
| else | ||
| log_message "WARNING: Failed to add $ip to blacklist or it may already exist" | ||
| fi | ||
| } | ||
|
|
||
| # Function to remove firewall rule | ||
| remove_rule() { | ||
| local ip="$1" | ||
|
|
||
| ipset del blacklist "$ip" 2>/dev/null | ||
| if [[ $? -eq 0 ]]; then | ||
| log_message "Successfully removed $ip from blacklist" | ||
| else | ||
| log_message "WARNING: Failed to remove $ip from blacklist or it may not exist" | ||
| fi | ||
| } | ||
|
|
||
| # Execute based on command | ||
| case "$COMMAND" in | ||
| "add") | ||
| add_rule "$SRCIP" | ||
| ;; | ||
| "delete") | ||
| remove_rule "$SRCIP" | ||
| ;; | ||
| *) | ||
| log_message "ERROR: Unknown command: $COMMAND" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| exit 0 | ||
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,9 @@ | ||
| <!-- Sample Log --> | ||
|
|
||
| <!-- Aug 10 19:12:33 intern-phxdc-pve1 kernel: SSH_NEW: IN=vmbr0 OUT= MAC=24:6e:96:53:53:0a:90:b1:1c:06:d2:df:08:00 SRC=68.59.164.131 DST=10.15.0.4 LEN=64 TOS=0x00 PREC=0x00 TTL=52 ID=0 DF PROTO=TCP SPT=56148 DPT=2359 WINDOW=65535 RES=0x00 CWR ECE SYN URGP=0 --> | ||
| <decoder name="hypervisor-ssh-bruteforce"> | ||
| <program_name>kernel</program_name> | ||
| <prematch>SSH_NEW: IN=</prematch> | ||
| <regex>SSH_NEW: IN=(\S+) OUT=(\S*) MAC=(\S+) SRC=(\S+) DST=(\S+) LEN=(\d+) TOS=(\S+) PREC=(\S+) TTL=(\d+) ID=(\d+) DF PROTO=(\S+) SPT=(\d+) DPT=(\d+) WINDOW=(\d+) RES=(\S+) CWR ECE SYN URGP=(\d+)</regex> | ||
| <order>in_interface,out_interface,mac,srcip,dstip,len,tos,prec,ttl,id,protocol,srcport,dstport,window,res,urgp</order> | ||
| </decoder> |
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,38 @@ | ||
| <!-- Modify it at your will. --> | ||
| <!-- Copyright (C) 2015, Wazuh Inc. --> | ||
|
|
||
| <!-- Example --> | ||
| <group name="local,syslog,sshd,"> | ||
|
|
||
| <!-- | ||
| Dec 10 01:02:02 host sshd[1234]: Failed none for root from 1.1.1.1 port 1066 ssh2 | ||
| --> | ||
| <rule id="100001" level="5"> | ||
| <if_sid>5716</if_sid> | ||
| <srcip>1.1.1.1</srcip> | ||
| <description>sshd: authentication failed from IP 1.1.1.1.</description> | ||
| <group>authentication_failed,pci_dss_10.2.4,pci_dss_10.2.5,</group> | ||
| </rule> | ||
|
|
||
| </group> | ||
|
|
||
| <group name="local,iptables,sshd,bruteforce,"> | ||
|
|
||
| <!-- Base rule for SSH connection attempts detected by iptables --> | ||
| <rule id="100002" level="5"> | ||
| <decoded_as>hypervisor-ssh-bruteforce</decoded_as> | ||
| <description>SSH connection attempt detected by iptables from $(srcip) to port $(dstport)</description> | ||
| </rule> | ||
|
|
||
| <!-- Frequency rule for SSH brute force detection --> | ||
| <rule id="100003" level="10" frequency="5" timeframe="60"> | ||
| <if_matched_sid>100002</if_matched_sid> | ||
| <location>intern-phxdc-pve1</location> | ||
| <same_source_ip /> | ||
| <same_dstport /> | ||
| <description>Possible SSH brute force detected - $(frequency) attempts in $(timeframe) seconds from $(srcip)</description> | ||
| <mitre> | ||
| <id>T1110</id> | ||
| </mitre> | ||
| </rule> | ||
| </group> |
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,140 @@ | ||
| // Script to manage Wazuh Agents on the Wazuh Manager | ||
| // Last Modified on August 7th, 2025 by Maxwell Klema | ||
| // ------------------------------------------------- | ||
|
|
||
| const axios = require('axios'); | ||
| const env = require('dotenv').config({ path: '/var/lib/vz/snippets/Wazuh/.env', quiet: true}); | ||
|
|
||
| const authConfig = { | ||
| method: 'post', | ||
| url: 'https://wazuh-server.opensource.mieweb.org/security/user/authenticate', | ||
| maxBodyLength: Infinity, | ||
| headers: { | ||
| 'Authorization': `Basic ${Buffer.from(`${process.env.API_USERNAME}:${process.env.API_PASSWORD}`).toString('base64')}`, | ||
| } | ||
| }; | ||
|
|
||
| async function getJWTToken() { | ||
| const response = await axios.request(authConfig); | ||
| if (response.status !== 200) { | ||
| return null; | ||
| } | ||
| return response.data.data.token; | ||
| } | ||
|
|
||
| async function getAgents() { | ||
|
|
||
| const JWT = await getJWTToken(); | ||
| if (!JWT) { | ||
| console.log('fail'); | ||
| return; | ||
| } | ||
|
|
||
| let config = { | ||
| method: 'get', | ||
| url: 'https://wazuh-server.opensource.mieweb.org/agents?', | ||
| maxBodyLength: Infinity, | ||
| headers: { | ||
| 'content-type': 'application/json', | ||
| 'Authorization': `Bearer ${JWT}`, | ||
| } | ||
| } | ||
|
|
||
| axios.request(config).then((response) => { | ||
| const agents = response.data.data.affected_items; | ||
| if (!agents || agents.length === 0) { | ||
| console.log('fail'); | ||
| return; | ||
| } | ||
|
|
||
| agents.forEach(agent => { | ||
| console.log(agent.name); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function addAgent(containerName, containerIP) { | ||
|
|
||
| const JWT = await getJWTToken(); | ||
| if (!JWT) { | ||
| console.log('fail'); | ||
| return; | ||
| } | ||
|
|
||
| // Add the Agent to the Manager | ||
| let agentConfig = { | ||
| method: 'post', | ||
| url: 'https://wazuh-server.opensource.mieweb.org/agents?pretty=true', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'Authorization': `Bearer ${JWT}` | ||
| }, | ||
| data: { | ||
| 'name': containerName, | ||
| 'ip': containerIP | ||
| } | ||
| }; | ||
|
|
||
| const response = await axios.request(agentConfig); | ||
| if (response.status !== 200) { | ||
| console.log('fail'); | ||
| } | ||
| const agentKey = response.data.data.key; | ||
| console.log(agentKey); | ||
| } | ||
|
|
||
| async function deleteAgent(agentName) { | ||
|
|
||
| const JWT = await getJWTToken(); | ||
|
|
||
| if (!JWT) { | ||
| console.log('fail'); | ||
| return; | ||
| } | ||
|
|
||
| const agent_id = await getAgentIDByName(agentName, JWT); | ||
|
|
||
| if (!agent_id) { | ||
| console.log('fail'); | ||
| return; | ||
| } | ||
|
|
||
| let config = { | ||
| method: 'delete', | ||
| url: `https://wazuh-server.opensource.mieweb.org/agents/?agents_list=${agent_id}&status=all&older_than=0s`, | ||
| maxBodyLength: Infinity, | ||
| headers: { | ||
| 'content-type': 'application/json', | ||
| 'Authorization': `Bearer ${JWT}`, | ||
| } | ||
| }; | ||
|
|
||
| axios.request(config).then((response) => { | ||
| if (response.status !== 200) { | ||
| console.log('fail'); | ||
| return; | ||
| } | ||
| console.log('success'); | ||
| }).catch((error) => { | ||
| console.log('fail'); | ||
| }); | ||
| } | ||
|
|
||
| async function getAgentIDByName(agentName, JWT) { | ||
| let config = { | ||
| method: 'get', | ||
| url: 'https://wazuh-server.opensource.mieweb.org/agents/?name=' + agentName, | ||
| maxBodyLength: Infinity, | ||
| headers: { | ||
| 'Authorization': `Bearer ${JWT}` | ||
| } | ||
| }; | ||
|
|
||
| const response = await axios.request(config); | ||
| if (response.status !== 200) { | ||
| return null; | ||
| } | ||
| return response.data.data.affected_items[0].id; | ||
| } | ||
|
|
||
| module.exports = { getAgents, addAgent, deleteAgent }; |
Oops, something went wrong.
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.
The big thing I wanted to point out that I forgot to mention was the move to ipset for better performance on a larger scope of IP's, but it looks like this was already changed.
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.
Yes, it provides much better performance and cleaner code!