jas- / node-libnmap

API to access nmap from node.js
MIT License
257 stars 42 forks source link

Multiple problems under MS Windows #19

Closed bwerst closed 9 years ago

bwerst commented 9 years ago

Having several issues with node-libnmap.js running in a windows environment.

nmap was installed via downloaded installer from nmap.org. nmap is in the command line PATH.

I could not get fs.exists(opts.nmap, function(exists) to work correctly around line 193. Tried multiple settings for defaults.nmap. Eventually gave up and commented out the body of the check: function(opts) {....

Removing the check function allowed discover() to work successfully. Scan however is failing with null errors on the line if(host[1]) around line 559. TypeError: Cannot read property '1' of null.

local host was originally in my range array, but remembered reading that nmap on windows doesn't like localhost. I think the null host value mentioned above is because it appears to be scanning the local workstation at its actual designated IP address. I had similar error with localhost.

Unfortunately, I still rate as a beginner at javascript so I'm having trouble modifying the code to add more preventative checks.

jas- commented 9 years ago

Please provide a test case

bwerst commented 9 years ago

Windows 7 Pro nmap installed from packaged installer 5.61-Spiceworks. Its in my PATH.

My test code is: var scanner = require('node-libnmap') var opts = { range: ['10.2.0.0/24']

} scanner.nmap('scan', opts, function(err, report) { if (err) console.error(err) report.forEach(function(item){ console.log('Parent Item: ' + item[0]) }) })

Attached is my modified node-libnmap.js.

I added some debugging console logs, here's my output:

C:\bwerst\projects\nmap>node nmap-scandetail.js Checking file exists: nmap detail = 'Host: 10.2.0.72 ()' report() check host: [ 'Host: 10.2.0.72 ()', '10.2.0.72', '', index: 0, input: 'Host: 10.2.0.72 ()' ] detail = 'Ports: 23/open/tcp//telnet///, 80/open/tcp//http///, 8082/open/tcp//bl ackice-alerts///' detail = 'Ignored State: closed (997)' detail = 'Host: 10.2.0.100 (HDHR-10185744.red.local)' report() check host: [ 'Host: 10.2.0.100 (HDHR-10185744.red.local)', '10.2.0.100', 'HDHR-10185744.red.local', index: 0, input: 'Host: 10.2.0.100 (HDHR-10185744.red.local)' ] detail = 'Ports: 80/open/tcp//http///' detail = 'Ignored State: closed (999)\r' detail = 'Host: 10.2.0.110 (linux.red.local)' report() check host: [ 'Host: 10.2.0.110 (linux.red.local)', '10.2.0.110', 'linux.red.local', index: 0, input: 'Host: 10.2.0.110 (linux.red.local)' ] detail = 'Ports: 22/open/tcp//ssh///, 80/open/tcp//http///, 443/open/tcp//https/ //' detail = 'Ignored State: filtered (997)\r' detail = 'Host: 10.2.0.111 ()' report() check host: [ 'Host: 10.2.0.111 ()', '10.2.0.111', '', index: 0, input: 'Host: 10.2.0.111 ()' ] detail = 'Ports: 22/open/tcp//ssh///, 80/open/tcp//http///, 443/open/tcp//https/ //' detail = 'Ignored State: closed (997)\r' detail = 'Host: 10.2.0.114 (WC514301.red.local)' report() check host: [ 'Host: 10.2.0.114 (WC514301.red.local)', '10.2.0.114', 'WC514301.red.local', index: 0, input: 'Host: 10.2.0.114 (WC514301.red.local)' ] detail = 'Ports: 1/unknown/tcp//tcpmux///, 3/unknown/tcp//compressnet///, 4/unkn own/tcp//unknown///, 6/unknown/tcp//unknown///, 7/unknown/tcp//echo///, 9/unknow n/tcp//discard///, 13/unknown/tcp//daytime///, 17/unknown/tcp//qotd///, 19/unkno wn/tcp//chargen///, 20/unknown/tcp//ftp-data///, 21/unknown/tcp//ftp///, 22/unkn own/tcp//ssh///, 23/unknown/tcp//telnet///, 24/unknown/tcp//priv-mail///, 25/unk nown/tcp//smtp///, 26/unknown/tcp//rsftp///, 30/unknown/tcp//unknown///, 32/unkn own/tcp//unknown///, 33/unknown/tcp//dsp///, 37/unknown/tcp//time///, 42/unknown /tcp//nameserver///, 43/unknown/tcp//whois///, 49/unknown/tcp//tacacs///, 53/unk nown/tcp//domain///, 70/unknown/tcp//gopher///, 79/unknown/tcp//finger///, 80/un known/tcp//http///, 81/unknown/tcp//hosts2-ns///, 82/unknown/tcp//xfer///, 83/un known/tcp//mit-ml-dev///, 84/unknown/tcp//ctf///, 85/unknown/tcp//mit-ml-dev///, 88/unknown/tcp//kerberos-sec///, 89/unknown/tcp//su-mit-tg///, 90/unknown/tcp// dnsix///, 99/unknown/tcp//metagram///, 100/unknown/tcp//newacct///, 106/unknown/ tcp//pop3pw///, 109/unknown/tcp//pop2///, 110/unknown/tcp//pop3///, 111/unknown/ tcp//rpcbind///, 113/unknown/tcp//ident///, 119/unknown/tcp//nntp///, 125/unknow n/tcp//locus-map///, 135/unknown/tcp//msrpc///, 139/unknown/tcp//netbios-ssn///, 143/unknown/tcp//imap///, 144/unknown/tcp//news///, 146/unknown/tcp//iso-tp0/// , 161/unknown/tcp//snmp///, 163/unknown/tcp//cmip-man///, 179/unknown/tcp//bgp// /, 199/unknown/tcp//smux///, 211/unknown/tcp//914c-g///, 212/unknown/tcp//anet// /, 222/unknown/tcp//rsh-spx///, 254/unknown/tcp//unknown///, 255/unknown/tcp//un known///, 256/unknown/tcp//fw1-secureremote///, 259/unknown/tcp//esro-gen///, 26 4/unknown/tcp//bgmp///, 280/unknown/tcp//http-mgmt///, 301/unknown/tcp//unknown/ //, 306/unknown/tcp//unknown///, 311/unknown/tcp//asip-webadmin///, 340/unknown/ tcp//unknown///, 366/unknown/tcp//odmr///, 389/unknown/tcp//ldap///, 406/unknown /tcp//imsp///, 407/unknown/tcp//timbuktu///, 416/unknown/tcp//silverplatter///, 417/unknown/tcp//onmux///, 425/unknown/tcp//icad-el///, 427/unknown/tcp//svrloc/ //, 443/unknown/tcp//https///, 444/unknown/tcp//snpp///, 445/unknown/tcp//micros oft-ds///, 458/unknown/tcp//appleqtc///, 464/unknown/tcp//kpasswd5///, 465/unkno wn/tcp//smtps///, 481/unknown/tcp//dvs///, 497/unknown/tcp//retrospect///, 500/u nknown/tcp//isakmp///, 512/unknown/tcp//exec///, 513/unknown/tcp//login///, 514/ unknown/tcp//shell///, 515/unknown/tcp//printer///, 524/unknown/tcp//ncp///, 541 /unknown/tcp//uucp-rlogin///, 543/unknown/tcp//klogin///, 544/unknown/tcp//kshel l///, 545/unknown/tcp//ekshell///, 548/unknown/tcp//afp///, 554/unknown/tcp//rts p///, 555/unknown/tcp//dsf///, 563/unknown/tcp//snews///, 587/unknown/tcp//submi ssion///, 593/unknown/tcp//http-rpc-epmap///, 616/unknown/tcp//sco-sysmgr///, 61 7/unknown/tcp//sco-dtmgr///, 625/unknown/tcp//apple-xsrvr-admin///, 631/unknown/ tcp//ipp///, 636/unknown/tcp//ldapssl///, 646/unknown/tcp//ldp///, 648/unknown/t cp//rrp///, 666/unknown/tcp//doom///, 667/unknown/tcp//disclose///, 668/unknown/ tcp//mecomm///, 683/unknown/tcp//corba-iiop///, 687/unknown/tcp//asipregistry/// , 691/unknown/tcp//resvc///, 700/unknown/tcp//epp///, 705/unknown/tcp//agentx/// , 711/unknown/tcp//cisco-tdp///, 714/unknown/tcp//iris-xpcs///, 720/unknown/tcp/ /unknown///, 722/unknown/tcp//unknown///, 726/unknown/tcp//unknown///, 749/unkno wn/tcp//kerberos-adm///, 765/unknown/tcp//webster///, 777/unknown/tcp//multiling -http///, 783/unknown/tcp//spamassassin///, 787/unknown/tcp//qsc///, 800/unknown /tcp//mdbs_daemon///, 801/unknown/tcp//device///, 808/unknown/tcp//ccproxy-http/ //, 843/unknown/tcp//unknown///, 873/unknown/tcp//rsync///, 880/unknown/tcp//unk nown///, 888/unknown/tcp//accessbuilder///, 898/unknown/tcp//sun-manageconsole// /, 900/unknown/tcp//omginitialrefs///, 901/unknown/tcp//samba-swat///, 902/unkno wn/tcp//iss-realsecure///, 903/unknown/tcp//iss-console-mgr///, 911/unknown/tcp/ /xact-backup///, 912/unknown/tcp//apex-mesh///, 981/unknown/tcp//unknown///, 987 /unknown/tcp//unkno' report() check host: null C:\bwerst\projects\nmap\node_modules\node-libnmap\lib\node-libnmap.js:559 if (host[1]) ^ TypeError: Cannot read property '1' of null at C:\bwerst\projects\nmap\node_modules\node-libnmap\lib\node-libnmap.js:559 :25 at Array.forEach (native) at C:\bwerst\projects\nmap\node_modules\node-libnmap\lib\node-libnmap.js:553 :21 at Array.forEach (native) at Object.tools.report (C:\bwerst\projects\nmap\node_modules\node-libnmap\li b\node-libnmap.js:547:11) at Socket. (C:\bwerst\projects\nmap\node_modules\node-libnmap\lib \node-libnmap.js:94:30) at Socket.emit (events.js:129:20) at readableAddChunk (_stream_readable.js:163:16) at Socket.Readable.push (_stream_readable.js:126:10) at Pipe.onread (net.js:538:20)

C:\bwerst\projects\nmap>nmap -version

Nmap version 5.61-Spiceworks ( http://nmap.org ) Platform: i686-pc-windows-windows Compiled with: nmap-liblua-5.1.3 openssl-1.0.0a nmap-libpcre-7.6 libpcap-4.1.3 n map-libdnet-1.12 ipv6 Compiled without:

C:\bwerst\projects\nmap>

Thanks!

On Thu, Aug 27, 2015 at 8:34 AM, Jason Gerfen notifications@github.com wrote:

Please provide a test case

— Reply to this email directly or view it on GitHub https://github.com/jas-/node-libnmap/issues/19#issuecomment-135430624.

jas- commented 9 years ago

Please ommit your modified bit and provide the errors provided from the test case.

bwerst commented 9 years ago

How am I supposed to run the test case?

My project is 'c:\bwerst\projects\nmap. Under that is node_modules\node-libnmap as installed from 'npm install node-libnmap' run from my projects\nmap folder. Your readme says to test run 'npm test'. Its not clear where to run that from. I tried running it from node-libmap folder and get an error that 'make' is not recognized as an internal or external command.

I tried running your init.js and discover.js in the test folder and they had path errors.

C:\bwerst\projects\nmap\node_modules\node-libnmap\test>node discover.js module.js:338 throw err; ^ Error: Cannot find module 'chai' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at Object. (C:\bwerst\projects\nmap\node_modules\node-libnmap\test\discover.js:22:12) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10)

I tried copying those files to my project folder and then had different path related errors.

C:\bwerst\projects\nmap\node_modules\node-libnmap\test>node discover.js module.js:338 throw err; ^ Error: Cannot find module 'chai' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at Object. (C:\bwerst\projects\nmap\node_modules\node-libnmap\test\discover.js:22:12) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10)

On Thu, Aug 27, 2015 at 10:34 AM, Jason Gerfen notifications@github.com wrote:

Please ommit your modified bit and provide the errors provided from the test case.

— Reply to this email directly or view it on GitHub https://github.com/jas-/node-libnmap/issues/19#issuecomment-135470957.

jas- commented 9 years ago

Hmm, perhaps I wasn't clear in my last piece of correspondence.

Please provide the error your implementation produces while omitting the debugging content you provided.

In order to run the test case(s) a typical method is as such:

%> git clone https://github.com/jas-/node-libnmap.git
%> cd node-libnmap
%> npm test
bwerst commented 9 years ago

Hopefully this is what you are looking for after figuring out how to install make by installing cygwin64, etc....

Here's what I get:

C:\bwerst\projects\node-libnmap>npm test

node-libnmap@0.1.13 test C:\bwerst\projects\node-libnmap

make test

nmap

discovery method

  1) validate report

nmap

default method

  √ object description

  √ latest version

  √ usage url

  √ support url

  √ license url

  √ legal url (nmap)

nmap

scan method

  2) valid report

6 passing (754ms)

2 failing

1) nmap discovery method validate report:

 Uncaught Error: The nmap binary was not found. Install nmap

  at C:\bwerst\projects\node-libnmap\lib\node-libnmap.js:193:17

  at FSReqWrap.cb [as oncomplete] (fs.js:226:19)

2) nmap scan method valid report:

 Uncaught Error: The nmap binary was not found. Install nmap

  at C:\bwerst\projects\node-libnmap\lib\node-libnmap.js:193:17

  at FSReqWrap.cb [as oncomplete] (fs.js:226:19)

Makefile:5: recipe for target 'test' failed

make: *\ [test] Error 2

npm ERR! Test failed. See above for more details.

C:\bwerst\projects\node-libnmap>

nmap does execute from the command line because its in the PATH.

On Thu, Aug 27, 2015 at 3:24 PM, Jason Gerfen notifications@github.com wrote:

Hmm, perhaps I wasn't clear in my last piece of correspondence.

Please provide the error your implementation produces while omitting the debugging content you provided.

In order to run the test case(s) a typical method is as such:

%> git clone https://github.com/jas-/node-libnmap.git%> cd node-libnmap%> npm test

— Reply to this email directly or view it on GitHub https://github.com/jas-/node-libnmap/issues/19#issuecomment-135544362.

jas- commented 9 years ago

Can you examine this similar closed issue to see if specifying the full path to the nmap binary will resolve your problem?

jas- commented 9 years ago

@bwerst This should be resolved in v0.1.14

bwerst commented 9 years ago

Its working very well now. Thank you!

On Sat, Aug 29, 2015 at 3:35 PM, Jason Gerfen notifications@github.com wrote:

Closed #19 https://github.com/jas-/node-libnmap/issues/19.

— Reply to this email directly or view it on GitHub https://github.com/jas-/node-libnmap/issues/19#event-395857360.

jas- commented 9 years ago

@bwerst Good to hear, thanks for reporting this issue.