Zapisy do 19 stycznia, 23:59
Sprawdź szczegóły: https://asdevops.pl/n8n
Współczesne środowisko bezpieczeństwa wymaga, aby wszystkie dostępne narzędzia działały w harmonii – od systemów ochrony antywirusowej po platformy SIEM.
Jednym z najpopularniejszych rozwiązań open‑source do monitorowania i analizy incydentów jest Wazuh. Warto wiedzieć, że dzięki kilku prostym konfiguracjom można go połączyć zarówno z wbudowanym systemem Windows Defender, jak i z chmurą VirusTotal – serwisem pozwalającym na analizę plików pod kątem malware.
Poniżej znajdziesz kompletny przewodnik, który pokaże Ci:
Jak przygotować środowisko Wazuh dla agentów Windows.
Jak włączyć i skonfigurować Windows Defender jako źródło alertów.
Jak integrować Wazuh z VirusTotal przy pomocy API.
Integracja Wazuh z Windows Defender:
Podglad zdarzeń
Dziennik aplikacji i usług –Microsoft — windows — Windows Defender — Operational
Prawy myszy — Właściwości <— kopiujemy „Pełna nazwę: Microsoft-Windows-Windows Defender/Operational
Przechodzimy w eksploratorze plików: C:\Program Files (x86)\ossec-agent <—uruchamiamy „win32ui.exe„
Klikamy View — View Config
Kopiujemy sekcję „localfile w „Active-response” nad sekcja „Policy monitoring”
Zamieniamy sekcję „active-response…” na „Microsoft-Windows-Windows Defender/Operational”
Oraz „syslog” na eventchannel
Zapisujemy i restartujemy agenta
W przeglądarce internetowej wyszukujemy „eikar file”, klikamy na link Wikipedii
Kopiujemy „X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*”
W notatniku kopiujemy ten ciąg znaków i zapisujemy w jakimś folderze. Windows Defender wykryje i usunie plik. W Wazuh wchodzimy w naszego Agenta Windows
Klikamy w „Threat Hunting” —> „Events”. Po chwili klikamy :”Refresh” i naszym oczom okazują się logi/powiadomienia z Windows Defender:
Integracja Wazuh z Virus Total:
https://documentation.wazuh.com/current/proof-of-concept-guide/detect-remove-malware-virustotal.html <—- Oficjalna dokumentacja Wazuh !!!
Na stronie www.virustotal.com tworzymy konto i kopiujemy klucz API
Konfiguracja w Wazuh — server management — setting:
Wklejamy:
<integration>
<name>virustotal</name>
<api_key>TWÓJ_KLUCZ_API</api_key>
<group>syscheck</group>
<alert_format>json</alert_format>
</integration>
W pierwszej kolejności w Windows wyłączamy ochronę w czasie rzeczywistym
Konfiguracja w Windows — c:\Program files )x86)\ossec-agent:
<directories check_all=”yes” realtime=”yes”>C:\Users\TWÓJ_UŻYTKOWNIK\Downloads\testy</directories>
Z strony https://www.python.org/downloads/windows/
Pobieramy
Uruchamiamy instalację prawym myszy — uruchom jako administrator i instalujemy zaznaczając poniższe:


Uruchamiamy Powershell jako Administrator instalujemy poniższe
pip install pyinstaller
Zamykamy powershell i uruchamiamy bez uprawnień Administratora
Tworzymy w notatniku plik o nazwie remove-threat.py i wklejamy
# Copyright (C) 2015-2025, Wazuh Inc.
# All rights reserved.
import os
import sys
import json
import datetime
import stat
import tempfile
import pathlib
if os.name == 'nt’:
LOG_FILE = „C:\\Program Files (x86)\\ossec-agent\\active-response\\active-responses.log”
else:
LOG_FILE = „/var/ossec/logs/active-responses.log”
ADD_COMMAND = 0
DELETE_COMMAND = 1
CONTINUE_COMMAND = 2
ABORT_COMMAND = 3
OS_SUCCESS = 0
OS_INVALID = -1
class message:
def __init__(self):
self.alert = „”
self.command = 0
def write_debug_file(ar_name, msg):
with open(LOG_FILE, mode=”a”) as log_file:
log_file.write(str(datetime.datetime.now().strftime(’%Y/%m/%d %H:%M:%S’)) + ” ” + ar_name + „: ” + msg +”\n”)
def setup_and_check_message(argv):
input_str = „”
for line in sys.stdin:
input_str = line
break
msg_obj = message()
try:
data = json.loads(input_str)
except ValueError:
write_debug_file(argv[0], 'Decoding JSON has failed, invalid input format’)
msg_obj.command = OS_INVALID
return msg_obj
msg_obj.alert = data
command = data.get(„command”)
if command == „add”:
msg_obj.command = ADD_COMMAND
elif command == „delete”:
msg_obj.command = DELETE_COMMAND
else:
msg_obj.command = OS_INVALID
write_debug_file(argv[0], 'Not valid command: ’ + command)
return msg_obj
def send_keys_and_check_message(argv, keys):
keys_msg = json.dumps({„version”: 1,”origin”:{„name”: argv[0],”module”:”active-response”},”command”:”check_keys”,”parameters”:{„keys”:keys}})
write_debug_file(argv[0], keys_msg)
print(keys_msg)
sys.stdout.flush()
input_str = „”
while True:
line = sys.stdin.readline()
if line:
input_str = line
break
try:
data = json.loads(input_str)
except ValueError:
write_debug_file(argv[0], 'Decoding JSON has failed, invalid input format’)
return OS_INVALID
action = data.get(„command”)
if action == „continue”:
return CONTINUE_COMMAND
elif action == „abort”:
return ABORT_COMMAND
else:
write_debug_file(argv[0], „Invalid value of 'command'”)
return OS_INVALID
def secure_delete_file(filepath_str, ar_name):
filepath = pathlib.Path(filepath_str)
# Reject NTFS alternate data streams
if ’::’ in filepath_str:
raise Exception(f”Refusing to delete ADS or NTFS stream: {filepath_str}”)
# Reject symbolic links and reparse points
if os.path.islink(filepath):
raise Exception(f”Refusing to delete symbolic link: {filepath}”)
attrs = os.lstat(filepath).st_file_attributes
if attrs & stat.FILE_ATTRIBUTE_REPARSE_POINT:
raise Exception(f”Refusing to delete reparse point: {filepath}”)
resolved_filepath = filepath.resolve()
# Ensure it’s a regular file
if not resolved_filepath.is_file():
raise Exception(f”Target is not a regular file: {resolved_filepath}”)
# Perform deletion
os.remove(resolved_filepath)
def main(argv):
write_debug_file(argv[0], „Started”)
msg = setup_and_check_message(argv)
if msg.command < 0:
sys.exit(OS_INVALID)
if msg.command == ADD_COMMAND:
alert = msg.alert[„parameters”][„alert”]
keys =
[„id”]]action = send_keys_and_check_message(argv, keys)
if action != CONTINUE_COMMAND:
if action == ABORT_COMMAND:
write_debug_file(argv[0], „Aborted”)
sys.exit(OS_SUCCESS)
else:
write_debug_file(argv[0], „Invalid command”)
sys.exit(OS_INVALID)
try:
file_path = alert[„data”][„virustotal”][„source”][„file”]
if os.path.exists(file_path):
secure_delete_file(file_path, argv[0])
write_debug_file(argv[0], json.dumps(msg.alert) + ” Successfully removed threat”)
else:
write_debug_file(argv[0], f”File does not exist: {file_path}”)
except OSError as error:
write_debug_file(argv[0], f”{json.dumps(msg.alert)}: OSError removing threat: {str(error)}”)
except Exception as e:
write_debug_file(argv[0], f”{json.dumps(msg.alert)}: Error removing threat: {str(e)}”)
else:
write_debug_file(argv[0], „Invalid command”)
write_debug_file(argv[0], „Ended”)
sys.exit(OS_SUCCESS)
if __name__ == „__main__”:
main(sys.argv)
W razie problemów z kodem powyżej w komentarzu dodam plik remove-threat.py
Kod z dokumentacji Wazuh jest błędny z nowsza wersja pythona, poprawiłem dla was kod !
Zapisujemy np na Pulpit

W powershell konwertujemy .py na .exe komenda:
pyinstaller –F remove-threat.py
Po utworzeniu plik znajduje się na pulpicie w folderze dist

Utworzony plik remove-threat.exe kopiujemy do lokalizacji
C:\Program Files (x86)\ossec-agent\active-response\bin
Następnie w powershellu jako Administrator restartujemy agenta Wazuha
Restart-Service -Name wazuh
Ponownie przechodzimy do serwara Wazuh i w Setting dadajemy na samym końcu
<command>
<name>remove-threat</name>
<executable>remove-threat.exe</executable>
<timeout_allowed>no</timeout_allowed>
</command>
<active-response>
<disabled>no</disabled>
<command>remove-threat</command>
<location>local</location>
<rules_id>87105</rules_id>
</active-response>
Zapisujemy
W terminalu serwara Wazuh nano /var/ossec/etc/rules/local_rules.xml

Wklejamy
<group name=”virustotal,”>
<rule id=”100092″ level=”12″>
<if_sid>657</if_sid>
<match>Successfully removed threat</match>
<description>$(parameters.program) removed threat located at $(parameters.alert.data.virustotal.source.file)</description>
</rule>
<rule id=”100093″ level=”12″>
<if_sid>657</if_sid>
<match>Error removing threat</match>
<description>Error removing threat located at $(parameters.alert.data.virustotal.source.file)</description>
</rule>
</group>
Następnie systemctl restart wazuh-manager
Tak jak w przypadku Windows defendera zapisujemy plik eikar w folderze
C:\Users\TWÓJ_UŻYTKOWNIK\Downloads\testy
W Wazuh widzimy akcję wykrycia i usunięcia pliku przez Virus Total:

