Keine Beschreibung

send-wazuh-proposal-required-events.sh 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Usage:
  4. # scripts/send-wazuh-proposal-required-events.sh [selector] [count] [delay_seconds]
  5. #
  6. # selector:
  7. # all | a1 | a2 | a3 | a4 | <usecase_id>
  8. # example usecase_id: A2-01, A3-05, A4-24
  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-required-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. FGT_DEVNAME="${FGT_DEVNAME:-FGT80F-Branch01}"
  30. FGT_DEVID="${FGT_DEVID:-FGT80FTK20000001}"
  31. WIN_HOST="${WIN_HOST:-win-dc01}"
  32. DNS_HOST="${DNS_HOST:-dns-fw-01}"
  33. SIM_VPN_USER="${SIM_VPN_USER:-remote.user}"
  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. rand_private_ip() {
  54. echo "10.$((RANDOM % 20 + 10)).$((RANDOM % 200 + 1)).$((RANDOM % 240 + 10))"
  55. }
  56. rand_domain() {
  57. echo "ioc-$((RANDOM % 9000 + 1000)).malicious.example"
  58. }
  59. emit_syslog() {
  60. local msg="$1"
  61. local sent="false"
  62. if [[ "${DRY_RUN}" == "1" ]]; then
  63. echo "[DRY_RUN $(date -u +'%Y-%m-%dT%H:%M:%SZ')] ${msg}"
  64. return 0
  65. fi
  66. if command -v nc >/dev/null 2>&1; then
  67. if printf "%s\n" "${msg}" | nc -u -w1 "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  68. sent="true"
  69. fi
  70. fi
  71. if [[ "${sent}" != "true" ]]; then
  72. if printf "%s\n" "${msg}" >"/dev/udp/${WAZUH_SYSLOG_HOST}/${WAZUH_SYSLOG_PORT}" 2>/dev/null; then
  73. sent="true"
  74. fi
  75. fi
  76. if [[ "${sent}" != "true" ]]; then
  77. echo "error: failed to send syslog event to ${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  78. return 1
  79. fi
  80. echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] sent: ${msg}"
  81. }
  82. selector_matches() {
  83. local id="$1"
  84. local section="$2"
  85. local sel
  86. sel="$(echo "${SELECTOR}" | tr '[:upper:]' '[:lower:]')"
  87. local idl
  88. idl="$(echo "${id}" | tr '[:upper:]' '[:lower:]')"
  89. local sec
  90. sec="$(echo "${section}" | tr '[:upper:]' '[:lower:]')"
  91. [[ "${sel}" == "all" || "${sel}" == "${sec}" || "${sel}" == "${idl}" ]]
  92. }
  93. emit_fgt_usecase() {
  94. local id="$1"
  95. local section="$2"
  96. local severity="$3"
  97. local usecase="$4"
  98. local body="$5"
  99. selector_matches "${id}" "${section}" || return 0
  100. emit_syslog "<190>date=$(date '+%Y-%m-%d') time=$(date '+%H:%M:%S') devname=\"${FGT_DEVNAME}\" devid=\"${FGT_DEVID}\" eventtime=$(date +%s) vd=\"root\" soc_mvp_test=true source=fortigate section=${section} usecase_id=${id} severity=${severity} usecase=\"${usecase}\" ${body}"
  101. sleep "${EVENT_DELAY}"
  102. }
  103. emit_dns_usecase() {
  104. local id="$1"
  105. local section="$2"
  106. local severity="$3"
  107. local usecase="$4"
  108. local body="$5"
  109. selector_matches "${id}" "${section}" || return 0
  110. emit_syslog "<189>$(date '+%b %d %H:%M:%S') ${DNS_HOST} soc_mvp_test=true source=dns section=${section} usecase_id=${id} severity=${severity} usecase=\"${usecase}\" ${body}"
  111. sleep "${EVENT_DELAY}"
  112. }
  113. emit_windows_usecase() {
  114. local id="$1"
  115. local section="$2"
  116. local severity="$3"
  117. local usecase="$4"
  118. local body="$5"
  119. selector_matches "${id}" "${section}" || return 0
  120. emit_syslog "<182>$(date '+%b %d %H:%M:%S') ${WIN_HOST} soc_mvp_test=true source=windows section=${section} usecase_id=${id} severity=${severity} usecase=\"${usecase}\" ${body}"
  121. sleep "${EVENT_DELAY}"
  122. }
  123. emit_a1() {
  124. local sip
  125. local domain
  126. local mip
  127. sip="$(rand_private_ip)"
  128. domain="$(rand_domain)"
  129. mip="$(rand_public_ip)"
  130. emit_dns_usecase "A1-01" "A1" "medium" \
  131. "DNS Network Traffic Communicate to Malicious Domain" \
  132. "event_type=ioc_dns_traffic src_ip=${sip} query=${domain} resolved_ip=${mip} action=blocked"
  133. emit_dns_usecase "A1-02" "A1" "medium" \
  134. "DNS Network Traffic Malicious Domain IOCs Detection" \
  135. "event_type=ioc_domain_match src_ip=${sip} ioc_type=domain ioc_value=${domain} feed=threatintel_main confidence=high action=alert"
  136. }
  137. emit_a2() {
  138. local pub
  139. local sip
  140. pub="$(rand_public_ip)"
  141. sip="$(rand_private_ip)"
  142. emit_fgt_usecase "A2-01" "A2" "high" "IPS IDS Network Traffic Allowed RDP from Public IPs" \
  143. "logid=\"0000000013\" type=\"traffic\" subtype=\"forward\" srcip=${pub} dstip=${sip} dstport=3389 service=\"RDP\" action=\"accept\" policyid=44"
  144. emit_fgt_usecase "A2-02" "A2" "high" "IPS IDS Firewall Account Admin Password Change" \
  145. "logid=\"0100044547\" type=\"event\" subtype=\"system\" user=\"admin\" action=\"password-change\" target_account=\"admin\""
  146. emit_fgt_usecase "A2-03" "A2" "high" "IPS IDS Firewall Account Create Add Admin Account" \
  147. "logid=\"0100044548\" type=\"event\" subtype=\"system\" user=\"admin\" action=\"create-admin\" target_account=\"secops_admin\""
  148. emit_fgt_usecase "A2-04" "A2" "high" "IPS IDS Firewall Configure Disabled Email Notification" \
  149. "logid=\"0100044551\" type=\"event\" subtype=\"system\" action=\"config-change\" config_item=\"alertemail\" config_value=\"disable\""
  150. emit_fgt_usecase "A2-05" "A2" "low" "IPS IDS Firewall Configure Download Configure FW" \
  151. "logid=\"0100044552\" type=\"event\" subtype=\"system\" action=\"download-config\" user=\"admin\""
  152. emit_fgt_usecase "A2-06" "A2" "medium" "IPS IDS IDS Alert Multiple Critical High" \
  153. "logid=\"0720018432\" type=\"utm\" subtype=\"ips\" action=\"detected\" attack=\"Multiple.Critical.High.Signatures\" severity=\"high\" count=7"
  154. emit_fgt_usecase "A2-07" "A2" "low" "IPS IDS Network Traffic Port Scanning" \
  155. "logid=\"0720018433\" type=\"utm\" subtype=\"anomaly\" attack=\"TCP.Port.Scan\" srcip=${pub} dstip=${sip} action=\"detected\""
  156. emit_fgt_usecase "A2-08" "A2" "medium" "IPS IDS Network Traffic IOC Detection" \
  157. "logid=\"0720018434\" type=\"utm\" subtype=\"ips\" ioc_type=ip ioc_value=$(rand_public_ip) action=\"blocked\""
  158. emit_fgt_usecase "A2-09" "A2" "medium" "IPS IDS Network Traffic Port Scanning from Private IP" \
  159. "logid=\"0720018435\" type=\"utm\" subtype=\"anomaly\" attack=\"Internal.Port.Scan\" srcip=$(rand_private_ip) dstip=$(rand_private_ip) action=\"detected\""
  160. emit_fgt_usecase "A2-10" "A2" "medium" "IPS IDS Network Traffic Communicate to Malicious IP" \
  161. "logid=\"0000000013\" type=\"traffic\" subtype=\"forward\" srcip=$(rand_private_ip) dstip=$(rand_public_ip) threat_label=\"known-c2\" action=\"accept\""
  162. }
  163. emit_a3() {
  164. local out_th
  165. out_th="$(rand_public_ip)"
  166. emit_fgt_usecase "A3-01" "A3" "high" "VPN Authentication Success from Guest Account" \
  167. "logid=\"0101037131\" type=\"event\" subtype=\"vpn\" action=\"ssl-login-success\" user=\"guest\" srcip=${out_th} country=\"TH\""
  168. emit_fgt_usecase "A3-02" "A3" "high" "VPN Authentication Success from Multiple Country" \
  169. "logid=\"0101037132\" type=\"event\" subtype=\"vpn\" action=\"ssl-login-success\" user=\"${SIM_VPN_USER}\" srcip=${out_th} country=\"US\" previous_country=\"TH\""
  170. emit_fgt_usecase "A3-03" "A3" "high" "VPN Authentication Brute Force Success" \
  171. "logid=\"0101037133\" type=\"event\" subtype=\"vpn\" action=\"ssl-login-success\" user=\"${SIM_VPN_USER}\" srcip=${out_th} failed_attempts_before_success=18"
  172. emit_fgt_usecase "A3-04" "A3" "low" "VPN Authentication Multiple Fail Many Accounts from One Source" \
  173. "logid=\"0101037134\" type=\"event\" subtype=\"vpn\" action=\"ssl-login-fail\" srcip=${out_th} failed_accounts=12"
  174. emit_fgt_usecase "A3-05" "A3" "high" "VPN Authentication Success from Outside Thailand" \
  175. "logid=\"0101037135\" type=\"event\" subtype=\"vpn\" action=\"ssl-login-success\" user=\"${SIM_VPN_USER}\" srcip=${out_th} country=\"US\" expected_country=\"TH\""
  176. }
  177. emit_a4() {
  178. emit_windows_usecase "A4-01" "A4" "medium" "Windows Authentication Multiple Fail from Privileged Account" \
  179. "event_id=4625 account=\"administrator\" src_ip=$(rand_private_ip) fail_count=9"
  180. emit_windows_usecase "A4-02" "A4" "medium" "Windows Authentication Multiple Fail from Service Account" \
  181. "event_id=4625 account=\"svc_backup\" src_ip=$(rand_private_ip) fail_count=11"
  182. emit_windows_usecase "A4-03" "A4" "medium" "Windows AD Enumeration with Malicious Tools" \
  183. "event_id=4688 process=\"adfind.exe\" user=\"user1\" host=\"${WIN_HOST}\""
  184. emit_windows_usecase "A4-04" "A4" "medium" "Windows Authentication Fail from Public IPs" \
  185. "event_id=4625 account=\"user1\" src_ip=$(rand_public_ip) fail_count=4"
  186. emit_windows_usecase "A4-05" "A4" "medium" "Windows File Share Enumeration to Single Destination" \
  187. "event_id=5145 account=\"user1\" src_ip=$(rand_private_ip) share=\"\\\\\\\\fileserver\\\\finance\" object_count=87"
  188. emit_windows_usecase "A4-06" "A4" "high" "Windows Authentication Success from Public IPs" \
  189. "event_id=4624 account=\"user2\" src_ip=$(rand_public_ip) logon_type=10"
  190. emit_windows_usecase "A4-07" "A4" "high" "Windows Authentication Privileged Account Impersonation" \
  191. "event_id=4624 account=\"administrator\" impersonation=true source_account=\"user2\""
  192. emit_windows_usecase "A4-08" "A4" "high" "Windows Authentication Successful Pass the Hash RDP" \
  193. "event_id=4624 account=\"administrator\" logon_type=10 auth_package=\"NTLM\" pth_indicator=true"
  194. emit_windows_usecase "A4-09" "A4" "high" "Windows Authentication Success from Guest Account" \
  195. "event_id=4624 account=\"guest\" logon_type=3"
  196. emit_windows_usecase "A4-10" "A4" "high" "Windows Authentication Interactive Logon Success by Service Account" \
  197. "event_id=4624 account=\"svc_backup\" logon_type=2"
  198. emit_windows_usecase "A4-11" "A4" "high" "Windows Account Added to Privileged Custom Group" \
  199. "event_id=4732 account=\"user3\" target_group=\"SOC-Privileged-Custom\""
  200. emit_windows_usecase "A4-12" "A4" "high" "Windows Account Added to Privileged Group" \
  201. "event_id=4728 account=\"user3\" target_group=\"Domain Admins\""
  202. emit_windows_usecase "A4-13" "A4" "high" "Windows Domain Configure DSRM Password Reset" \
  203. "event_id=4794 account=\"administrator\" action=\"dsrm-password-reset\""
  204. emit_windows_usecase "A4-14" "A4" "low" "Windows Authentication Multiple Fail One Account from Many Sources" \
  205. "event_id=4625 account=\"user4\" src_count=15 fail_count=28"
  206. emit_windows_usecase "A4-15" "A4" "low" "Windows Authentication Multiple Fail Many Accounts from One Source" \
  207. "event_id=4625 src_ip=$(rand_private_ip) account_count=18 fail_count=42"
  208. emit_windows_usecase "A4-16" "A4" "low" "Windows Authentication Multiple Fail from Guest Account" \
  209. "event_id=4625 account=\"guest\" fail_count=9"
  210. emit_windows_usecase "A4-17" "A4" "low" "Windows Authentication Multiple Fail One Account from One Source" \
  211. "event_id=4625 account=\"user5\" src_ip=$(rand_private_ip) fail_count=10"
  212. emit_windows_usecase "A4-18" "A4" "low" "Windows Authentication Multiple Interactive Logon Denied" \
  213. "event_id=4625 account=\"user6\" logon_type=2 fail_count=7"
  214. emit_windows_usecase "A4-19" "A4" "low" "Windows Authentication Password Spray" \
  215. "event_id=4625 spray=true src_ip=$(rand_public_ip) attempted_accounts=25"
  216. emit_windows_usecase "A4-20" "A4" "low" "Windows Authentication Attempt from Disabled Account" \
  217. "event_id=4625 account=\"disabled.user\" status=\"0xC0000072\""
  218. emit_windows_usecase "A4-21" "A4" "low" "Windows Domain Account Created" \
  219. "event_id=4720 account=\"new.domain.user\" account_type=\"domain\""
  220. emit_windows_usecase "A4-22" "A4" "low" "Windows Local Account Re Enabled" \
  221. "event_id=4722 account=\"local.user\" account_type=\"local\""
  222. emit_windows_usecase "A4-23" "A4" "low" "Windows Local Account Created" \
  223. "event_id=4720 account=\"local.new\" account_type=\"local\""
  224. emit_windows_usecase "A4-24" "A4" "low" "Windows Domain Account Re Enabled" \
  225. "event_id=4722 account=\"domain.reenabled\" account_type=\"domain\""
  226. }
  227. emit_selected_set() {
  228. local sel
  229. sel="$(echo "${SELECTOR}" | tr '[:upper:]' '[:lower:]')"
  230. case "${sel}" in
  231. all)
  232. emit_a1
  233. emit_a2
  234. emit_a3
  235. emit_a4
  236. ;;
  237. a1|a1-*)
  238. emit_a1
  239. ;;
  240. a2|a2-*)
  241. emit_a2
  242. ;;
  243. a3|a3-*)
  244. emit_a3
  245. ;;
  246. a4|a4-*)
  247. emit_a4
  248. ;;
  249. *)
  250. # Exact usecase selectors (e.g. A3-05) are handled by selector_matches.
  251. emit_a1
  252. emit_a2
  253. emit_a3
  254. emit_a4
  255. ;;
  256. esac
  257. }
  258. echo "starting proposal-required log simulator"
  259. echo "selector=${SELECTOR} count=${COUNT} delay=${DELAY}s event_delay=${EVENT_DELAY}s dry_run=${DRY_RUN}"
  260. echo "target=${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  261. if [[ "${FOREVER}" == "true" ]]; then
  262. echo "running forever with interval ${DELAY}s (Ctrl+C to stop)"
  263. trap 'echo; echo "stopped"; exit 0' INT TERM
  264. while true; do
  265. emit_selected_set
  266. sleep "${DELAY}"
  267. done
  268. else
  269. for ((i=1; i<=COUNT; i++)); do
  270. emit_selected_set
  271. if [[ "${i}" -lt "${COUNT}" ]]; then
  272. sleep "${DELAY}"
  273. fi
  274. done
  275. echo "done"
  276. fi