Nenhuma Descrição

send-wazuh-test-events.sh 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCENARIO="${1:-all}"
  4. COUNT="${2:-1}"
  5. DELAY="${3:-0.3}"
  6. FOREVER="false"
  7. for arg in "${@:4}"; do
  8. case "${arg}" in
  9. --forever)
  10. FOREVER="true"
  11. ;;
  12. *)
  13. echo "error: unexpected argument '${arg}'"
  14. echo "usage: scripts/send-wazuh-test-events.sh [scenario] [count] [delay_seconds] [--forever]"
  15. exit 1
  16. ;;
  17. esac
  18. done
  19. WAZUH_SYSLOG_HOST="${WAZUH_SYSLOG_HOST:-127.0.0.1}"
  20. WAZUH_SYSLOG_PORT="${WAZUH_SYSLOG_PORT:-514}"
  21. WAZUH_TEST_SRC_IP="${WAZUH_TEST_SRC_IP:-203.0.113.10}"
  22. WAZUH_TEST_DOMAIN="${WAZUH_TEST_DOMAIN:-malicious.example}"
  23. WAZUH_TEST_USER="${WAZUH_TEST_USER:-guest.user}"
  24. if ! [[ "${COUNT}" =~ ^[0-9]+$ ]] || [[ "${COUNT}" -lt 1 ]]; then
  25. echo "error: count must be a positive integer"
  26. exit 1
  27. fi
  28. if ! [[ "${DELAY}" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
  29. echo "error: delay must be numeric (example: 0.5)"
  30. exit 1
  31. fi
  32. emit_syslog() {
  33. local msg="$1"
  34. local sent="false"
  35. if command -v nc >/dev/null 2>&1; then
  36. if printf "%s\n" "${msg}" | nc -u -w1 "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  37. sent="true"
  38. fi
  39. fi
  40. if [[ "${sent}" != "true" ]]; then
  41. if printf "%s\n" "${msg}" >"/dev/udp/${WAZUH_SYSLOG_HOST}/${WAZUH_SYSLOG_PORT}" 2>/dev/null; then
  42. sent="true"
  43. fi
  44. fi
  45. if [[ "${sent}" != "true" ]]; then
  46. echo "error: failed to send syslog event to ${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  47. echo "hint: install netcat or run with bash UDP support (/dev/udp)"
  48. return 1
  49. fi
  50. echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] sent: ${msg}"
  51. }
  52. random_id() {
  53. printf "%s" "evt-$(date +%s)-$RANDOM-$RANDOM"
  54. }
  55. send_ioc_dns() {
  56. local eid
  57. eid="$(random_id)"
  58. 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"
  59. }
  60. send_ioc_ips() {
  61. local eid
  62. eid="$(random_id)"
  63. 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"
  64. }
  65. send_vpn_outside_th() {
  66. local eid
  67. eid="$(random_id)"
  68. 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"
  69. }
  70. send_windows_auth_fail() {
  71. local eid
  72. eid="$(random_id)"
  73. 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"
  74. }
  75. send_once() {
  76. case "${SCENARIO}" in
  77. ioc_dns)
  78. send_ioc_dns
  79. ;;
  80. ioc_ips)
  81. send_ioc_ips
  82. ;;
  83. vpn_outside_th)
  84. send_vpn_outside_th
  85. ;;
  86. windows_auth_fail)
  87. send_windows_auth_fail
  88. ;;
  89. all)
  90. send_ioc_dns
  91. send_ioc_ips
  92. send_vpn_outside_th
  93. send_windows_auth_fail
  94. ;;
  95. *)
  96. echo "error: unknown scenario '${SCENARIO}'"
  97. echo "valid: ioc_dns | ioc_ips | vpn_outside_th | windows_auth_fail | all"
  98. exit 1
  99. ;;
  100. esac
  101. }
  102. if [[ "${FOREVER}" == "true" ]]; then
  103. echo "running forever with interval ${DELAY}s (Ctrl+C to stop)"
  104. trap 'echo; echo "stopped"; exit 0' INT TERM
  105. while true; do
  106. send_once
  107. sleep "${DELAY}"
  108. done
  109. else
  110. for ((i=1; i<=COUNT; i++)); do
  111. send_once
  112. if [[ "${i}" -lt "${COUNT}" ]]; then
  113. sleep "${DELAY}"
  114. fi
  115. done
  116. fi