目的
本练习的目的是展示如何使用ASM来保护web应用程序。首先,您将访问DVWA网站,提交SQL注入、跨站点脚本和强制浏览攻击。然后,您将使用快速部署策略模板创建ASM安全策略,并在事件日志中查看用户请求。在第二个练习中,您将通过调整学习和阻塞设置页面上的设置来添加文件类型强制,生成学习建议,然后手动将文件类型添加到安全策略中。在最后的练习中,您将研究文件类型属性实施,然后您将使用可信请求在自动模式下创建一个新的安全策略,然后您将使用Firefox iMacro生成学习建议,然后您将查看ASM更新参数的属性并修改其实施。
任务一:认识网站漏洞
SQL Injection:
输入 1 ,提交
这一步是为了展示出userid,first name,last name

输入 $username = 1’ or ‘1’ = '1,提交,这样就可以得到数据库里所有的用户信息

输入’ and 1=0 union select null, concat(first_name,0x0a,last_name,0x0a,user,0x0a,password) from users #,提交,这样就可以得到user id,first name,last name,user name,以及经过hash加密的password

注意这里一个username为manly的数据,以这组数据为例,选择它password的hash结果并复制

可以看到可以被解码出来,如下

进入dvwa,点击logout

使用manly/P@ssw0rd!尝试登录,发现登陆成功

左下角可以看到登录的用户为manly

SQL注入可以做到对敏感数据的增删改查
Cross-Site Scripting
再dvwa网页点击XSS stored

创建一个条目:name栏输入Comment
Message栏输入This web site is very useful. It’s helped me understand the vulnerabilities that my web application has. I guess my web developers aren’t as skilled as I thought they were.
点击sign guestbook
我们得到以下效果,这个效果是为了论坛中大家可以留言讨论

再创建一条攻击条目,name栏输入Attack
Message栏输入
点击Sign guestbook
这事一段javascript代码,网页进行了跳转

再次点击DVWA书签,使用gordonb/abc123登录

点击XSS stored,页面仍然跳到了告警页面

点击OK,点击Home

再次回到manly用户登录页面,回到XSS stored页面
Name栏输入redirect
Message栏输入
点击sign guestbook
回到gordonb账号,点击XSS stored按钮

点击OK,在正常页面短暂停留后

随后就重定向到了黑客设置的网站

CSS攻击可以让黑客对数据库插入任何形式的代码脚本
任务二:创建rapid deployment安全策略
登录到F5,在ltm里创建irules
random_ip_irule
when CLIENT_ACCEPTED {
set ip_addr [expr int(rand()*223)].[expr int(rand()*255)].[expr int(rand()*255)].[expr int(rand()*254)]
}
when HTTP_REQUEST {
HTTP::header insert X-Forwarded-For $ip_addr
}
将这个irules挂到dvwa_virtual下面

创建安全策略,输入以下信息,点击create policy
Policy Name lorax_security_policy
Policy Template Rapid Deployment
Virtual Server dvwa_virtual

点击箭头指向位置

会跳到改策略的properties页面

打开advancd,选择xff,下拉点击save

点击apply policy

策略部署完成
任务三:查看asm event log
打开dvwa页面,点击SQL Injection页面,输入12,提交

点击XSS stored,点击ok

把url改成http://10.1.10.35/php.ini

点击DVWA书签,点击setup,点击create /reset database,关闭页面

查看event log,由于irule和trust xff header设置,这里可以看到访问请求时来自全球各地的

https://www.cnblogs.com/lexus/archive/2012/02/21/2360944.html

一共有九个header

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Mozilla/5.0,参考下面的链接,写的很幽默
https://cloud.tencent.com/developer/article/1932541
Chrome使用了WebKit渲染引擎,想装成Safari,而WebKit呢又伪装自己是KHTML,KHTML呢又是伪装成Gecko的。同一时候全部的浏览器又都宣称自己是Mozilla,于是,Chrome宣称自己是Mozilla/5.0
ASM练习2 Using file type enforcement
进入Security ›› Application Security : Policy Building : Traffic Learning,可以看到有很多条学习建议

进入Security ›› Application Security : Policy Building : Learning and Blocking Settings
根据下图红框部分进行配置

然后将Enforcement Mode改回Transparent
点击save,点击apply policy,点击ok



任务二 更新安全策略的学习建议
打开无痕模式窗口,点击DVWA书签,使用gordonb/abc123登录进去
点击user policy

然后点击main DVWA page

依次点击1、2、3

将url改成http://10.1.10.35/php.ini

将url改成http://10.1.10.25/README.md
关闭页面

查看学习进度(筛选针对php的illegal file type)
learning score为10%
一共生成两条建议

查看学习进度(筛选针对md的illegal file type)
learning score为5%
一共生成一条建议
任务三 调整策略学习速度
进入learning and blocking页面
翻到底部,按照如下配置:
保存并应用策略

打开无痕窗口,使用gordonb/abc123登录,
依次点击user policy,main DVWA,instructions,DVWA Security, About,关闭页面
等待至少20s
再次打开无痕窗口,使用gordonb/abc123登录
依次点击user policy,main DVWA page,setup,Logout
将url改成http://10.1.10.25/README.md,点击回车,关闭页面
等待至少20s
再次打开无痕窗口,使用gordonb/abc123登录
依次点击user policy,main DVWA page,关闭页面
在配置页面打开Traffic learning页面
筛选出针对php的illegal file type,
learning score为100%
一共十条建议

筛选出针对md的illegal file type,
learning score为20%
一共两条建议

任务四 手动添加文件类型
选择应用允许的文件类型并添加到 lorax_security_policy 策略中
-筛选针对php的illegal file type
-在右侧选择Related Suggestions-Suggestions with the same violation

这样完美就可以看到所有文件类型的学习建议,我们需要更多的流量来观察learning score是如何被影响的
-点击open filter(放大镜),选择advanced filter,如下配置,点击apply filter

我们可以看到有如下这么多文件类型的学习建议
点击全选,我们可以看到学习建议都是add file type(根据自己的环境来)

点击Accept Suggestions,我们可以看到有两个选项
Accept Suggestions:按照Action编辑策略
Accept Suggextions and enable staging on Matched File Types:接受这些建议,并将它们安排为staging状态
这里我们选择第二个

再次选择0-24 learning score的学习建议

选择ignore suggextions,应用策略
如果我们选择了delete suggestion,这些文件类型之后还会再次出现在学习建议里

进入file type页面,删除*,应用策略

打开无痕窗口,使用gordonb/abc123登录DVWA
修改url为http://10.1.10.25/php.ini

我仍然可以打开这个页面
为什么asm仍然允许打开这个非法页面?我认为是这个策略用的是transparent模式,没有拦截策略

打开日志页面
显示这些请求是非法的

如何拦截这条请求?我认为需要开启blocking

改完配置后

任务五 修改安全策略的Enforcement Mode
修改learning and blocking的enforcement mode为blocking

访问http://10.1.10.35/pgp.ini

访问http://10.1.10.25/README.md

现在可以看到这两个页面都被block了,但是这样的blocking页面太基础,我们可以修改返回页面
进入如下路径,修改reponse pages

将reponse body改成
<html><head><title>Illegal Request</title></head>
<body>For security purposes, Lorax Investments has blocked this <font color=red>illegal request</font>.<br><br>
You can contact our technical support department and supply them with the following support ID: <b><%TS.request.ID()%></b><br><br><a href='javascript:history.back();'>[Go Back]</a></body></html></body></html>

点击保存,并应用策略
重新加载http://10.1.10.25/README.md

进入日志页面,选择最新的/README.md条目,查看明细,我们可以看到除了illegal file type,还有illegal url length和request
length两个原因同时导致页面被block
在attack type中点击buffer overflow,可以看到攻击类型的具体信息

更新特征库
原始共有3304个特征

在learning and blocking页面,点击attack signatures,点击change

选择下面三个特征库,点击change

保存并应用策略
回到appalication security-attack signatures,现在特征值有7113个

练习3 建立automatic policy
任务一 enforce 特定的文件类型
打开无痕窗口,使用gordonb/abc123登录
修改url为:
http://10.1.10.35/index.php?A=alksdjfslfjsdlfjsdlfjk&B=lsakdfjskfjsdlfjsflkjdsflkjsdslkfjsfkj&C=askdfslkdfjsdkfjsdlkfjsdkfwiefiskfjis&D=skladfskvjisadfieieakfdkjdsfkdsdsjf&E=vakjeiaskjfsiefsfsafivsidfisaef&F=8324v8fs8v8dsv8dsfs8vsdvisda3r25&G=8kvw8ey5r438nfdfvu34rpoindv8re8we88f&H=232sdofdjswef82weoifjwoifjw323wewefwelifw38ijfwie&I=alksdjfslfjsdlfjsdlfjk&J=lsakdfjskfjsdlfjsflkjdsflkjsdslkfjsfkj&K=askdfslkdfjsdkfjsdlkfjsdkfwiefiskfjis&L=skladfskvjisadfieieakfdkjdsfkdsdsjf&M=vakjeiaskjfsiefsfsafivsidfisaef&n=8324v8fs8v8dsv8dsfs8vsdvisda3r25&N=8kvw8ey5r438nfdfvu34rpoindv8re8we88f&O=232sdofdjswef82weoifjwoifjw323wewefwelifw38ijfwie&P=qwertyuiopasdfghjjklzxcvbnm0987654321232sdofdjswef82weoifjwoifjw323wewefwelifw38ijfwie&q=qwertyuiopasdfghjjklzxcvbnm0987654321232sdofdjswef82weoifjwoifjw323wewefwelifw38ijfwie&Q=qwertyuiopasdfghjjklzxcvbnm0987654321&P=askdfslkdfjsdkfjsdlkfjsdkfwiefiskfjis8324v8fs8v8dsv8dsfs8vsdvisda3r25alksdjfslfjsdlfjsdlfjk&J=lsakdfjskfjsdlfjsflkjdsflkjsdslkfjsfkjaskdfslkdfjsdkfjsdlkfjsdkfwiefiskfjis8324v8fs8v8dsv8dsfs8vsdvisda3r25alksdjfslfjsdlfjsdlfjk&J=lsakdfjskfjsdlfjsflkjdsflkjsdslkfjsfkjaslkdfsalkfjsadwkljweifakdjfaslkdfslmvksdkfiesksdfsdiksdfjsi&R=wieslfjsifsifjsiefjsdlfissijifjeiasifejsaiesaehfwuepewweffwepfwuwieslfjsifsifjsiefjsdlfissijifjeiasifejsaiesaehfwuepewweffwepfwuwieslfjsifsifjsiefjsdlfissijifjeiasifejsaiesaehfwuepewweffwepfwuwieslfjsifsifjsiefjsdlfissijifjeiasifejsaiesaehfwuepewweffwepfwuwieslfjsifsifjsiefjsdlfissijifjeiasifejsaiesaehfwuepewwesajfie83292sddra8
这个请求被正常接受

查看日志:
这里显示违规情况需要进一步评估

点击illegal query string length
文件类型为php
detected query string length为1484
expected query string length为1000

打开allowed file type页面,找到php,点击后面的学习建议

可以看到这里生成建议,将string length改完2048
这里只是看一下生成的建议,还没有决定要去改掉

点击ignore suggestions,那么这条学习建议就不会再出现了

那么query string length默认被设置为1000,但是实际请求长度为1484,大于1000,为什么没有被block呢
点击php前面的复选框,然后点击enforce,然后应用策略

刷新请求页面,发现请求被block,关闭请求页面

任务二 根据trusted requests创建automatic policy building
将lorax_security_policy改成automatic learning,指定trusted ip
去dvwa_virtual的vs里把irule(random_ip_irule)去掉,这样访问的源地址就只来自你的客户端本身
到policy list页面,选择lorax_security_policy,点击delete,我们来根据以下信息重新创建一下
Policy Name lorax_security_policy
Policy Template Comprehensive
Virtual Server dvwa_virtual
Application Language Unicode (utf-8)
Trusted IP Addresses 10.1.10.0 / 255.255.255.0 (Click Add)


填完点击左上角的create policy
进入learning and blocking页面,将file type,urls,parameters的learn new xxx改成always,parameter level选择url,如下


打开trusted ip addresses,可以看到之前创建的trusted ip已经生成
打开loosen policy,tighten policy(stabilize),minimize false positives(track site changes)按照下图修改

点击保存并应用策略
任务三 创建trusted learning suggestions
使用正常用户流量生成可信学习建议,用于添加文件类型、url和参数
注意:本练习使用两个Firefox宏。确保运行指定的确切宏(boot camp build1.iim or boot camp build2.iim。如果运行了错误的宏,该练习将无法按所配置的方式工作。
boot camp build1.iim:
URL GOTO=http://10.1.10.35/
URL GOTO=http://10.1.10.35/login.php
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:login.php ATTR=NAME:username CONTENT=gordonb
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:login.php ATTR=NAME:password CONTENT=abc123
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:login.php ATTR=NAME:Login
URL GOTO=http://10.1.10.35/index.php
URL GOTO=http://10.1.10.35/instructions.php?doc=copying
URL GOTO=http://10.1.10.35/instructions.php?doc=PHPIDS-license
URL GOTO=http://10.1.10.35/userpolicy.html
URL GOTO=http://10.1.10.35/index.php
URL GOTO=http://10.1.10.35/login.php?username=admin&password=password#
URL GOTO=http://10.1.10.35/login.php?username=gordonb&password=abc123#
URL GOTO=http://10.1.10.35/vulnerabilities/sqli/?id=1&Submit=Submit#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=I+have+a+lot+of+text+to+enter+into+this+field.#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=F5+Networks,+401+Elliott+Ave.+W.,+Seattle,+WA+98119#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=In+New+York+Slice%2C+each+player+slices+up+pizzas%2C+giving+their+opponents+first+choice%2C+while+they+take+the+leftovers.+There+are+a+dozen+kinds+of+pizza+to+work+with+and+each+player+decides+if+they+want+to+eat+or+keep+slices%2C+building+the+best+pizzas%21+#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=%27Some+slices+have+anchovies+on+them+%28yuck%21%29%2C+which+are+worth+negative+points+%E2%80%94+but+anchovies+might+show+up+on+different+pizza+types+you%27re+collecting%2C+so+in+order+to+have+the+majority%2C+you+just+might+have+to+collect+one+with+anchovies+on+it.%27#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=I+absolutely+love+this+art+box!+The+bottom+compartment+is+huge.+The+top+flip+up+compartments+are+great%3B+I+didn’t+realize+they+would+be+big+enough+for+pens+and+pencils%2C+so+you+can+put+a+quick+item+or+two+for+your+current+project+in+there+and+not+have+to+go+into+the+box!#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=Lid+came+apart+immediately+upon+opening.+Impossible+to+reassemble.+CHEAP+CRAP!+I+had+this+box+in+college+20+years+ago.+Was+solid%2C+sturdy+quality+plastic+for+all+art+supplies.+Save+your+money!+Go+to+a+craft+store%2C+or+better+yet%2C+spend+good+money+at+an+art+store.#
URL GOTO=http://10.1.10.35/logout.php
boot camp build2.iim:
URL GOTO=http://10.1.10.35/
URL GOTO=http://10.1.10.35/login.php
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:login.php ATTR=NAME:username CONTENT=gordonb
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:login.php ATTR=NAME:password CONTENT=abc123
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:login.php ATTR=NAME:Login
URL GOTO=http://10.1.10.35/login.php?username=admin&password=password#
URL GOTO=http://10.1.10.35/login.php?username=gordonb&password=abc123#
URL GOTO=http://10.1.10.35/index.php
URL GOTO=http://10.1.10.35/instructions.php?doc=copying
URL GOTO=http://10.1.10.35/instructions.php?doc=PHPIDS-license
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=I+have+a+lot+of+text+to+enter+into+this+field.#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=F5+Networks,+401+Elliott+Ave.+W.,+Seattle,+WA+98119#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=In+New+York+Slice%2C+each+player+slices+up+pizzas%2C+giving+their+opponents+first+choice%2C+while+they+take+the+leftovers.+There+are+a+dozen+kinds+of+pizza+to+work+with+and+each+player+decides+if+they+want+to+eat+or+keep+slices%2C+building+the+best+pizzas%21+#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=%27Some+slices+have+anchovies+on+them+%28yuck%21%29%2C+which+are+worth+negative+points+%E2%80%94+but+anchovies+might+show+up+on+different+pizza+types+you%27re+collecting%2C+so+in+order+to+have+the+majority%2C+you+just+might+have+to+collect+one+with+anchovies+on+it.%27#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=I+absolutely+love+this+art+box!+The+bottom+compartment+is+huge.+The+top+flip+up+compartments+are+great%3B+I+didn’t+realize+they+would+be+big+enough+for+pens+and+pencils%2C+so+you+can+put+a+quick+item+or+two+for+your+current+project+in+there+and+not+have+to+go+into+the+box!#
URL GOTO=http://10.1.10.35/vulnerabilities/xss_r/?name=Lid+came+apart+immediately+upon+opening.+Impossible+to+reassemble.+CHEAP+CRAP!+I+had+this+box+in+college+20+years+ago.+Was+solid%2C+sturdy+quality+plastic+for+all+art+supplies.+Save+your+money!+Go+to+a+craft+store%2C+or+better+yet%2C+spend+good+money+at+an+art+store.#
URL GOTO=http://10.1.10.35/logout.php
打开allowed file types
当我们删除并重新创建这个安全策略的时候,我们将会丢失之前添加进来的文件类型
打开新的无痕窗口,点击imacros,点击boot camp build1.iim,然后点击play(Loop)
这个imacros会发出几个web请求,包括SQL injection和XSS reflected页面,等macros完成后,关闭页面
在配置页面,打开traffic learning
这里有关于illegal file type,illegal url,illegal paramemer的学习建议吗?为什么?
答:没有这几个类型的学习建议
因为这几个类型在learnng and blocking配置里被配置为所有类型都列入白名单

打开allowed file types页面
可以看到很多文件类型被自动列了进来,并且处于staging状态,说明他们并没有被enforced,没有被执行
打开allowed urls页面
有32条allowed urls记录被自动添加进来
打开parameters list页面
也有新的parameters被添加
看一下 parameter value type,这里有ignore value,user-input value,两种类型
现在再次打开一个新的页面,点击imacros里面的boot camp build2.iim,点击play(loop),运行结束时,关闭页面
打开配置页面到allowed file type页面
可以看到有几个类型不再是staging状态,也就是说现在处于enforced状态
注:如果没有状态改变的话,等几秒钟再重新跑一遍imacros
打开parameters list,name一项的parameter value type改成了user-input value
目前处于staging状态
20秒后再打开页面运行一遍,运行完成关闭页面,下载name这一项不在是staging状态
点开name这一项,目前我这里maximum length的值为500
正常情况下,运行了boot camp build2.iim几次后,这里的值会是10,当运行次数变多后,这个值将不满足name这一项的长度要求,并且系统会自适应修改这个值,并且状态反复在staging和enforced中跳跃,直到最终变成500
打开value meta character页面,这里可以看到被允许的meta character
name这一项状态处于enforced,maximum length 为500,且meta character有了记录之后,打开learning and blocking页面(否则继续执行boot camp build2.iim),learning mode改成manual,保存并应用策略
打开新的页面,用gordonb/abc123登录dvwa,点击xss reflected,输入以下内容并提交
This is a very cute Rocket Ship projection alarm clock. It is 100% attractive sitting on my dresser.
The Rocket Ship reminds me of the rockets in TV and movies and books from the 50’s. Rocket alarm clock
projects the time and four different NASA images on the ceiling or wall. There are four NASA space
images to choose from: “man on the Moon”, “earth”, “Moon” and “space shuttle”. The top of the clock
rotates and pivots allowing the time and image to project anywhere in the room. Images project up to
30 inches in diameter. Powered by 3 C batteries (not Included) or Included AC adaptor. Children will
love having this rocket ship alarm clock in their bedroom. Alarm button on/off is on the side.
操作被block
查看日志,查看最新的/vulnerabilities/xss_r/的条目,有两个原因导致访问被block
一是value长度大于设定的500
二是解码出来的character %不在允许的meta character里

在第一个illegal parameter value length违规行为,点击后面的view suggestion based on this violation
可以跳转到学习建议页面,这里建议将length改成1000,点击accept suggestion,然后关闭学习建议页面
同样的,接受第二条的学习建议,应用策略并关闭学习建议页面
任务四 测试signature violations
测试ASM是否会block违反特征库特征的请求
打开xss reflected页面,输入以下内容并提交
结果页面被block
打开sql injection,输入以下内容并提交
%’ or 1='1
结果这个sql攻击仍然可以生效
右击页面,点击检查,知道输入框对应的name,这里显示name=id
关闭检查窗口
打开parameter list窗口,为什么name parameter对应的攻击特征被block,id parameter对应的攻击特征没有被block
我认为是因为id parameter处于staging状态
点击id,清除perform staging勾选框
parameter value type 改成user-input value
maximum length 改成25,更新并应用策略
回到攻击页面,ctrl + F5刷新,页面被block
parameter value type:
ignore value:系统不会检查这个parameter的有效性,对于特征,系统不会进行基于parameter的特征检查,但是会进行其他特征检查
就是没法明细这个parameter的特征检查控制了

json value:这个parameter的值强制执行为json数据

user-input value:parameter值由用户输入提供,可以自定义下面这些内容


1万+

被折叠的 条评论
为什么被折叠?



