728x90
Blind SQL Injection
- 결과가 직접 노출되지 않아도 데이터베이스의 참/거짓 응답을 통해 정보를 추출하는 공격

DVWA Blind SQL Injection 페이지는 SQL Injection과 같은 기능을 하고 있다.
ㅤ

패킷을 캡처해서 봐도 POST 요청으로 id 값과 Submit 값을 받는 것 또한 동일했다.
ㅤ

하지만 Blind SQL Injection은 쿼리의 결과가 출력되지 않고 존재 유무에 대한 결과만 반환되고 있는 걸 알 수 있었다.
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$id = $_POST[ 'id' ];
$exists = false;
switch ($_DVWA['SQLI_DB']) {
case MYSQL:
$id = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = $id;";
try {
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query ); // Removed 'or die' to suppress mysql errors
} catch (Exception $e) {
print "There was an error.";
exit;
}
$exists = false;
if ($result !== false) {
try {
$exists = (mysqli_num_rows( $result ) > 0); // The '@' character suppresses errors
} catch(Exception $e) {
$exists = false;
}
}
break;
case SQLITE:
global $sqlite_db_connection;
$query = "SELECT first_name, last_name FROM users WHERE user_id = $id;";
try {
$results = $sqlite_db_connection->query($query);
$row = $results->fetchArray();
$exists = $row !== false;
} catch(Exception $e) {
$exists = false;
}
break;
}
if ($exists) {
// Feedback for end user
$html .= '<pre>User ID exists in the database.</pre>';
} else {
// Feedback for end user
$html .= '<pre>User ID is MISSING from the database.</pre>';
}
}
?>
DVWA 깃허브 코드를 보니, 역시 id를 제출하면 데이터가 DB에 있는지 존재 유무에 대한 메시지만 출력한다는 것을 알 수 있었다.

이 문제 또한 union을 사용하여 column 개수를 찾아보았다.union select 이후에 1, 2, 3 차례대로 추가해가면서 페이지의 출력되는 메시지를 확인했고,
ㅤ

union select 1,2 를 입력했을 때 참이 되었다. 따라서 Blind SQL Injection을 통해 컬럼 개수가 2개인 것을 알게 되었다.
ㅤ

또한 and length(database()) 의 값은 하나씩 대입해보며 데이터베이스 이름의 길이를 알아보았고,and length(database())=4 일 때 참이 되었다. 따라서 참/거짓 정보만을 통해 데이터베이스 이름 길이가 4글자인 것을 알게 되었다.
728x90
'DVWA' 카테고리의 다른 글
| DVWA | DOM XSS | medium (0) | 2024.11.26 |
|---|---|
| DVWA | Weak Session IDs | medium (0) | 2024.11.26 |
| DVWA | SQL Injection | medium (0) | 2024.11.21 |
| DVWA | Insecure CAPTCHA | medium (1) | 2024.11.20 |
| DVWA | File Upload | medium (0) | 2024.11.20 |