libnmap 0.4.19 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -16
- package/README.md +98 -45
- package/binding.gyp +39 -0
- package/examples/accuracy.js +16 -12
- package/examples/default.js +8 -8
- package/examples/default2io.js +9 -17
- package/examples/discover.js +10 -8
- package/examples/fingerprint.js +30 -0
- package/examples/flags.js +10 -10
- package/examples/ipv6.js +9 -7
- package/examples/ports.js +11 -10
- package/examples/security-scripts.js +44 -0
- package/examples/timeout.js +10 -9
- package/examples/udp.js +12 -10
- package/examples/xml.js +9 -9
- package/index.js +2 -2
- package/lib/classes/networking.js +22 -163
- package/lib/classes/reporting.js +37 -31
- package/lib/classes/tools.js +110 -175
- package/lib/classes/validation.js +35 -156
- package/lib/classes/xml.js +192 -0
- package/lib/libnmap.js +28 -103
- package/lib/worker.js +24 -0
- package/package.json +32 -16
- package/scripts/build-nmap.js +110 -0
- package/scripts/fetch-sources.js +89 -0
- package/scripts/link.mk +13 -0
- package/src/addon.cc +101 -0
- package/.travis.yml +0 -21
- package/CHANGELOG +0 -3208
- package/CONTRIBUTING.md +0 -109
- package/_config.yml +0 -1
- package/examples/blocksize.js +0 -25
- package/examples/threshold.js +0 -22
- package/test/discover.js +0 -50
- package/test/scan.js +0 -50
package/LICENSE
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
libnmap
|
|
2
|
+
Copyright (c) 2013 Jason Gerfen
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
nmap
|
|
5
|
+
Copyright (c) 1996 - 2026 Nmap Software LLC
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
this
|
|
7
|
-
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
-
subject to the following conditions:
|
|
7
|
+
You can use, redistribute, and/or modify
|
|
8
|
+
this code under the terms of the Nmap Public Source License
|
|
9
|
+
version 0.95.
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
This program is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
Nmap Public Source License for more details.
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
16
|
+
The full text of the Nmap Public Source License is in the nmap
|
|
17
|
+
sources (src/nmap/LICENSE) and at <https://nmap.org/npsl/>.
|
package/README.md
CHANGED
|
@@ -1,46 +1,108 @@
|
|
|
1
|
-
# libnmap
|
|
1
|
+
# libnmap
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[](https://npmjs.com/package/libnmap) [](https://travis-ci.org/jas-/node-libnmap) [](https://david-dm.org/jas-/node-libnmap)  [](https://snyk.io/test/github/jas-/node-libnmap?targetFile=package.json)
|
|
3
|
+
Build & leverage [nmap](https://github.com/nmap/nmap) as a node.js module, no need to install an `nmap` binary.
|
|
6
4
|
|
|
5
|
+
[](https://npmjs.com/package/libnmap) [](https://github.com/jas-/node-libnmap/actions/workflows/ci.yml)  [](https://snyk.io/test/github/jas-/node-libnmap?targetFile=package.json)
|
|
7
6
|
|
|
8
7
|
## install ##
|
|
9
8
|
|
|
9
|
+

|
|
10
|
+
|
|
10
11
|
To install `npm install libnmap`
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
The install gets the nmap and OpenSSL sources and compiles them. See `build tools` for details.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
Some package managers (pnpm, yarn, bun, and npm with `ignore-scripts`) do not
|
|
16
|
+
run install scripts unless you allow them. If a scan gives the error "the nmap
|
|
17
|
+
module is not compiled", allow the install script of `libnmap` and run
|
|
18
|
+
`npm rebuild libnmap`.
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
### build tools ###
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
* `verbose` {Boolean} Turn on verbosity during scan(s)
|
|
21
|
-
* `ports` {String} Range of ports to scan
|
|
22
|
-
* `range` {Array} An array of hostnames/ipv4/ipv6, CIDR or ranges
|
|
23
|
-
* `timeout` {Number} Number of seconds to wait for host/port response
|
|
24
|
-
* `blocksize` {Number} Number of hosts per network scanning block
|
|
25
|
-
* `threshold` {Number} Max number of spawned process
|
|
26
|
-
* `flags` {Array} Array of flags for .spawn()
|
|
27
|
-
* `udp` {Boolean} UDP scan mode enabled
|
|
28
|
-
* `json` {Boolean} JSON object as output, false produces XML
|
|
22
|
+
Example package requirements.
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
<details>
|
|
25
|
+
<summary>Debian, Ubuntu (apt)</summary>
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
```sh
|
|
28
|
+
sudo apt-get install build-essential perl python3 nodejs npm
|
|
29
|
+
```
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
<details>
|
|
33
|
+
<summary>Fedora, RHEL, CentOS, Rocky, AlmaLinux (dnf)</summary>
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
sudo dnf install gcc gcc-c++ make perl python3 diffutils tar nodejs npm
|
|
37
|
+
```
|
|
38
|
+
</details>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary>openSUSE (zypper)</summary>
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
sudo zypper install gcc gcc-c++ make perl python3 nodejs npm
|
|
45
|
+
```
|
|
46
|
+
</details>
|
|
47
|
+
|
|
48
|
+
<details>
|
|
49
|
+
<summary>Arch Linux, Manjaro (pacman)</summary>
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
sudo pacman -S --needed base-devel perl python nodejs npm
|
|
53
|
+
```
|
|
54
|
+
</details>
|
|
55
|
+
|
|
56
|
+
<details>
|
|
57
|
+
<summary>Gentoo (emerge)</summary>
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
sudo emerge --ask dev-lang/perl dev-lang/python net-libs/nodejs
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The compiler and `make` are part of the base system.
|
|
64
|
+
</details>
|
|
65
|
+
|
|
66
|
+
<details>
|
|
67
|
+
<summary>Alpine (apk)</summary>
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
sudo apk add build-base linux-headers perl python3 nodejs npm
|
|
71
|
+
```
|
|
72
|
+
</details>
|
|
73
|
+
|
|
74
|
+
<details>
|
|
75
|
+
<summary>macOS</summary>
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
xcode-select --install
|
|
79
|
+
brew install node
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The Xcode command line tools supply the compiler, `make`, `perl` and `python3`.
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
## methods ##
|
|
86
|
+
|
|
87
|
+
* `scan` Scans the ports of each host in the range
|
|
88
|
+
* `discover` Finds the neighbors on the IPv4 network of each network interface
|
|
89
|
+
|
|
90
|
+
## options ##
|
|
91
|
+
|
|
92
|
+
* `range` {Array} Hostnames, IPv4/IPv6 addresses, CIDR or address ranges
|
|
93
|
+
* `ports` {String} Ports to scan (default `1-1024`)
|
|
94
|
+
* `timeout` {Number} Number of seconds to wait for each host (default `120`)
|
|
95
|
+
* `flags` {Array} More nmap flags (default `-T4`)
|
|
96
|
+
* `udp` {Boolean} Scan UDP ports (requires root)
|
|
97
|
+
* `json` {Boolean} JSON object as output (default), false produces XML
|
|
33
98
|
|
|
34
99
|
## examples ##
|
|
35
100
|
|
|
36
|
-
|
|
37
|
-
see [here](https://github.com/jas-/node-libnmap/tree/master/examples) or simply
|
|
38
|
-
look in the included `examples/` folder.
|
|
101
|
+
More examples are in the `examples/` folder.
|
|
39
102
|
|
|
40
103
|
### scan ###
|
|
41
104
|
|
|
42
|
-
|
|
43
|
-
default IANA range of reserved ports is scanned per host in each range (1024).
|
|
105
|
+

|
|
44
106
|
|
|
45
107
|
```javascript
|
|
46
108
|
const nmap = require('libnmap');
|
|
@@ -50,46 +112,37 @@ const opts = {
|
|
|
50
112
|
'10.0.2.0/25',
|
|
51
113
|
'192.168.10.80-120',
|
|
52
114
|
'fe80::42:acff:fe11:fd4e/64'
|
|
53
|
-
]
|
|
115
|
+
],
|
|
116
|
+
ports: '22,80,443'
|
|
54
117
|
};
|
|
55
118
|
|
|
56
119
|
nmap.scan(opts, function(err, report) {
|
|
57
|
-
if (err) throw
|
|
120
|
+
if (err) throw err;
|
|
58
121
|
|
|
59
|
-
|
|
60
|
-
console.log(JSON.stringify(report[item]));
|
|
61
|
-
}
|
|
122
|
+
console.log(JSON.stringify(report, null, 2));
|
|
62
123
|
});
|
|
63
124
|
```
|
|
64
125
|
|
|
65
126
|
### discover ###
|
|
66
127
|
|
|
67
|
-
|
|
68
|
-
information about neighbors per network interface.
|
|
128
|
+

|
|
69
129
|
|
|
70
130
|
```javascript
|
|
71
131
|
const nmap = require('libnmap');
|
|
72
132
|
|
|
73
133
|
nmap.discover(function(err, report) {
|
|
74
|
-
if (err) throw
|
|
134
|
+
if (err) throw err;
|
|
75
135
|
|
|
76
|
-
|
|
77
|
-
console.log(JSON.stringify(report[item]));
|
|
78
|
-
}
|
|
136
|
+
console.log(JSON.stringify(report, null, 2));
|
|
79
137
|
});
|
|
80
138
|
```
|
|
81
139
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
To see some output examples please take a look at the [json (default) & xml reports](https://gist.github.com/jas-/23e2a32110562388bef5).
|
|
85
|
-
|
|
86
|
-
## contributing ##
|
|
140
|
+
## tests ##
|
|
87
141
|
|
|
88
|
-
|
|
89
|
-
to help facilitate pull requests.
|
|
142
|
+
To test `npm test`
|
|
90
143
|
|
|
91
144
|
## license ##
|
|
92
145
|
|
|
93
|
-
This software is licensed under the [
|
|
146
|
+
This software is licensed under the [Nmap Public Source License](https://nmap.org/npsl/), the same license as nmap. See [LICENSE](https://github.com/jas-/node-libnmap/blob/master/LICENSE).
|
|
94
147
|
|
|
95
|
-
Copyright Jason Gerfen, 2013
|
|
148
|
+
Copyright Jason Gerfen, 2013.
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"variables": {
|
|
3
|
+
"nmap_src": "src/nmap"
|
|
4
|
+
},
|
|
5
|
+
"target_defaults": {
|
|
6
|
+
"xcode_settings": { "MACOSX_DEPLOYMENT_TARGET": "11.0" }
|
|
7
|
+
},
|
|
8
|
+
"targets": [
|
|
9
|
+
{
|
|
10
|
+
"target_name": "nmap",
|
|
11
|
+
"sources": [ "src/addon.cc" ],
|
|
12
|
+
"include_dirs": [
|
|
13
|
+
"<(nmap_src)",
|
|
14
|
+
"<(nmap_src)/nbase",
|
|
15
|
+
"<(nmap_src)/nsock/include",
|
|
16
|
+
"<(nmap_src)/libdnet-stripped/include",
|
|
17
|
+
"<(nmap_src)/libpcap",
|
|
18
|
+
"<(nmap_src)/liblua",
|
|
19
|
+
"<(nmap_src)/liblinear",
|
|
20
|
+
"<(nmap_src)/libz",
|
|
21
|
+
"<(nmap_src)/libpcre/src"
|
|
22
|
+
],
|
|
23
|
+
"defines": [ "HAVE_CONFIG_H" ],
|
|
24
|
+
# Unmodified upstream nmap: scripts/build-nmap.js compiles it and prints the link inputs.
|
|
25
|
+
"libraries": [ "<!@(node scripts/build-nmap.js)" ],
|
|
26
|
+
"cflags_cc": [ "-fvisibility=hidden", "-w" ],
|
|
27
|
+
"xcode_settings": {
|
|
28
|
+
"OTHER_CPLUSPLUSFLAGS": [ "-w" ],
|
|
29
|
+
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES"
|
|
30
|
+
},
|
|
31
|
+
"conditions": [
|
|
32
|
+
# The module must use its own zlib and Lua, not the symbols that the node binary exports.
|
|
33
|
+
[ "OS=='linux'", {
|
|
34
|
+
"ldflags": [ "-Wl,-Bsymbolic", "-Wl,--exclude-libs,ALL" ]
|
|
35
|
+
}]
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
package/examples/accuracy.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// A slow scan for hosts that are far away, limit the rate of answers, or
|
|
10
|
+
// are behind an intrusion detection system. The scan of each port takes
|
|
11
|
+
// 10 seconds or more, so keep the list of ports and the range short.
|
|
12
|
+
|
|
9
13
|
const nmap = require('../');
|
|
10
14
|
const opts = {
|
|
11
|
-
timeout: 900, // 900s = 15m
|
|
15
|
+
timeout: 900, // 900s = 15m for each host
|
|
16
|
+
ports: '22,80,443',
|
|
12
17
|
flags: [
|
|
13
|
-
'-
|
|
18
|
+
'-T2', // Polite timing; slower than the default (-T4)
|
|
14
19
|
'--max-retries 10', // Don't give up on slow responding hosts
|
|
15
|
-
'--
|
|
20
|
+
'--max-rtt-timeout 2s', // Wait longer for the answer on slow connections
|
|
16
21
|
'--scan-delay 10s', // Account for host 'rate limiting'
|
|
17
|
-
'--max-rate 30', //
|
|
22
|
+
'--max-rate 30', // Send no more than 30 packets each second
|
|
18
23
|
],
|
|
19
|
-
range: ['scanme.nmap.org'
|
|
24
|
+
range: ['scanme.nmap.org'],
|
|
20
25
|
};
|
|
21
26
|
|
|
22
|
-
nmap.scan(opts, function(err, report) {
|
|
23
|
-
if (err) throw new Error(err);
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
nmap.scan(opts, (err, report) => {
|
|
29
|
+
if (err) throw err;
|
|
30
|
+
|
|
31
|
+
console.log(JSON.stringify(report, null, 2));
|
|
28
32
|
});
|
package/examples/default.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// The default scan: TCP ports 1-1024 of each host in the range.
|
|
10
|
+
// The range accepts hostnames, addresses, CIDR and address ranges.
|
|
11
|
+
|
|
9
12
|
const nmap = require('../');
|
|
10
13
|
const opts = {
|
|
11
|
-
range: ['scanme.nmap.org'
|
|
14
|
+
range: ['scanme.nmap.org']
|
|
12
15
|
};
|
|
13
16
|
|
|
14
17
|
|
|
15
|
-
nmap.scan(opts,
|
|
18
|
+
nmap.scan(opts, (err, report) => {
|
|
16
19
|
if (err) throw new Error(err);
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
console.log(JSON.stringify(report[item], null, 2));
|
|
20
|
-
}
|
|
21
|
+
console.log(JSON.stringify(report, null, 2));
|
|
21
22
|
});
|
|
22
|
-
|
package/examples/default2io.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// Writes the report of one scan to a file.
|
|
10
|
+
|
|
10
11
|
const fs = require('fs');
|
|
11
|
-
const
|
|
12
|
+
const nmap = require('../');
|
|
12
13
|
const opts = {
|
|
13
|
-
range: ['scanme.nmap.org'
|
|
14
|
+
range: ['scanme.nmap.org'],
|
|
14
15
|
ports: '21,22,80,443'
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
nmap.scan(opts,
|
|
19
|
-
if (err) throw
|
|
20
|
-
|
|
21
|
-
for (let item in report) {
|
|
22
|
-
let data = JSON.stringify(report[item], null, 2),
|
|
23
|
-
filename = item.replace(' ', '-');
|
|
24
|
-
|
|
25
|
-
fs.writeFile(path+filename+'.json', data, function(error) {
|
|
26
|
-
if (error) return console.log(error);
|
|
19
|
+
nmap.scan(opts, (err, report) => {
|
|
20
|
+
if (err) throw err;
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
}
|
|
22
|
+
fs.writeFileSync('report.json', JSON.stringify(report, null, 2));
|
|
31
23
|
});
|
package/examples/discover.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// Finds the neighbors on the IPv4 network of each network interface.
|
|
10
|
+
// As root, nmap uses ARP requests, which also give the MAC address.
|
|
11
|
+
|
|
9
12
|
const nmap = require('../');
|
|
10
13
|
|
|
11
|
-
nmap.discover({verbose: true}, function(err, report) {
|
|
12
|
-
if (err) throw new Error(err);
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
nmap.discover((err, report) => {
|
|
16
|
+
if (err) throw err;
|
|
17
|
+
|
|
18
|
+
console.log(JSON.stringify(report, null, 2));
|
|
19
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* libnmap
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict'
|
|
8
|
+
|
|
9
|
+
// Identifies the operating system of each host and the software behind
|
|
10
|
+
// each open port. OS detection requires root privileges, and is most
|
|
11
|
+
// accurate when the host has one open and one closed port.
|
|
12
|
+
|
|
13
|
+
const nmap = require('../');
|
|
14
|
+
const opts = {
|
|
15
|
+
timeout: 300,
|
|
16
|
+
flags: [
|
|
17
|
+
'-O', // OS detection from the TCP/IP stack of the host
|
|
18
|
+
'--osscan-guess', // Give the nearest matches if no match is exact
|
|
19
|
+
'-sV', // Software name and version of each open port
|
|
20
|
+
'--version-intensity 7' // 0 (fast) to 9 (try each probe); default is 7
|
|
21
|
+
],
|
|
22
|
+
range: ['scanme.nmap.org']
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
nmap.scan(opts, (err, report) => {
|
|
27
|
+
if (err) throw err;
|
|
28
|
+
|
|
29
|
+
console.log(JSON.stringify(report, null, 2));
|
|
30
|
+
});
|
package/examples/flags.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// More nmap flags for a scan. A flag can include its value.
|
|
10
|
+
|
|
9
11
|
const nmap = require('../');
|
|
10
12
|
const opts = {
|
|
11
13
|
flags: [
|
|
12
14
|
'-sV', // Open port to determine service (i.e. FTP, SSH etc)
|
|
13
15
|
'-O', // OS finger printing (requires elevated privileges)
|
|
14
|
-
'-sC', // Enables the nmap scripts
|
|
15
|
-
'--traceroute', // Turns on tracerouting
|
|
16
|
+
'-sC', // Enables the default nmap scripts against each host
|
|
17
|
+
'--traceroute', // Turns on tracerouting (requires elevated privileges)
|
|
16
18
|
'--script traceroute-geolocation' // Turns on GeoIP functionality per hops
|
|
17
19
|
],
|
|
18
|
-
range: ['scanme.nmap.org'
|
|
20
|
+
range: ['scanme.nmap.org']
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
|
|
22
|
-
nmap.scan(opts,
|
|
24
|
+
nmap.scan(opts, (err, report) => {
|
|
23
25
|
if (err) throw err;
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
});
|
|
27
|
+
console.log(JSON.stringify(report, null, 2));
|
|
28
|
+
});
|
package/examples/ipv6.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// Scans IPv4 and IPv6 hosts. nmap scans one address family for each run,
|
|
10
|
+
// so this range starts two runs at the same time. The one report has the
|
|
11
|
+
// hosts of the two runs.
|
|
12
|
+
|
|
9
13
|
const nmap = require('../');
|
|
10
14
|
const opts = {
|
|
11
15
|
range: ['scanme.nmap.org', '2001:db8::/128']
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
|
|
15
|
-
nmap.scan(opts,
|
|
16
|
-
if (err) throw
|
|
19
|
+
nmap.scan(opts, (err, report) => {
|
|
20
|
+
if (err) throw err;
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
console.log(JSON.stringify(report[item], null, 2));
|
|
20
|
-
}
|
|
22
|
+
console.log(JSON.stringify(report, null, 2));
|
|
21
23
|
});
|
package/examples/ports.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// Scans a list of ports.
|
|
10
|
+
// Examples: '512' (single), '1-65535' (range), '10-30,80,443' (multiple)
|
|
11
|
+
|
|
9
12
|
const nmap = require('../');
|
|
10
13
|
const opts = {
|
|
11
|
-
ports: '
|
|
12
|
-
range: ['scanme.nmap.org'
|
|
14
|
+
ports: '21-25,80,443,8000-8100',
|
|
15
|
+
range: ['scanme.nmap.org']
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
|
|
16
|
-
nmap.scan(opts,
|
|
17
|
-
if (err) throw
|
|
19
|
+
nmap.scan(opts, (err, report) => {
|
|
20
|
+
if (err) throw err;
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
});
|
|
22
|
+
console.log(JSON.stringify(report, null, 2));
|
|
23
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* libnmap
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict'
|
|
8
|
+
|
|
9
|
+
// Runs scripts of the Nmap Scripting Engine (NSE) against each host.
|
|
10
|
+
// nmap includes more than 600 scripts, in categories such as:
|
|
11
|
+
//
|
|
12
|
+
// default scripts that are fast, reliable and useful for most scans
|
|
13
|
+
// safe scripts that do not attack or put load on the host
|
|
14
|
+
// discovery scripts that find more data about the network
|
|
15
|
+
// vuln scripts that examine the host for known vulnerabilities
|
|
16
|
+
// auth scripts that examine authentication (anonymous access...)
|
|
17
|
+
// intrusive scripts that can stop a service or look like an attack
|
|
18
|
+
// brute, dos, exploit attacks; use only with written permission
|
|
19
|
+
//
|
|
20
|
+
// The --script value accepts script names, categories and expressions.
|
|
21
|
+
// This example selects the vulnerability and authentication scripts that
|
|
22
|
+
// are also in the safe category, with the default scripts.
|
|
23
|
+
//
|
|
24
|
+
// Only scan hosts that you own or have permission to scan.
|
|
25
|
+
|
|
26
|
+
const nmap = require('../');
|
|
27
|
+
const opts = {
|
|
28
|
+
timeout: 600,
|
|
29
|
+
ports: '21-25,53,80,110,143,443,445,3306,3389,5432,8080',
|
|
30
|
+
flags: [
|
|
31
|
+
'-sV', // Many scripts start only for a service that nmap identified
|
|
32
|
+
|
|
33
|
+
// The value is its own entry, so the spaces stay in one argument
|
|
34
|
+
'--script', 'default or ((vuln or auth) and safe)'
|
|
35
|
+
],
|
|
36
|
+
range: ['scanme.nmap.org']
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
nmap.scan(opts, (err, report) => {
|
|
41
|
+
if (err) throw err;
|
|
42
|
+
|
|
43
|
+
console.log(JSON.stringify(report, null, 2));
|
|
44
|
+
});
|
package/examples/timeout.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// The timeout is the number of seconds that nmap gives to each host
|
|
10
|
+
// (the nmap --host-timeout option). The default is 120 seconds.
|
|
11
|
+
|
|
9
12
|
const nmap = require('../');
|
|
10
13
|
const opts = {
|
|
11
14
|
timeout: 900, // 900s = 15m and increases the reliability of scan results
|
|
12
|
-
range: ['scanme.nmap.org'
|
|
15
|
+
range: ['scanme.nmap.org']
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
|
|
16
|
-
nmap.scan(opts,
|
|
17
|
-
if (err) throw
|
|
19
|
+
nmap.scan(opts, (err, report) => {
|
|
20
|
+
if (err) throw err;
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
});
|
|
22
|
+
console.log(JSON.stringify(report, null, 2));
|
|
23
|
+
});
|
package/examples/udp.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* libnmap
|
|
3
|
-
* Copyright(c) 2013
|
|
4
|
-
* License:
|
|
3
|
+
* Copyright(c) 2013 Jason Gerfen <jason.gerfen@gmail.com>
|
|
4
|
+
* License: NPSL-0.95
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
'use strict'
|
|
8
8
|
|
|
9
|
+
// Scans UDP ports (the nmap -sU option). A UDP scan requires root
|
|
10
|
+
// privileges, and is slow: a closed port can limit the rate of the answers.
|
|
11
|
+
|
|
9
12
|
const nmap = require('../');
|
|
10
13
|
const opts = {
|
|
11
|
-
udp: true,
|
|
12
|
-
|
|
14
|
+
udp: true,
|
|
15
|
+
ports: '53,67,123,161',
|
|
16
|
+
range: ['scanme.nmap.org']
|
|
13
17
|
};
|
|
14
18
|
|
|
15
19
|
|
|
16
|
-
nmap.scan(opts,
|
|
17
|
-
if (err) throw
|
|
20
|
+
nmap.scan(opts, (err, report) => {
|
|
21
|
+
if (err) throw err;
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
+
console.log(JSON.stringify(report, null, 2));
|
|
24
|
+
});
|