Skip to content
jas-Public

About

node.js bindings for zmap network scanning tool

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

libzmap

Build & leverage zmap as a node.js module, no need to install a zmap binary.

npm CI Downloads

install

npm install libzmap

To install npm install libzmap

build tools

Example package requirements. The last line of each list is only necessary for an install from git.

Debian, Ubuntu (apt)
sudo apt-get install build-essential python3 pkg-config \
  libpcap-dev libjson-c-dev libgmp-dev libjudy-dev libunistring-dev \
  gengetopt flex byacc

Ubuntu 24.04 and Debian 12 package node.js 18; install node.js 22 or later from nodejs.org.

Fedora, RHEL, CentOS, Rocky, AlmaLinux (dnf)
sudo dnf install gcc gcc-c++ make python3 tar nodejs npm \
  libpcap-devel json-c-devel gmp-devel Judy-devel libunistring-devel \
  gengetopt flex byacc

On RHEL and its rebuilds, Judy-devel and gengetopt are in EPEL.

openSUSE (zypper)
sudo zypper install gcc gcc-c++ make python3 nodejs22 npm22 \
  libpcap-devel libjson-c-devel gmp-devel judy-devel libunistring-devel \
  gengetopt flex byacc
Arch Linux, Manjaro (pacman)
sudo pacman -S --needed base-devel python nodejs npm \
  libpcap json-c gmp judy libunistring \
  gengetopt flex byacc
Gentoo (emerge)
sudo emerge --ask net-libs/nodejs net-libs/libpcap dev-libs/json-c dev-libs/gmp \
  dev-libs/judy dev-libs/libunistring \
  dev-util/gengetopt sys-devel/flex dev-util/byacc
Alpine (apk)
sudo apk add build-base linux-headers python3 pkgconf nodejs npm \
  libpcap-dev json-c-dev gmp-dev judy-dev libunistring-dev \
  gengetopt flex byacc
macOS
xcode-select --install
brew install node json-c gmp judy libunistring pkgconf \
  gengetopt byacc

The Xcode command line tools supply the compiler, make, python3 and flex. macOS includes libpcap.

permissions

zmap sends raw packets, so a scan needs root (sudo node script.js). On Linux you can instead give node.js the capabilities one time:

sudo setcap cap_net_raw,cap_net_admin+ep "$(readlink -f "$(command -v node)")"

methods

  • zmap Runs a scan, zmap(opts, callback)
  • scan Runs a scan and returns it: .done (promise), events, for await and .stop()
  • isRunning True while a scan runs (one scan at a time in a process)

options

  • range {String|Array} Addresses or CIDR blocks to scan
  • ports {String} Ports to scan; without ports the scan is ICMP echo
  • iface {String} Network interface (default: the interface of the default route)
  • ipaddr {String} Source address(es), e.g. 10.0.2.15-10.0.2.18
  • mac {String} Gateway MAC address
  • whitelist {String} File of networks to scan
  • blacklist {String} File of networks to skip
  • shards {Number} With shardtotal, this scan is shard N of M (needs seed)
  • seed {Number} Seed of the address order, the same on each shard
  • threads {Number} Send threads
  • rate {Number} Packets per second (default 10000)
  • probeModule {String} icmp_echoscan, tcp_synscan, udp, dns, ...
  • dryrun {Boolean} Send no packets (needs no root)

Any other zmap option works in camelCase, e.g. maxRuntime, cooldownTime, outputFilter.

examples

More examples are in the examples/ folder.

JSON report

const zmap = require('libzmap');
const opts = {
  iface: 'eth0',
  ipaddr: '10.0.2.15-10.0.2.18',
  mac: '52:54:00:12:34:56',
  shards: 2,
  shardtotal: 4,
  seed: 1234,
  threads: 10,
  range: '10.0.2.0/24',
  blacklist: '/path/to/blacklist.conf',
  whitelist: '/path/to/whitelist.conf'
};

zmap.zmap(opts, function(err, report) {
  if (err) throw err;

  console.log(JSON.stringify(report, null, 2));
});

The report has hosts (each address that answered, with its ports), results (each answer, with zmap's fields) and metadata (zmap's scan settings and statistics).

Each result as it arrives:

for await (const result of zmap.scan(opts)) {
  console.log(JSON.stringify(result));
}

tests

To test npm test

license

This software is licensed under the Apache License 2.0, the same license as zmap.

Copyright Jason Gerfen, 2014.

About

node.js bindings for zmap network scanning tool

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages