启动mysql:php
sudo mysqld_safe
注意启动后程序不会退出,能够打开新的终端执行后续命令。
mysql
启动Apache:sql
sudo service apache2 start
配置DNS:数据库
sudo vim /etc/hosts
在原来的基础上直接添加
apache
配置网站文件:vim
sudo vim /etc/apache2/conf.d/lab.conf
关闭php配置策略:缓存
sudo vim /etc/php5/apache2/php.ini
把magic_quotes_gpc=On 改成 magic_quotes_gpc = Off
服务器
访问:www.sqllabcollabtive.com;当咱们知道用户而不知道到密码的时候,咱们能够怎么登录?cookie
查看登录验证文件:网络
sudo vim /var/www/SQL/Collabtive/include/class.user.php
设置行号 :set number
找到其中第375行 :375
$sel1 = mysql_query ("SELECT ID, name, locale, lastlogin, gender, FROM user WHERE (name = '$user' OR email = '$user') AND pass = '$pass'");
这一句就是咱们登陆时,后台的sql语句;咱们能够构造一个语句,在不知道密码的状况下登录;
修改完后重启一下服务器:
sudo service apache2 restart
咱们在$user后面加上) # 这样就会只验证用户名,后面的会被#注释
绕过密码登陆成功
Collabtive平台中能够更新用户信息,咱们要实现经过本身的用户去修改别人的用户信息;
咱们使用任意用户,如: bob bob 进行登陆;
在编辑用户的位置:user 填 ted 用户;
Company 处填:
', `pass` = '9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684' WHERE ID = 4 # ' 注:这里的 9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684 就是pass的md5值;
点击修改,而后咱们退出当前用户,使用ted用户登陆,这个时候ted用户的密码应该是pass;
SQL注入漏洞的根本问题是数据与代码的分离失败,所以咱们能够针对这个缘由进行防护
防护转义特殊字符使用,默认开启magic_quotes_gpc,将magic_quotes_gpc值设为On。
sudo vim /etc/php5/apache2/php.ini
MySQL提供一个函数 mysql_real_escape_string(),这个函数能够用来过滤一些特殊字符;如\x00, \n, \r, , ', " and \x1a;
代码防护示例:
sudo vim /var/www/SQL/Collabtive/include/class.user.php
修改下图红色框中部分
以及编辑用户代码部分
修改下图红框部分
修改成以下:
// This code was provided by the lab's author Wenliang Du, of Syracuse // University under the GNU Free Documentation License function login($user, $pass) { if (!$user) { return false; } // modification fixed $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); $pass = sha1($pass); $sel1 = mysql_query("SELECT ID, name, locale, lastlogin, gender FROM user WHERE (name = '$user' OR email = '$user') AND pass = '$pass'"); $chk = mysql_fetch_array($sel1); if ($chk["ID"] != "") { // New user session object and cookie creation code // removed for brevity return true; } else { return false; } }
以及编辑用户代码:
function edit($id, $name, $realname, $email, $tel1, $tel2, $company, $zip, $gender, $url, $address1, $address2, $state, $country, $tags, $locale, $avatar = "", $rate = 0.0) { $name = mysql_real_escape_string($name); $realname = mysql_real_escape_string($realname); // modification fixed $company = mysql_real_escape_string($company); $email = mysql_real_escape_string($email); // further escaped parameters removed for brevity... $rate = (float) $rate; $id = (int) $id; if ($avatar != "") { $upd = mysql_query("UPDATE user SET name='$name', email='$email', tel1='$tel1', tel2='$tel2', company='$company', zip='$zip', gender='$gender', url='$url', adress='$address1', adress2='$address2', state='$state', country='$country', tags='$tags', locale='$locale', avatar='$avatar', rate='$rate' WHERE ID = $id"); } else { // same query as above minus setting avatar; removed for // brevity } if ($upd) { $this->mylog->add($name, 'user', 2, 0); return true; } else { return false; } }
经过SQL逻辑分离来告诉数据库究竟是哪部分是数据部分,哪一部分是SQL语句部分;
提供以新的new mysqli()函数, 将这个函数写入config/standary/config.php文件:
sudo vim /var/www/SQL/Collabtive/include/class.user.php
修改代码以下:
// This code was provided by the lab's author Wenliang Du, of Syracuse // University under the GNU Free Documentation License function login($user, $pass) { if (!$user) { return false; } // using prepared statements // note that $conn is instantiated in the datenbank class found in // ./class.datenbank.php. this may need to be passed in, but we // will assume we have access to it for the sake of brevity $stmt = $conn->prepare("SELECT ID,name,locale,lastlogin,gender FROM user WHERE (name=? OR email=?) AND pass=?"); $stmt->bind_param("sss", $user, $user, sha1($pass)); $stmt->execute(); $stmt->bind_result($bind_ID, $bind_name, $bind_locale, $bind_lastlogin, $bind_gender); $chk = $stmt->fetch(); if ($bind_ID != "") { // New user session object and cookie creation code // removed for brevity return true; } else { return false; } }
以及编辑用户处的代码:
// This code was provided by the lab's author Wenliang Du, of Syracuse // University under the GNU Free Documentation License function edit($id, $name, $realname, $email, $tel1, $tel2, $company, $zip, $gender, $url, $address1, $address2, $state, $country, $tags, $locale, $avatar = "", $rate = 0.0) { // the bind_param() function wants a double, not float, though // they are the same internally $rate = (double) $rate; $id = (int) $id; if ($avatar != "") { // again, $conn is instantiated in the datenbank class, and // may need to be passed, but we are assuming we have // access to it for the sake of brevity // note that the app uses zip as a string, does not use // realname although it is passed, and the columns adress // and adress2 are misspelled $stmt = $conn->prepare("UPDATE user SET name=?, email=?, tel1=?, tel2=?, company=?, zip=?, gender=?, url=?, adress=?, adress2=?, state=?, country=?, tags=?, locale=?, avatar=? rate=? WHERE ID = ?"); $stmt->bind_param("sssssssssssssssdi", $name, $email, $tel1, $tel2, $company, $zip, $gender, $url, $address1, $address2, $state, $country, $tags, $locale, $avatar, $rate, $id); $upd = $stmt->execute(); } else { $stmt = $conn->prepare("UPDATE user SET name=?, email=?, tel1=?, tel2=?, company=?, zip=?, gender=?, url=?, adress=?, adress2=?, state=?, country=?, tags=?, locale=?, rate=? WHERE ID = ?"); $stmt->bind_param("ssssssssssssssdi", $name, $email, $tel1, $tel2, $company, $zip, $gender, $url, $address1, $address2, $state, $country, $tags, $locale, $rate, $id); $upd = $stmt->execute(); } if ($upd) { $this->mylog->add($name, 'user', 2, 0); return true; } else { return false; } }
参考课程资源中的“TCP_IP网络协议攻击实验.pdf ”
以SEED为攻击机,以Linux Metasploitable/Windows Metasploitable作靶机完成TCP/IP协议攻击,提交本身攻击成功截图,加上本身的学号水印。任选两个攻击:
ARP缓存欺骗攻击,ICMP重定向攻击,SYN Flood攻击,TCP RST攻击,TCP 会话劫持攻击
选择了ARP缓存欺骗攻击和SYN Flood攻击
一、ARP缓存欺骗攻击
首先查看两个靶机的IP地址:
一个是172.16.6.21,另外一个是172.16.6.117
初始ARP缓冲中没有内容
攻击机能够ping通两个靶机
得到两个靶机的IP和mac地址
打开攻击机上的netwox,依次输入五、33,使用netwox中的工具伪造ARP数据包,使用如下两条命令
此时再查看靶机的ARP缓存,发现欺骗成功。
二、SYN Flood攻击
查看靶机IP地址
攻击机Telnet连接靶机23端口,成功,能够链接
使用netwag攻击进行SYN flood攻击
打开的界面
搜索并选择SYN
设置靶机的IP地址和端口
开启tcpdump监听
实施攻击
攻击成功,没法Telnet连接上靶机