Skip to content

Commit c519f69

Browse files
committed
separted out the file reader
1 parent 23a774e commit c519f69

File tree

6 files changed

+44
-16
lines changed

6 files changed

+44
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ At the top of the Html content, look for a `<![CDATA[ \"-alert(123456789))// ]]>
3030
## Additional Resources
3131

3232
[OWASP XSS Cheatsheet](https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet)
33+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xss-scanner",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Cross-Site Scripting (XSS) scanner. This tool helps to find possible XSS vulnerabilities.",
55
"keywords" : [ "xss", "xss-vulnerability", "xss-detection", "xss-exploitation", "xss-scanner" ],
66
"repository": {

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function xssOptions() {
1010
// port: 8888
1111
// },
1212

13+
payloadFile: "data/payload.test.txt",
1314
fileOutput: false,
1415
host: "www.yourwebsite.com",
1516
port: 80,

src/payload.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
var { stringFormat } = require('./util');
1+
var { stringFormat, ripPayload } = require('./util');
22
var { xssOptions } = require('./config');
33

44
const http = require("http");
55
const fs = require("fs");
66
const uuid = require("node-uuid");
7-
const readline = require("readline");
87
const chalk = require("chalk");
98

109
const config = xssOptions();
1110

12-
const payloadFileReader = readline.createInterface({
13-
input: fs.createReadStream("data/payload.txt")
14-
});
15-
16-
payloadFileReader.on("line", (line) => {
17-
if (line.length === 0) return;
18-
19-
attack(line);
20-
});
21-
2211
var attack = function (line) {
2312
try {
2413
var reqOptions = {
@@ -77,4 +66,6 @@ var attack = function (line) {
7766
} catch (err) {
7867
console.log(chalk.red(err + " - " + line));
7968
}
80-
};
69+
};
70+
71+
ripPayload(config.payloadFile, attack);

src/util.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module.exports = {
2-
stringFormat
2+
stringFormat,
3+
ripPayload
34
}
45

6+
const readline = require("readline");
7+
const fs = require("fs");
8+
59
// Thanks ASP.NET AJAX 1.0 Source Code Released
610
// https://weblogs.asp.net/scottgu/asp-net-ajax-1-0-source-code-released
711
function stringFormat (s) {
@@ -10,4 +14,22 @@ function stringFormat (s) {
1014
s = s.replace(reg, arguments[i + 1]);
1115
}
1216
return s;
17+
};
18+
19+
function ripPayload(pathToPayload, attackCallback, doneCallback) {
20+
let payloadReader = readline.createInterface({
21+
input: fs.createReadStream(pathToPayload)
22+
});
23+
24+
payloadReader.on("line", (line) => {
25+
if (line.length === 0) return;
26+
27+
attackCallback(line);
28+
});
29+
30+
payloadReader.on("close", () => {
31+
if (doneCallback) {
32+
doneCallback();
33+
}
34+
});
1335
};

tests/util.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var { stringFormat } = require('../src/util');
1+
var { stringFormat, ripPayload } = require('../src/util');
22

33
const chai = require("chai");
44
const expect = chai.expect;
@@ -15,4 +15,17 @@ describe("stringFormat", () => {
1515

1616
expect(actual).to.equal("/whatever.php?foo=bar&fizz=buzz");
1717
});
18+
});
19+
20+
describe("ripPayload", () => {
21+
it("should rip line by line the input and invoke callback", (done) => {
22+
let actualAttacks = 0;
23+
24+
ripPayload("data/payload.test.txt", (line) => {
25+
actualAttacks++;
26+
}, () => {
27+
expect(actualAttacks).to.equal(12);
28+
done();
29+
});
30+
});
1831
});

0 commit comments

Comments
 (0)