-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
55 lines (51 loc) · 1.48 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const express = require('express');
const axios = require('axios');
const app = express();
const port = 9090;
app.use(express.urlencoded({ extended: true }));
app.get('/', (req, res) => {
res.send(`
<h1>SSRF Demo</h1>
<h4> The URL should be in the format "http/s://example.com"
<form action="/fetch-url" method="post">
<label for="url">Enter URL:</label>
<input type="text" id="url" name="url" required>
<button type="submit">Fetch URL</button>
</form>
<div id="result"></div>
`);
});
app.post('/fetch-url', async (req, res) => {
const { url } = req.body;
try {
const response = await axios.get(url);
res.send(`
<h1>SSRF Demo</h1>
<form action="/fetch-url" method="post">
<label for="url">Enter URL:</label>
<input type="text" id="url" name="url" required>
<button type="submit">Fetch URL</button>
</form>
<div id="result">
<h2>Fetched Content:</h2>
<pre>${response.data}</pre>
</div>
`);
} catch (error) {
res.send(`
<h1>SSRF Demo</h1>
<form action="/fetch-url" method="post">
<label for="url">Enter URL:</label>
<input type="text" id="url" name="url" required>
<button type="submit">Fetch URL</button>
</form>
<div id="result">
<h2>Error fetching content:</h2>
<pre>${error.message}</pre>
</div>
`);
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});