-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
77 lines (64 loc) · 1.76 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
//Dependencies
const Axios = require("Axios")
const Fs = require("fs")
//Variables
const Self_Args = process.argv.slice(2)
var Self = {
check_index: 0,
data: null,
results: []
}
//Functions
async function check(i){
try{
const response = await Axios({
method: "GET",
url: Self.data[i],
headers: {
origin: "https://attacker.com"
}
})
if(JSON.stringify(response.headers).indexOf("https://attacker.com") !== -1){
console.log(`${Self.data[i]} vulnerable to CORS.`)
Self.results.push(Self.data[i])
}else{
console.log(`${Self.data[i]} not vulnerable to CORS.`)
}
}catch{
console.log(`${Self.data[i]} not vulnerable to CORS.`)
}
Self.check_index++
if(Self.check_index === Self.data.length){
console.log("Finished checking.")
if(!Self.results.length){
console.log("No links is vulnerable to CORS.")
}else{
console.log(`Saving results to ${Self_Args[1]}`)
Fs.writeFileSync(Self_Args[1], Self.results.join("\n"), "utf8")
console.log(`Results successfully saved to ${Self_Args[1]}`)
}
process.exit()
}
}
//Main
if(!Self_Args.length){
console.log("node index.js <input> <output>")
process.exit()
}
if(!Fs.existsSync(Self_Args[0])){
console.log("Invalid input.")
process.exit()
}
if(!Self_Args[1]){
console.log("Invalid output.")
process.exit()
}
const input_data = Fs.readFileSync(Self_Args[0], "utf8").replace(/\r/g, "").split("\n")
if(!input_data.length){
console.log("Input data is empty.")
process.exit()
}
Self.data = input_data
for( i = 0; i <= input_data.length-1; i++ ){
check(i)
}