10.41. 通用应用层关键词¶
10.41.1. app-layer-protocol¶
匹配检测到的应用层协议。
语法:
app-layer-protocol:[!]<协议>(,<模式>);
示例:
app-layer-protocol:ssh;
app-layer-protocol:!tls;
app-layer-protocol:failed;
app-layer-protocol:!http,final;
app-layer-protocol:http,to_server; app-layer-protocol:tls,to_client;
app-layer-protocol:http2,final; app-layer-protocol:http1,original;
app-layer-protocol:unknown;
特殊值'failed'可用于匹配协议检测失败的流。当Suricata无法识别协议或遇到特定'放弃'条件时会发生这种情况。
特殊值'unknown'可用于匹配尚未识别的协议状态。该值不可被否定。
可用模式包括: * direction : 在当前数据包方向上识别的协议 * to_server : 在指向服务器方向上识别的协议 * to_client : 在指向客户端方向上识别的协议 * either : 尝试匹配双向发现的协议 * final : Suricata最终选择用于解析的协议 * original : 原始协议(在协议变更情况下)
默认情况下(未指定模式时),模式为``direction``。
以下是匹配80端口非HTTP流量的规则示例:
alert tcp any any -> any 80 (msg:"HTTP标准端口上的非HTTP流量"; flow:to_server; app-layer-protocol:!http,final; sid:1; )
10.41.1.1. 放弃检测条件¶
协议检测在以下情况下会放弃:
双向检测后未找到匹配协议
A方向检测失败,B方向完全无流量(如FTP数据通道)
A方向检测失败,B方向数据量过少导致检测不确定
在后两种情况下会设置``app-layer-event:applayer_proto_detection_skipped``事件。
10.41.2. app-layer-event¶
匹配应用层解析器和协议检测引擎生成的事件。
语法:
app-layer-event:<事件名称>;
示例:
app-layer-event:applayer_mismatch_protocol_both_directions;
app-layer-event:http.gzip_decompression_failed;
10.41.2.1. 协议检测事件¶
10.41.2.1.1. applayer_mismatch_protocol_both_directions¶
客户端与服务器方向使用不同协议。例如客户端向SSH服务器发送HTTP请求。
10.41.2.1.2. applayer_wrong_direction_first_data¶
Suricata中某些协议实现对首包方向有特定要求。HTTP解析器即为一例。
10.41.2.1.3. applayer_detect_protocol_only_one_direction¶
协议检测仅在单一方向成功。FTP和SMTP协议通常会出现这种情况。
10.41.2.1.4. applayer_proto_detection_skipped¶
由于:ref:`proto-detect-bail-out`原因跳过了协议检测。
10.41.3. app-layer-state¶
匹配检测到的应用层协议事务状态。
语法:
app-layer-state:[<>]<状态>;
示例:
app-layer-state:request_headers;
app-layer-state:>request_body;