我需要使用 Snort 和其他 IDS/WAF(Suricata、mod_security 和 Shadow Daemon)分析 Apache 日志。为了做到这一点,我正在考虑使用 Python 中的 Scapy 使用存储在 Apache 日志中的 GET 和 POST 请求创建 TCP 数据包。像这样的东西:
packet= IP(dst=dst_ip)/TCP(dport=9999)/Raw(load=payload) #payload contains the http request
我将这个 TCP 数据包存储到一个 PCAP 文件中,以便稍后使用 Snort 或我所说的另一个 IDS/WAF 对其进行分析。
这种构建数据包的方法的问题是通信中没有状态,Snort 通过以下警报检测到它:
[**] [129:2:1] Data on SYN packet [**]
[Classification: Generic Protocol Command Decode] [Priority: 3]
09/01-20:29:50.816860 127.0.0.1:20 -> 127.0.0.1:9999
TCP TTL:64 TOS:0x0 ID:1 IpLen:20 DgmLen:102
******S* Seq: 0x0 Ack: 0x0 Win: 0x2000 TcpLen: 20
[Xref => http://www.securityfocus.com/bid/34429][Xref => http://cve.mitre.org/cgi-bin/cvename.cgi?name=2009-1157]
然后,我修改了代码以添加序列和确认号:
ip = IP(src=src_ip, dst=dst_ip)
packet = (ip / TCP(sport=src_port, dport=dest_port, flags='PA',
seq=seq_n, ack=ack_n) / Raw(load=fullrequest[0])
seq_n = seq_n + len(payload.encode('UTF8'))
这样,有一个序列,但SYN 数据包警报的数据会更改为另一个(尽管不会留下与相同数量的包一样多的警报,但只有 22% 的数据包会引发警报):
[**] [129:12:1] Consecutive TCP small segments exceeding threshold [**]
[Classification: Potentially Bad Traffic] [Priority: 2]
09/01-20:49:15.037299 127.0.0.1:60664 -> 127.0.0.1:80
TCP TTL:64 TOS:0x0 ID:1 IpLen:20 DgmLen:94
***AP*** Seq: 0x156E7 Ack: 0xB Win: 0x2000 TcpLen: 20
最后,我选择使用套接字创建一个客户端-服务器结构(将负载从一个虚拟机发送到另一个虚拟机),使用 WireShark 分析流量,然后将包保存为 PCAP。这里的问题是 Snort 没有检测到单一攻击。另外,我不能自动化这个分析操作。
攻击示例:
"GET /shoutbox.php?conf=../../../../../../../../etc/passwd HTTP/1.1"
"GET /cgi-bin/apexec.pl?etype=odp&template=../../../../../../../../../../etc/hosts%00.html&passurl=/category/ HTTP/1.1"
我做错了什么?有什么提示吗?