Keine Beschreibung

send-wazuh-test-events.sh 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 ! [[ "${COUNT}" =~ ^[0-9]+$ ]] || [[ "${COUNT}" -lt 1 ]]; then
  12. echo "error: count must be a positive integer"
  13. exit 1
  14. fi
  15. emit_syslog() {
  16. local msg="$1"
  17. local sent="false"
  18. if command -v nc >/dev/null 2>&1; then
  19. if printf "%s\n" "${msg}" | nc -u -w1 "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  20. sent="true"
  21. fi
  22. fi
  23. if [[ "${sent}" != "true" ]]; then
  24. if printf "%s\n" "${msg}" >"/dev/udp/${WAZUH_SYSLOG_HOST}/${WAZUH_SYSLOG_PORT}" 2>/dev/null; then
  25. sent="true"
  26. fi
  27. fi
  28. if [[ "${sent}" != "true" ]]; then
  29. echo "error: failed to send syslog event to ${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  30. echo "hint: install netcat or run with bash UDP support (/dev/udp)"
  31. return 1
  32. fi
  33. echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] sent: ${msg}"
  34. }
  35. random_id() {
  36. printf "%s" "evt-$(date +%s)-$RANDOM-$RANDOM"
  37. }
  38. send_ioc_dns() {
  39. local eid
  40. eid="$(random_id)"
  41. 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"
  42. }
  43. send_ioc_ips() {
  44. local eid
  45. eid="$(random_id)"
  46. 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"
  47. }
  48. send_vpn_outside_th() {
  49. local eid
  50. eid="$(random_id)"
  51. 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"
  52. }
  53. send_windows_auth_fail() {
  54. local eid
  55. eid="$(random_id)"
  56. 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"
  57. }
  58. send_once() {
  59. case "${SCENARIO}" in
  60. ioc_dns)
  61. send_ioc_dns
  62. ;;
  63. ioc_ips)
  64. send_ioc_ips
  65. ;;
  66. vpn_outside_th)
  67. send_vpn_outside_th
  68. ;;
  69. windows_auth_fail)
  70. send_windows_auth_fail
  71. ;;
  72. all)
  73. send_ioc_dns
  74. send_ioc_ips
  75. send_vpn_outside_th
  76. send_windows_auth_fail
  77. ;;
  78. *)
  79. echo "error: unknown scenario '${SCENARIO}'"
  80. echo "valid: ioc_dns | ioc_ips | vpn_outside_th | windows_auth_fail | all"
  81. exit 1
  82. ;;
  83. esac
  84. }
  85. for ((i=1; i<=COUNT; i++)); do
  86. send_once
  87. if [[ "${i}" -lt "${COUNT}" ]]; then
  88. sleep "${DELAY}"
  89. fi
  90. done