前两篇我们完成了对Snort的安装、配置,了解了Snort配置为 IDS 的基本使用
这一篇讲一讲 Snort 如何对 Nmap扫描和 SQL 注入进行检测

检测Nmap扫描

1、NMAP Ping扫描
规则

vim /etc/snort/rules/local.rules
##下面的规则都写入这个文件中

alert icmp any any -> 192.168.43.97 any (msg: "NMAP ping sweep Scan"; dsize:0;sid:10000001; rev: 1;)

nmap扫描命令

nmap -sP 192.168.43.97 --disable-arp-ping

##若不使用”--disable-arp-ping“参数,南无nmap可能会发送 arp 数据包,使 snort 检测不到,我们使用此参数,让其只发送 ICMP 扫描

在这里插入图片描述

2、NMAP TCP/UDP扫描
能够检测到攻击使用 nmap 的端口爆破、连接及漏洞利用行为
规则

alert tcp any any -> 192.168.43.97 any (msg: "NMAP TCP Scan";sid:10000002;rev:2;)

alert udp any any -> 192.168.43.97 any ( msg:"Nmap UDP Scan"; sid:10000003; rev:1; )

nmap

nmap -sT -p1-200 192.168.43.97

nmap -sU -p1-200 192.168.43.97

检测到tcp扫描

在这里插入图片描述

检测到UDP扫描
在这里插入图片描述

3、NMAP XMAS扫描
有时攻击者不适用 TCP 通讯进行扫描,而使用 XMAS 通过 Fin、PSH和URG发送数据包进行扫描
那我们可以使用如下规则

alert tcp any any -> 192.168.43.97 any (msg:"Nmap XMAS Tree Scan"; flags:FPU; sid:1000004; rev:1; )

nmap

nmap -sX -p1-200 192.168.43.97

发现XMAS扫描
在这里插入图片描述

4、检测 Fin扫描

alert tcp any any -> 192.168.43.97 any (msg:"Nmap FIN Scan"; flags:F; sid:1000005; rev:1;)

namp

nmap -sF -p1-200 192.168.43.97

检测到了多数 FIN 扫描和 TCP 扫描,无 UDP 扫描
在这里插入图片描述

5、NULL扫描检测

alert tcp any any -> 192.168.43.97 any (msg:"Nmap NULL Scan"; flags:0; sid:1000006; rev:1; )

nmap

nmap -sN -p1-200 192.168.43.97

SQL注入检测

在Snort安装之前我们安装了 LAMP(Apache、Mysql、Php),这里就直接对 web 主页进行 SQL注入

1、基于错误的SQL注入
SQL注入攻击中,检测SQL注入的方法是在 URL 尾补加上单引号/双引号 引起报错,所以我们可以对 单引号和双引号的检测入手,看下面的规则

alert tcp any any -> 192.168.43.97 80 (msg: "SQL Injection Detected"; content: "%27" ; sid:100000007; ) 

alert tcp any any -> 192.168.43.97 80 (msg: "SQL Injection Detected"; content: "22" ; sid:100000008; )

其中 %27 和 %22 是经 url编码的 单引号和 双引号

加上单引号访问

http://192.168.43.97/index.php'

还检测到了 OR,有点离谱
在这里插入图片描述

加上双引号访问

http://192.168.43.97/index.php"

在这里插入图片描述

2、布尔型SQL注入
攻击者通过使用 AND/OR 运算符,来对页面返回的true或false进行评估,判断SQL注入

alert tcp any any -> 192.168.43.97 80 (msg: "AND SQL Injection Detected"; content: "and"; nocase; sid:100000009; ) 

alert tcp any -> 192.168.43.97 80 (msg: "OR SQL Injection Detected"; content : "or" ; nocase; sid:100000010; )

访问

http://192.168.43.97/index.php and 1=1 --+

在这里插入图片描述

访问

http://192.168.43.97/index.php or 1=1 --+

在这里插入图片描述

3、联合查询

alert tcp any any -> 192.168.43.97 80 (msg: "UNION SELECT SQL Injection"; content: "union" ; sid:100000011; )

访问

http://192.168.43.97/index.php union select 1,2,3 --+

在这里插入图片描述

Snort的规则还是很灵活的,作为 IDS 入侵检测是很有效的,但是其匹配规则并不是很十分精确,实际过程中还是要搭配其他安全设备一起使用。

参考:
https://www.cnblogs.com/mubaiLee/p/13773687.html
https://www.hackingarticles.in/ids-ips-penetration-testing-lab-setup-snort/
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐