diff --git a/examples/no-defaults.js b/examples/no-defaults.js new file mode 100644 index 0000000..4ce507a --- /dev/null +++ b/examples/no-defaults.js @@ -0,0 +1,22 @@ +/*! + * libnmap + * Copyright(c) 2021 Evandro Brandão + * License: MIT + */ + +'use strict' + +const nmap = require('../'); +const opts = { + range: ['scanme.nmap.org', '127.0.0.1'], + noDefaults: true +}; + + +nmap.scan(opts, function(err, report) { + if (err) throw new Error(err); + + for (let item in report) { + console.log(JSON.stringify(report[item], null, 2)); + } +}); \ No newline at end of file diff --git a/lib/classes/tools.js b/lib/classes/tools.js index c8d8bd8..d7c640a 100644 --- a/lib/classes/tools.js +++ b/lib/classes/tools.js @@ -158,14 +158,13 @@ class tools extends emitter { */ command(opts, block) { const flags = opts.flags.join(' '); - const proto = (opts.udp) ? ' -sU' : ' '; - const to = `--host-timeout=${opts.timeout}s `; + const proto = (opts.udp) ? ' -sU ' : ' '; + const to = opts.timeout ? `--host-timeout=${opts.timeout}s ` :''; const ipv6 = (validation.test(validation.patterns.IPv6, block)) ? ' -6 ' : ' '; - return (opts.ports) ? - `${opts.nmap+proto} ${to}${flags}${ipv6}-p${opts.ports} ${block}` : - `${opts.nmap+proto} ${to}${flags}${ipv6}${block}`; + `${opts.nmap+proto}${to}${flags}${ipv6}-p${opts.ports} ${block}` : + `${opts.nmap+proto}${to}${flags}${ipv6}${block}`; } @@ -197,6 +196,11 @@ class tools extends emitter { const ranges = []; const called = caller.get()[1].getFunctionName(); + /** Remove defaults options if user disabled it (flags, ports, timeout) */ + if(opts.noDefaults) { + const {ports, timeout, ...defaultsRest} = defaults; + defaults = {...defaultsRest, flags: []}; + } /* Override 'defaults.flags' array with 'opts.flags' (prevents merge) */ if (/array/.test(typeof opts.flags)) defaults.flags = opts.flags; diff --git a/lib/classes/validation.js b/lib/classes/validation.js index 3e8b21c..ffa323b 100644 --- a/lib/classes/validation.js +++ b/lib/classes/validation.js @@ -100,7 +100,6 @@ class validation { const scope = this; let errors = []; let result; - scope.exists(opts.nmap, (result) => { if (!result) { diff --git a/package.json b/package.json index 94a74b5..bd41ff6 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "libnmap", + "name": "libnmap-xtr", "version": "v0.4.19", "description": "libnmap for node.js", - "author": "Jason Gerfen ", + "author": "Jason Gerfen , Evandro Brandão ", "keywords": [ "nmap", "libnmap", @@ -23,14 +23,11 @@ ], "repository": { "type": "git", - "url": "https://github.com/jas-/node-libnmap.git" - }, - "bugs": { - "url": "https://github.com/jas-/node-libnmap/issues" + "url": "https://github.com/kingaribel/node-libnmap.git" }, "scripts": { "start": "node index.js", - "test": "./node_modules/.bin/mocha -R spec" + "test": "./node_modules/.bin/mocha " }, "dependencies": { "async": "^2.6.3", diff --git a/test/no-defaults.spec.js b/test/no-defaults.spec.js new file mode 100644 index 0000000..f0d9b9f --- /dev/null +++ b/test/no-defaults.spec.js @@ -0,0 +1,50 @@ +/*! + * libnmap + * Copyright(c) 2013-2019 Jason Gerfen + * License: MIT + */ + +'use strict' + +const nmap = require('../'); +const timeout = 1024 * 1024 * 3; +const chai = require('chai'); +const should = chai.should(); +const expect = chai.expect; +const opts = { + range: [ + '127.0.0.1', + 'scanme.nmap.org', + '::1' + ], + noDefaults: true +}; + + +describe('scan method', function () { + + context('reporting', function () { + it('json', function (done) { + this.timeout(timeout); + + nmap.scan(opts, function (err, report) { + should.not.exist(err); + + report.should.be.a('object'); + done(); + }); + }); + + it('xml', function (done) { + this.timeout(timeout); + opts.json = false; + + nmap.scan(opts, function (err, report) { + should.not.exist(err); + + report.should.be.a('object'); + done(); + }); + }); + }); +});