forked from pthreat/nmapeteer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
93 lines (71 loc) · 1.71 KB
/
test.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
const puppeteer = require('puppeteer');
log = process.argv[2],
fs = require('fs'),
xml2js = require('xml2js'),
util = require('util');
process.setMaxListeners(0);
async function loadFile (file) {
return new Promise((resolve, reject) => {
fs.readFile(file, function (err, data) {
let ret = [],
xmlParser = new xml2js.Parser();
xmlParser.parseString(data, function (err, result) {
result.nmaprun.host.map(item => {
let addr = item.address[0]['$'].addr,
ports = item.ports[0].port;
ports.map(port => {
let state = port.state[0]['$'].state,
number = port['$'].portid,
proto = port.service[0]['$'].name;
if (proto === 'http-proxy') {
proto = 'http';
}
if ('open' !== state) {
return;
}
ret.push({
addr: addr,
proto: proto,
number: number
});
});
});
});
return resolve(ret);
});
});
}
async function navigate(url, output){
let args = {
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--ignore-certificate-errors'
]
};
const browser = await puppeteer.launch(args);
try {
const page = await browser.newPage();
await page.goto(url, {timeout: 100000});
await page.screenshot({path: output});
await browser.close();
}catch(error){
browser.close();
}finally{
browser.close();
}
}
loadFile(log)
.then(async hosts => {
for (let i = 0; i < hosts.length; i++) {
let host = hosts[i],
addr = host.addr,
proto = host.proto,
screenshot = './screenshots/' + proto + '_' + addr + '.png';
let url = proto + '://' + addr;
console.log('Navigate to: ', url);
await navigate(url, screenshot);
console.log('END');
}
});