Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 9849818

Browse files
committed
#33 Fix parser to handle empty service fields
1 parent b74fd3d commit 9849818

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

scanners/nmap/parser/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scanners/nmap/parser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"author": "iteratec GmbH",
99
"license": "Apache-2.0",
1010
"dependencies": {
11+
"lodash": "^4.17.15",
1112
"xml2js": "^0.4.22"
1213
},
1314
"devDependencies": {}

scanners/nmap/parser/parser.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const xml2js = require('xml2js');
2+
const { get } = require('lodash');
23

34
async function parse(fileContent) {
45
const hosts = await parseResultFile(fileContent);
@@ -271,13 +272,13 @@ function parseResultFile(fileContent) {
271272

272273
const port = parseInt(portItem.$.portid, 10);
273274
const protocol = portItem.$.protocol;
274-
const service = portItem.service[0].$.name;
275-
const serviceProduct = portItem.service[0].$.product;
276-
const serviceVersion = portItem.service[0].$.version;
275+
const service = get(portItem, ["service",0,"$","name"]);
276+
const serviceProduct = get(portItem, ["service",0,"$","product"]);
277+
const serviceVersion = get(portItem, ["service",0,"$","version"]);
277278

278-
const tunnel = portItem.service[0].$.tunnel;
279-
const method = portItem.service[0].$.method;
280-
const product = portItem.service[0].$.tunnel;
279+
const tunnel = get(portItem, ["service",0,"$","tunnel"]);
280+
const method = get(portItem, ["service",0,"$","method"]);
281+
const product = get(portItem, ["service",0,"$","tunnel"]);
281282

282283
const state = portItem.state[0].$.state;
283284

0 commit comments

Comments
 (0)