Geen omschrijving

send-wazuh-proposal-appendix-c-events.sh 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Usage:
  4. # scripts/send-wazuh-proposal-appendix-c-events.sh [selector] [count] [delay_seconds] [--forever]
  5. #
  6. # selector:
  7. # all | c1 | c2 | c3 | <usecase_id>
  8. # example usecase_id: C1-01, C2-03, C3-04
  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-c-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. VPN_HOST="${VPN_HOST:-fgt-vpn-01}"
  30. WIN_HOST="${WIN_HOST:-win-ad-01}"
  31. SIM_USER="${SIM_USER:-alice.admin}"
  32. SIM_SERVICE_USER="${SIM_SERVICE_USER:-svc_backup}"
  33. SIM_SRC_IP="${SIM_SRC_IP:-203.0.113.44}"
  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. emit_syslog() {
  43. local msg="$1"
  44. local sent="false"
  45. if [[ "${DRY_RUN}" == "1" ]]; then
  46. echo "[DRY_RUN $(date -u +'%Y-%m-%dT%H:%M:%SZ')] ${msg}"
  47. return 0
  48. fi
  49. if command -v nc >/dev/null 2>&1; then
  50. if printf "%s\n" "${msg}" | nc -u -w1 "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  51. sent="true"
  52. fi
  53. fi
  54. if [[ "${sent}" != "true" ]]; then
  55. if printf "%s\n" "${msg}" >"/dev/udp/${WAZUH_SYSLOG_HOST}/${WAZUH_SYSLOG_PORT}" 2>/dev/null; then
  56. sent="true"
  57. fi
  58. fi
  59. if [[ "${sent}" != "true" ]]; then
  60. echo "error: failed to send syslog event to ${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  61. return 1
  62. fi
  63. echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] sent: ${msg}"
  64. }
  65. selector_matches() {
  66. local id="$1"
  67. local section="$2"
  68. local sel
  69. sel="$(echo "${SELECTOR}" | tr '[:upper:]' '[:lower:]')"
  70. local idl
  71. idl="$(echo "${id}" | tr '[:upper:]' '[:lower:]')"
  72. local sec
  73. sec="$(echo "${section}" | tr '[:upper:]' '[:lower:]')"
  74. [[ "${sel}" == "all" || "${sel}" == "${sec}" || "${sel}" == "${idl}" ]]
  75. }
  76. emit_c_usecase() {
  77. local id="$1"
  78. local section="$2"
  79. local severity="$3"
  80. local host="$4"
  81. local usecase="$5"
  82. local body="$6"
  83. selector_matches "${id}" "${section}" || return 0
  84. emit_syslog "<182>$(date '+%b %d %H:%M:%S') ${host} soc_mvp_test=true source=windows section=${section} usecase_id=${id} severity=${severity} usecase=\"${usecase}\" ${body}"
  85. sleep "${EVENT_DELAY}"
  86. }
  87. emit_c1() {
  88. # Two successful logins by same user with impossible travel profile
  89. emit_c_usecase "C1-01" "C1" "high" "${VPN_HOST}" \
  90. "Impossible Travel Detection" \
  91. "event_type=vpn_login_success event_id=4624 success=true user=\"${SIM_USER}\" src_ip=203.150.10.10 country=TH src_lat=13.7563 src_lon=100.5018 dst_host=vpn-gw-01"
  92. emit_c_usecase "C1-01" "C1" "high" "${VPN_HOST}" \
  93. "Impossible Travel Detection" \
  94. "event_type=vpn_login_success event_id=4624 success=true user=\"${SIM_USER}\" src_ip=8.8.8.8 country=US src_lat=37.3861 src_lon=-122.0839 dst_host=vpn-gw-01"
  95. }
  96. emit_c2() {
  97. emit_c_usecase "C2-01" "C2" "high" "${WIN_HOST}" \
  98. "Privileged Account Usage Outside Business Hours" \
  99. "event_type=windows_auth_success event_id=4624 success=true user=\"administrator\" is_admin=true src_ip=${SIM_SRC_IP} logon_type=10 dst_host=dc-01"
  100. emit_c_usecase "C2-02" "C2" "medium" "${WIN_HOST}" \
  101. "Dormant Account Activation" \
  102. "event_type=windows_auth_success event_id=4624 success=true user=\"legacy.user\" src_ip=198.51.100.55 dst_host=dc-01"
  103. emit_c_usecase "C2-03" "C2" "high" "${WIN_HOST}" \
  104. "Service Account Interactive Logon" \
  105. "event_type=windows_auth_success event_id=4624 success=true user=\"${SIM_SERVICE_USER}\" account_type=service is_service=true logon_type=10 src_ip=198.51.100.66 dst_host=filesrv-01"
  106. emit_c_usecase "C2-04" "C2" "high" "${WIN_HOST}" \
  107. "Rapid Privilege Escalation then Sensitive Access" \
  108. "event_type=windows_privilege_group_add event_id=4732 user=\"${SIM_USER}\" action=group_add is_admin=true src_ip=10.10.1.20 dst_host=dc-01"
  109. emit_c_usecase "C2-04" "C2" "high" "${WIN_HOST}" \
  110. "Rapid Privilege Escalation then Sensitive Access" \
  111. "event_type=windows_file_share_access event_id=5145 user=\"${SIM_USER}\" action=share_access src_ip=10.10.1.20 dst_host=filesrv-02 dst_port=445"
  112. }
  113. emit_c3() {
  114. emit_c_usecase "C3-01" "C3" "high" "${WIN_HOST}" \
  115. "Multiple Authentication Success Across Hosts" \
  116. "event_type=windows_auth_success event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=app-01 dst_port=3389"
  117. emit_c_usecase "C3-01" "C3" "high" "${WIN_HOST}" \
  118. "Multiple Authentication Success Across Hosts" \
  119. "event_type=windows_auth_success event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=app-02 dst_port=3389"
  120. emit_c_usecase "C3-01" "C3" "high" "${WIN_HOST}" \
  121. "Multiple Authentication Success Across Hosts" \
  122. "event_type=windows_auth_success event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=db-01 dst_port=3389"
  123. emit_c_usecase "C3-01" "C3" "high" "${WIN_HOST}" \
  124. "Multiple Authentication Success Across Hosts" \
  125. "event_type=windows_auth_success event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=db-02 dst_port=3389"
  126. emit_c_usecase "C3-01" "C3" "high" "${WIN_HOST}" \
  127. "Multiple Authentication Success Across Hosts" \
  128. "event_type=windows_auth_success event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=fs-01 dst_port=3389"
  129. emit_c_usecase "C3-02" "C3" "high" "${WIN_HOST}" \
  130. "SMB/RDP Lateral Burst Pattern" \
  131. "event_type=windows_lateral_movement event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=rdp-01 dst_port=3389"
  132. emit_c_usecase "C3-02" "C3" "high" "${WIN_HOST}" \
  133. "SMB/RDP Lateral Burst Pattern" \
  134. "event_type=windows_lateral_movement event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=smb-01 dst_port=445"
  135. emit_c_usecase "C3-02" "C3" "high" "${WIN_HOST}" \
  136. "SMB/RDP Lateral Burst Pattern" \
  137. "event_type=windows_lateral_movement event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=smb-02 dst_port=445"
  138. emit_c_usecase "C3-02" "C3" "high" "${WIN_HOST}" \
  139. "SMB/RDP Lateral Burst Pattern" \
  140. "event_type=windows_lateral_movement event_id=4624 success=true user=\"ops.user\" src_ip=10.20.0.15 dst_host=rdp-02 dst_port=3389"
  141. emit_c_usecase "C3-03" "C3" "critical" "${WIN_HOST}" \
  142. "Admin Accessing Many Servers Rapidly" \
  143. "event_type=windows_auth_success event_id=4624 success=true user=\"administrator\" is_admin=true src_ip=10.20.0.22 dst_host=adm-01 dst_port=3389"
  144. emit_c_usecase "C3-03" "C3" "critical" "${WIN_HOST}" \
  145. "Admin Accessing Many Servers Rapidly" \
  146. "event_type=windows_auth_success event_id=4624 success=true user=\"administrator\" is_admin=true src_ip=10.20.0.22 dst_host=adm-02 dst_port=3389"
  147. emit_c_usecase "C3-03" "C3" "critical" "${WIN_HOST}" \
  148. "Admin Accessing Many Servers Rapidly" \
  149. "event_type=windows_auth_success event_id=4624 success=true user=\"administrator\" is_admin=true src_ip=10.20.0.22 dst_host=adm-03 dst_port=3389"
  150. emit_c_usecase "C3-03" "C3" "critical" "${WIN_HOST}" \
  151. "Admin Accessing Many Servers Rapidly" \
  152. "event_type=windows_auth_success event_id=4624 success=true user=\"administrator\" is_admin=true src_ip=10.20.0.22 dst_host=adm-04 dst_port=3389"
  153. emit_c_usecase "C3-03" "C3" "critical" "${WIN_HOST}" \
  154. "Admin Accessing Many Servers Rapidly" \
  155. "event_type=windows_auth_success event_id=4624 success=true user=\"administrator\" is_admin=true src_ip=10.20.0.22 dst_host=adm-05 dst_port=3389"
  156. # C3-04 scanning behavior: many destination ports from same source
  157. for port in 80 88 135 139 389 443 445 464 636 1025 1433 1521 2049 2375 3306 3389 5432 5985 8080 8443; do
  158. emit_c_usecase "C3-04" "C3" "medium" "${WIN_HOST}" \
  159. "Internal Scanning Enumeration Behavior" \
  160. "event_type=internal_scan src_ip=10.30.0.40 dst_host=10.30.10.$((RANDOM % 10 + 1)) dst_port=${port} action=connect_attempt"
  161. done
  162. }
  163. emit_selected_set() {
  164. local sel
  165. sel="$(echo "${SELECTOR}" | tr '[:upper:]' '[:lower:]')"
  166. case "${sel}" in
  167. all)
  168. emit_c1
  169. emit_c2
  170. emit_c3
  171. ;;
  172. c1|c1-*)
  173. emit_c1
  174. ;;
  175. c2|c2-*)
  176. emit_c2
  177. ;;
  178. c3|c3-*)
  179. emit_c3
  180. ;;
  181. *)
  182. emit_c1
  183. emit_c2
  184. emit_c3
  185. ;;
  186. esac
  187. }
  188. echo "starting proposal Appendix C log simulator"
  189. echo "selector=${SELECTOR} count=${COUNT} delay=${DELAY}s event_delay=${EVENT_DELAY}s dry_run=${DRY_RUN}"
  190. echo "target=${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  191. if [[ "${FOREVER}" == "true" ]]; then
  192. echo "running forever with interval ${DELAY}s (Ctrl+C to stop)"
  193. trap 'echo; echo "stopped"; exit 0' INT TERM
  194. while true; do
  195. emit_selected_set
  196. sleep "${DELAY}"
  197. done
  198. else
  199. for ((i=1; i<=COUNT; i++)); do
  200. emit_selected_set
  201. if [[ "${i}" -lt "${COUNT}" ]]; then
  202. sleep "${DELAY}"
  203. fi
  204. done
  205. echo "done"
  206. fi