Nessuna descrizione

send-wazuh-test-events.sh 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCENARIO="${1:-all}"
  4. COUNT="${2:-1}"
  5. DELAY="${3:-0.3}"
  6. WAZUH_SYSLOG_HOST="${WAZUH_SYSLOG_HOST:-127.0.0.1}"
  7. WAZUH_SYSLOG_PORT="${WAZUH_SYSLOG_PORT:-514}"
  8. WAZUH_TEST_SRC_IP="${WAZUH_TEST_SRC_IP:-203.0.113.10}"
  9. WAZUH_TEST_DOMAIN="${WAZUH_TEST_DOMAIN:-malicious.example}"
  10. WAZUH_TEST_USER="${WAZUH_TEST_USER:-guest.user}"
  11. if ! command -v nc >/dev/null 2>&1; then
  12. echo "error: nc (netcat) is required"
  13. exit 1
  14. fi
  15. if ! [[ "${COUNT}" =~ ^[0-9]+$ ]] || [[ "${COUNT}" -lt 1 ]]; then
  16. echo "error: count must be a positive integer"
  17. exit 1
  18. fi
  19. emit_syslog() {
  20. local msg="$1"
  21. if ! printf "%s\n" "${msg}" | nc -u -w1 "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  22. echo "error: failed to send syslog event to ${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  23. return 1
  24. fi
  25. echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] sent: ${msg}"
  26. }
  27. random_id() {
  28. printf "%s" "evt-$(date +%s)-$RANDOM-$RANDOM"
  29. }
  30. send_ioc_dns() {
  31. local eid
  32. eid="$(random_id)"
  33. emit_syslog "<134>$(date '+%b %d %H:%M:%S') soc-test soc_mvp_test=true event_id=${eid} event_type=ioc_dns src_ip=${WAZUH_TEST_SRC_IP} query=${WAZUH_TEST_DOMAIN} action=blocked severity=medium"
  34. }
  35. send_ioc_ips() {
  36. local eid
  37. eid="$(random_id)"
  38. emit_syslog "<134>$(date '+%b %d %H:%M:%S') soc-test soc_mvp_test=true event_id=${eid} event_type=ioc_ips src_ip=${WAZUH_TEST_SRC_IP} dst_ip=198.51.100.55 signature='Known C2 Beacon' severity=high"
  39. }
  40. send_vpn_outside_th() {
  41. local eid
  42. eid="$(random_id)"
  43. emit_syslog "<134>$(date '+%b %d %H:%M:%S') soc-test soc_mvp_test=true event_id=${eid} event_type=vpn_geo_anomaly user=${WAZUH_TEST_USER} src_ip=${WAZUH_TEST_SRC_IP} country=US success=true severity=high"
  44. }
  45. send_windows_auth_fail() {
  46. local eid
  47. eid="$(random_id)"
  48. emit_syslog "<134>$(date '+%b %d %H:%M:%S') soc-test soc_mvp_test=true event_id=${eid} event_type=windows_auth_fail user=${WAZUH_TEST_USER} src_ip=${WAZUH_TEST_SRC_IP} attempts=7 severity=medium"
  49. }
  50. send_once() {
  51. case "${SCENARIO}" in
  52. ioc_dns)
  53. send_ioc_dns
  54. ;;
  55. ioc_ips)
  56. send_ioc_ips
  57. ;;
  58. vpn_outside_th)
  59. send_vpn_outside_th
  60. ;;
  61. windows_auth_fail)
  62. send_windows_auth_fail
  63. ;;
  64. all)
  65. send_ioc_dns
  66. send_ioc_ips
  67. send_vpn_outside_th
  68. send_windows_auth_fail
  69. ;;
  70. *)
  71. echo "error: unknown scenario '${SCENARIO}'"
  72. echo "valid: ioc_dns | ioc_ips | vpn_outside_th | windows_auth_fail | all"
  73. exit 1
  74. ;;
  75. esac
  76. }
  77. for ((i=1; i<=COUNT; i++)); do
  78. send_once
  79. if [[ "${i}" -lt "${COUNT}" ]]; then
  80. sleep "${DELAY}"
  81. fi
  82. done