Нет описания

send-wazuh-fortigate-test-events.sh 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. MODEL="${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-fortigate-test-events.sh [model] [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. FGT_SRC_IP="${FGT_SRC_IP:-10.10.20.55}"
  22. FGT_DST_IP="${FGT_DST_IP:-172.217.14.238}"
  23. FGT_DOMAIN="${FGT_DOMAIN:-malicious.example}"
  24. FGT_USER="${FGT_USER:-guest.user}"
  25. if ! [[ "${COUNT}" =~ ^[0-9]+$ ]] || [[ "${COUNT}" -lt 1 ]]; then
  26. echo "error: count must be a positive integer"
  27. exit 1
  28. fi
  29. if ! [[ "${DELAY}" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
  30. echo "error: delay must be numeric (example: 0.5)"
  31. exit 1
  32. fi
  33. emit_syslog() {
  34. local msg="$1"
  35. local sent="false"
  36. if command -v nc >/dev/null 2>&1; then
  37. if printf "%s\n" "${msg}" | nc -u -w1 "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  38. sent="true"
  39. fi
  40. fi
  41. if [[ "${sent}" != "true" ]]; then
  42. if printf "%s\n" "${msg}" >"/dev/udp/${WAZUH_SYSLOG_HOST}/${WAZUH_SYSLOG_PORT}" 2>/dev/null; then
  43. sent="true"
  44. fi
  45. fi
  46. if [[ "${sent}" != "true" ]]; then
  47. echo "error: failed to send syslog event to ${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  48. echo "hint: install netcat or run with bash UDP support (/dev/udp)"
  49. return 1
  50. fi
  51. echo "[$(date -u +'%Y-%m-%dT%H:%M:%SZ')] sent: ${msg}"
  52. }
  53. random_id() {
  54. printf "%s" "fgt-evt-$(date +%s)-$RANDOM-$RANDOM"
  55. }
  56. send_fgt_501e() {
  57. local eid
  58. eid="$(random_id)"
  59. emit_syslog "<189>date=$(date '+%Y-%m-%d') time=$(date '+%H:%M:%S') devname=\"FGT501E-HQ\" devid=\"FGT501E12345678\" eventtime=$(date +%s) logid=\"0000000013\" type=\"traffic\" subtype=\"forward\" level=\"notice\" vd=\"root\" srcip=${FGT_SRC_IP} srcport=51522 srcintf=\"lan\" dstip=${FGT_DST_IP} dstport=443 dstintf=\"wan1\" proto=6 service=\"HTTPS\" policyid=12 action=\"accept\" sentbyte=1428 rcvdbyte=9821 duration=22 soc_mvp_test=true vendor=fortinet product=fortigate model=501E event_id=${eid} event_type=fortigate_traffic_allow severity=low"
  60. }
  61. send_fgt_80f() {
  62. local eid
  63. eid="$(random_id)"
  64. emit_syslog "<190>date=$(date '+%Y-%m-%d') time=$(date '+%H:%M:%S') devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=$(date +%s) logid=\"0419016384\" type=\"utm\" subtype=\"webfilter\" level=\"warning\" vd=\"root\" srcip=${FGT_SRC_IP} srcintf=\"internal\" dstip=104.18.21.123 dstport=80 hostname=\"${FGT_DOMAIN}\" url=\"/payload\" action=\"blocked\" cat=52 profile=\"WF-Strict\" policyid=3 soc_mvp_test=true vendor=fortinet product=fortigate model=80F event_id=${eid} event_type=fortigate_webfilter_block severity=medium"
  65. }
  66. send_fgt_60f() {
  67. local eid
  68. eid="$(random_id)"
  69. emit_syslog "<190>date=$(date '+%Y-%m-%d') time=$(date '+%H:%M:%S') devname=\"FGT60F-Store12\" devid=\"FGT60FTK21001234\" eventtime=$(date +%s) logid=\"0720018432\" type=\"utm\" subtype=\"ips\" level=\"alert\" vd=\"root\" srcip=${FGT_SRC_IP} dstip=45.155.205.233 srcport=51992 dstport=445 sessionid=9044333 action=\"blocked\" attack=\"MS.SMB.Server.Service.Remote.Code.Execution\" severity=\"critical\" policyid=8 soc_mvp_test=true vendor=fortinet product=fortigate model=60F event_id=${eid} event_type=fortigate_ips_block severity=high"
  70. }
  71. send_fgt_40f() {
  72. local eid
  73. eid="$(random_id)"
  74. emit_syslog "<191>date=$(date '+%Y-%m-%d') time=$(date '+%H:%M:%S') devname=\"FGT40F-SMB01\" devid=\"FGT40FTK22004567\" eventtime=$(date +%s) logid=\"0104044546\" type=\"event\" subtype=\"vpn\" level=\"warning\" vd=\"root\" user=\"${FGT_USER}\" tunneltype=\"ipsec\" remip=${FGT_SRC_IP} locip=198.51.100.27 action=\"tunnel-down\" reason=\"peer-not-responding\" msg=\"IPsec tunnel Branch-HQ is down\" soc_mvp_test=true vendor=fortinet product=fortigate model=40F event_id=${eid} event_type=fortigate_vpn_down severity=high"
  75. }
  76. send_once() {
  77. case "${MODEL}" in
  78. 501E|501e)
  79. send_fgt_501e
  80. ;;
  81. 80F|80f)
  82. send_fgt_80f
  83. ;;
  84. 60F|60f)
  85. send_fgt_60f
  86. ;;
  87. 40F|40f)
  88. send_fgt_40f
  89. ;;
  90. all)
  91. send_fgt_501e
  92. send_fgt_80f
  93. send_fgt_60f
  94. send_fgt_40f
  95. ;;
  96. *)
  97. echo "error: unknown model '${MODEL}'"
  98. echo "valid: 501E | 80F | 60F | 40F | all"
  99. exit 1
  100. ;;
  101. esac
  102. }
  103. if [[ "${FOREVER}" == "true" ]]; then
  104. echo "running forever with interval ${DELAY}s (Ctrl+C to stop)"
  105. trap 'echo; echo "stopped"; exit 0' INT TERM
  106. while true; do
  107. send_once
  108. sleep "${DELAY}"
  109. done
  110. else
  111. for ((i=1; i<=COUNT; i++)); do
  112. send_once
  113. if [[ "${i}" -lt "${COUNT}" ]]; then
  114. sleep "${DELAY}"
  115. fi
  116. done
  117. fi