hog.vim 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. " Vim syntax file
  2. " Language: hog (Snort.conf + .rules)
  3. " Maintainer: Victor Roemer, <vroemer@badsec.org>.
  4. " Last Change: 2019 Sep 22
  5. " 2012 Oct 24 -> Originalish release
  6. " 2019 Sep 22 -> included PR 3069
  7. " quit when a syntax file was already loaded
  8. if exists("b:current_syntax")
  9. finish
  10. endif
  11. setlocal iskeyword-=:
  12. setlocal iskeyword+=-
  13. syn case ignore
  14. " Hog ruletype crap
  15. syn keyword HogRuleType ruletype nextgroup=HogRuleTypeName skipwhite
  16. syn match HogRuleTypeName "[[:alnum:]_]\+" contained nextgroup=HogRuleTypeBody skipwhite
  17. syn region HogRuleTypeBody start="{" end="}" contained contains=HogRuleTypeType,HogOutput fold
  18. syn keyword HogRuleTypeType type contained
  19. " Hog Configurables
  20. syn keyword HogPreproc preprocessor nextgroup=HogConfigName skipwhite
  21. syn keyword HogConfig config nextgroup=HogConfigName skipwhite
  22. syn keyword HogOutput output nextgroup=HogConfigName skipwhite
  23. syn match HogConfigName "[[:alnum:]_-]\+" contained nextgroup=HogConfigOpts skipwhite
  24. syn region HogConfigOpts start=":" skip="\\.\{-}$\|^\s*#.\{-}$\|^\s*$" end="$" fold keepend contained contains=HogSpecial,HogNumber,HogIPAddr,HogVar,HogComment
  25. " Event filter's and threshold's
  26. syn region HogEvFilter start="event_filter\|threshold" skip="\\.\{-}$\|^\s*#.\{-}$\|^\s*$" end="$" fold transparent keepend contains=HogEvFilterKeyword,HogEvFilterOptions,HogComment
  27. syn keyword HogEvFilterKeyword skipwhite event_filter threshold
  28. syn keyword HogEvFilterOptions skipwhite type nextgroup=HogEvFilterTypes
  29. syn keyword HogEvFilterTypes skipwhite limit threshold both contained
  30. syn keyword HogEvFilterOptions skipwhite track nextgroup=HogEvFilterTrack
  31. syn keyword HogEvFilterTrack skipwhite by_src by_dst contained
  32. syn keyword HogEvFilterOptions skipwhite gen_id sig_id count seconds nextgroup=HogNumber
  33. " Suppressions
  34. syn region HogEvFilter start="suppress" skip="\\.\{-}$\|^\s*#.\{-}$\|^\s*$" end="$" fold transparent keepend contains=HogSuppressKeyword,HogComment
  35. syn keyword HogSuppressKeyword skipwhite suppress
  36. syn keyword HogSuppressOptions skipwhite gen_id sig_id nextgroup=HogNumber
  37. syn keyword HogSuppressOptions skipwhite track nextgroup=HogEvFilterTrack
  38. syn keyword HogSuppressOptions skipwhite ip nextgroup=HogIPAddr
  39. " Attribute table
  40. syn keyword HogAttribute attribute_table nextgroup=HogAttributeFile
  41. syn match HogAttributeFile contained ".*$" contains=HogVar,HogAttributeType,HogComment
  42. syn keyword HogAttributeType filename
  43. " Hog includes
  44. syn keyword HogInclude include nextgroup=HogIncludeFile skipwhite
  45. syn match HogIncludeFile ".*$" contained contains=HogVar,HogComment
  46. " Hog dynamic libraries
  47. syn keyword HogDylib dynamicpreprocessor dynamicengine dynamicdetection nextgroup=HogDylibFile skipwhite
  48. syn match HogDylibFile "\s.*$" contained contains=HogVar,HogDylibType,HogComment
  49. syn keyword HogDylibType directory file contained
  50. " Variable dereferenced with '$'
  51. syn match HogVar "\$[[:alnum:]_]\+"
  52. ", Variables declared with 'var'
  53. syn keyword HogVarType var nextgroup=HogVarSet skipwhite
  54. syn match HogVarSet "[[:alnum:]_]\+" display contained nextgroup=HogVarValue skipwhite
  55. syn match HogVarValue ".*$" contained contains=HogString,HogNumber,HogVar,HogComment
  56. " Variables declared with 'ipvar'
  57. syn keyword HogIPVarType ipvar nextgroup=HogIPVarSet skipwhite
  58. syn match HogIPVarSet "[[:alnum:]_]\+" display contained nextgroup=HogIPVarList,HogSpecial skipwhite
  59. syn region HogIPVarList start="\[" end="]" contains=HogIPVarList,HogIPAddr,HogVar,HogOpNot
  60. " Variables declared with 'portvar'
  61. syn keyword HogPortVarType portvar nextgroup=HogPortVarSet skipwhite
  62. syn match HogPortVarSet "[[:alnum:]_]\+" display contained nextgroup=HogPortVarList,HogPort,HogOpRange,HogOpNot,HogSpecial skipwhite
  63. syn region HogPortVarList start="\[" end="]" contains=HogPortVarList,HogVar,HogOpNot,HogPort,HogOpRange,HogOpNot
  64. syn match HogPort "\<\%(\d\+\|any\)\>" display contains=HogOpRange nextgroup=HogOpRange
  65. " Generic stuff
  66. syn match HogIPAddr contained "\<\%(\d\{1,3}\(\.\d\{1,3}\)\{3}\|any\)\>" nextgroup=HogIPCidr
  67. syn match HogIPAddr contained "\<\d\{1,3}\(\.\d\{1,3}\)\{3}\>" nextgroup=HogIPCidr
  68. syn match HogIPCidr contained "\/\([0-2][0-9]\=\|3[0-2]\=\)"
  69. syn region HogHexEsc contained start='|' end='|' oneline
  70. syn region HogString contained start='"' end='"' extend oneline contains=HogHexEsc
  71. syn match HogNumber contained display "\<\d\+\>"
  72. syn match HogNumber contained display "\<\d\+\>"
  73. syn match HogNumber contained display "0x\x\+\>"
  74. syn keyword HogSpecial contained true false yes no default all any
  75. syn keyword HogSpecialAny contained any
  76. syn match HogOpNot "!" contained
  77. syn match HogOpRange ":" contained
  78. " Rules
  79. syn keyword HogRuleAction activate alert drop block dynamic log pass reject sdrop sblock skipwhite nextgroup=HogRuleProto,HogRuleBlock
  80. syn keyword HogRuleProto ip tcp tcp-pkt tcp-stream udp icmp http ftp tls smb dns dcerpc ssh smtp imap msn modbus dnp3 enip nfs ikev2 ntp skipwhite contained nextgroup=HogRuleSrcIP
  81. syn match HogRuleSrcIP "\S\+" transparent skipwhite contained contains=HogIPVarList,HogIPAddr,HogVar,HogOpNot nextgroup=HogRuleSrcPort
  82. syn match HogRuleSrcPort "\S\+" transparent skipwhite contained contains=HogPortVarList,HogVar,HogPort,HogOpRange,HogOpNot nextgroup=HogRuleDir
  83. syn match HogRuleDir "->\|<>" skipwhite contained nextgroup=HogRuleDstIP
  84. syn match HogRuleDstIP "\S\+" transparent skipwhite contained contains=HogIPVarList,HogIPAddr,HogVar,HogOpNot nextgroup=HogRuleDstPort
  85. syn match HogRuleDstPort "\S\+" transparent skipwhite contained contains=HogPortVarList,HogVar,HogPort,HogOpRange,HogOpNot nextgroup=HogRuleBlock
  86. syn region HogRuleBlock start="(" end=")" transparent skipwhite contained contains=HogRuleOption,HogComment fold
  87. ",HogString,HogComment,HogVar,HogOptNot
  88. "syn region HogRuleOption start="\<gid\|sid\|rev\|depth\|offset\|distance\|within\>" end="\ze;" skipwhite contained contains=HogNumber
  89. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP msg gid sid rev classtype priority metadata target content nocase rawbytes
  90. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP depth startswith offset distance within http_client_body http_cookie http_raw_cookie http_header
  91. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP http_raw_header http_request_line http_method http_uri http_raw_uri http_protocol http_response_line http_stat_code http_stat_msg
  92. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP http_user_agent http_accept http_accept_enc http_accept_lang http_connection http_content_type http_content_len
  93. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP http_referer http_start http_header_names http_server_body http_host http_raw_host
  94. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP filename fileext filemagic filestore filemd5 filesha1 filesha256 filesize
  95. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP dns_query tls_cert_subject tls_cert_issuer tls_cert_serial tls_cert_fingerprint
  96. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP tls_sni tls_cert_notbefore tls_cert_notafter tls_cert_expired tls_cert_valid
  97. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP tls.version tls.subject tls.issuerdn tls.fingerprint tls.store ja3_hash ja3_string
  98. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP modbus dnp3_func dnp3_ind dnp3_obj dnp3_data enip_command cip_service
  99. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP app-layer-protocol app-layer-event xbits iprep lua luajit
  100. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP fast_pattern prefilter uricontent urilen isdataat pcre pkt_data file_data base64_decode base64_data
  101. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP byte_test byte_jump byte_extract ftpdata_command ftpbounce asn1 cvs dce_iface dce_opnum dce_stub_data
  102. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP sip_method sip_stat_code sip_header sip_body gtp_type gtp_info gtp_version ssl_version
  103. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP ssl_state fragoffset ttl tos id ipopts geoip fragbits dsize flags flow flowbits flowint seq ack window
  104. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP itype icode icmp_id icmp_seq rpc ip_proto sameip stream_reassemble stream_size
  105. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP logto session resp react tag activates activated_by count replace detection_filter
  106. syn keyword HogRuleOption skipwhite contained nextgroup=HogRuleSROP threshold reference sd_pattern file_type file_group
  107. syn region HogRuleSROP start=':' end=";" transparent keepend contained contains=HogRuleChars,HogString,HogNumber
  108. syn match HogRuleChars "\%(\k\|\.\|?\|=\|/\|%\|&\)\+" contained
  109. syn match HogURLChars "\%(\.\|?\|=\)\+" contained
  110. " Hog File Type Rules
  111. syn match HogFileType /^\s*file.*$/ transparent contains=HogFileTypeOpt,HogFileFROP
  112. syn keyword HogFileTypeOpt skipwhite contained nextgroup=HogRuleFROP file type ver category id rev content offset msg group
  113. syn region HogFileFROP start=':' end=";" transparent keepend contained contains=NotASemicoln
  114. syn match NotASemiColn ".*$" contained
  115. " Comments
  116. syn keyword HogTodo XXX TODO NOTE contained
  117. syn match HogTodo "Step\s\+#\=\d\+" contained
  118. syn region HogComment start="#" end="$" contains=HogTodo,@Spell
  119. syn case match
  120. if !exists("hog_minlines")
  121. let hog_minlines = 100
  122. endif
  123. exec "syn sync minlines=" . hog_minlines
  124. hi link HogRuleType Statement
  125. hi link HogRuleTypeName Type
  126. hi link HogRuleTypeType Keyword
  127. hi link HogPreproc Statement
  128. hi link HogConfig Statement
  129. hi link HogOutput Statement
  130. hi link HogConfigName Type
  131. "hi link HogEvFilter
  132. hi link HogEvFilterKeyword Statement
  133. hi link HogSuppressKeyword Statement
  134. hi link HogEvFilterTypes Constant
  135. hi link HogEvFilterTrack Constant
  136. hi link HogAttribute Statement
  137. hi link HogAttributeFile String
  138. hi link HogAttributeType Statement
  139. hi link HogInclude Statement
  140. hi link HogIncludeFile String
  141. hi link HogDylib Statement
  142. hi link HogDylibType Statement
  143. hi link HogDylibFile String
  144. " Variables
  145. " var
  146. hi link HogVar Identifier
  147. hi link HogVarType Keyword
  148. hi link HogVarSet Identifier
  149. hi link HogVarValue String
  150. " ipvar
  151. hi link HogIPVarType Keyword
  152. hi link HogIPVarSet Identifier
  153. " portvar
  154. hi link HogPortVarType Keyword
  155. hi link HogPortVarSet Identifier
  156. hi link HogPort Constant
  157. hi link HogTodo Todo
  158. hi link HogComment Comment
  159. hi link HogString String
  160. hi link HogHexEsc PreProc
  161. hi link HogNumber Number
  162. hi link HogSpecial Constant
  163. hi link HogSpecialAny Constant
  164. hi link HogIPAddr Constant
  165. hi link HogIPCidr Constant
  166. hi link HogOpNot Operator
  167. hi link HogOpRange Operator
  168. hi link HogRuleAction Statement
  169. hi link HogRuleProto Identifier
  170. hi link HogRuleDir Operator
  171. hi link HogRuleOption Keyword
  172. hi link HogRuleChars String
  173. hi link HogFileType HogRuleAction
  174. hi link HogFileTypeOpt HogRuleOption
  175. hi link NotASemiColn HogRuleChars
  176. let b:current_syntax = "hog"