Skip to content

Commit

Permalink
Merge pull request #2 from tumi8/merge-zmap-upstream
Browse files Browse the repository at this point in the history
Merge zmap upstream
  • Loading branch information
sattler authored Jul 5, 2022
2 parents 6676d65 + dd4cff4 commit da0a0ca
Show file tree
Hide file tree
Showing 109 changed files with 1,856 additions and 2,418 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{c,h}]
indent_style = tab
indent_size = 8

[CMakeLists.txt]
indent_style = spaces
indent_size = 4

[*.py]
indent_style = spaces
indent_size = 4

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.*
!.clang-format
*.o
*.a
Expand All @@ -18,7 +17,7 @@ src/topt.h
src/ztopt.c
src/ztopt.h
src/*.ggo
src/zblacklist
src/zblocklist
src/ztee
src/ziterate
lexer.c
Expand Down
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

10 changes: 2 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
project(ZMAP C)
set(ZMAP_VERSION DEVELOPMENT) # Change DEVELOPMENT to version number for release

option(WITH_REDIS "Build with support for Redis DB" OFF)
option(ENABLE_DEVELOPMENT "Enable development specific compiler and linker flags" OFF)
option(ENABLE_LOG_TRACE "Enable log trace messages" OFF)
option(RESPECT_INSTALL_PREFIX_CONFIG "Respect CMAKE_INSTALL_PREFIX for /etc" OFF)
Expand Down Expand Up @@ -77,11 +76,6 @@ endif()
string(REPLACE ";" " " JSON_CFLAGS "${JSON_CFLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${JSON_CFLAGS}")

if(WITH_REDIS)
set(REDIS_LIBS hiredis)
add_definitions("-DREDIS")
endif()

if(WITH_PFRING)
add_definitions("-DPFRING")
set(PFRING_LIBRARIES pfring rt numa)
Expand Down Expand Up @@ -138,7 +132,7 @@ foreach(EACH_CONF ${CONF_FILES})
if(NOT EXISTS "/etc/zmap/${CONF_BASENAME}")
install(FILES ${EACH_CONF} DESTINATION ${CONFIG_DESTINATION})
elseif(FORCE_CONF_INSTALL)
message(WARNING "FORCE_CONF_INSTALL will overwrite any exsiting configuration files")
message(WARNING "FORCE_CONF_INSTALL will overwrite any existing configuration files")
install(FILES ${EACH_CONF} DESTINATION ${CONFIG_DESTINATION})
else()
message(WARNING "Existing configuration file detected at /etc/zmap/${CONF_BASENAME}, ${CONF_BASENAME} from sources will NOT be installed. Please check and install manually!")
Expand All @@ -152,7 +146,7 @@ set(CPACK_SET_DESTDIR "on")
set(CPACK_PACKAGING_INSTALL_PREFIX "/tmp")
set(CPACK_GENERATOR "DEB")

set(${VERSION} CPACK_DEBIAN_PACKAGE_VERSION)
set(CPACK_DEBIAN_PACKAGE_VERSION ${ZMAP_VERSION})
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "network")
set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from source.
Developing
----------

- ZMap code follows the [Linux kernel style guide][kernelguide]. We mantain [a
- ZMap code follows the [Linux kernel style guide][kernelguide]. We maintain [a
configuration file](/.clang-format) for `clang-format` that applies this
style. You can use the [format.sh](/format.sh) script to apply this style.

Expand Down
71 changes: 51 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,63 @@
#
# To build, beware of caching and:
#
# * If you wish to build current master
# * If you wish to build current main
#
# docker build -t zmap_ubuntu -f Dockerfile .
# docker build -t zmap .
#
# * If you wish to build a specific commit, use the ZMAP_COMMIT build argument.
# * If you wish to build a specific commit, git checkout to that specific commit before building
#
# docker build -t zmap_ubuntu -f Dockerfile --build-arg ZMAP_COMMIT=<your commit> .
# To run CI pre-built images, use:
#
# To run:
#
# docker run -it --rm --net=host zmap_ubuntu <zmap args>
# docker run -it --rm --net=host ghcr.io/zmap/zmap <zmap args>
####

FROM ubuntu:16.04
FROM ubuntu:20.04 as builder

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC

RUN apt-get update \
&& apt-get install -y \
build-essential \
cmake \
libgmp3-dev \
gengetopt \
libpcap-dev \
flex \
byacc \
libjson-c-dev \
pkg-config \
libunistring-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/local/src

COPY . .

RUN cd /usr/local/src \
&& mkdir -p /opt/zmap \
&& cmake . -DRESPECT_INSTALL_PREFIX_CONFIG=ON \
&& cmake --build . --parallel "$(nproc)" \
&& cmake --install . --prefix "/opt/zmap"

FROM ubuntu:20.04

LABEL org.opencontainers.image.source="https://github.com/tumi8/zmap"

RUN apt-get update \
&& apt-get install -y \
libpcap0.8 \
libjson-c4 \
libhiredis0.14 \
libgmp10 \
dumb-init \
&& rm -rf /var/lib/apt/lists/*

ARG ZMAP_COMMIT=master
ENV ZMAP_COMMIT ${ZMAP_COMMIT}
COPY --from=builder /opt/zmap /opt/zmap

RUN apt-get -qq update && apt-get -qqy upgrade
# install zmap build dependencies
RUN apt-get -qqy install build-essential cmake libgmp3-dev gengetopt libpcap-dev flex byacc libjson-c-dev pkg-config libunistring-dev wget unzip
# install zmap+Docker specific things, currently just dumb-init, which allows
# us to more easily send signals to zmap, for example by allowing ctrl-c of
# a running container and zmap will stop.
RUN apt-get -qqy install python-dev python-pip
RUN pip install dumb-init
RUN wget -q https://github.com/zmap/zmap/archive/${ZMAP_COMMIT}.zip && unzip -q ${ZMAP_COMMIT}.zip && cd zmap-${ZMAP_COMMIT} && (cmake . && make -j4 && make install) 2>&1 > /dev/null
ENV PATH="/opt/zmap/sbin:${PATH}"

ENTRYPOINT ["dumb-init", "/usr/local/sbin/zmap"]
# dumb-init allows us to more easily send signals to zmap,
# for example by allowing ctrl-c of a running container and zmap will stop.
ENTRYPOINT ["dumb-init", "/opt/zmap/sbin/zmap"]
15 changes: 6 additions & 9 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ ZMap has the following dependencies:
- [libunistring](https://www.gnu.org/software/libunistring/) - Unicode string library for C
- [libdnet](https://github.com/dugsong/libdnet) - (macOS Only) Gateway and route detection

In addition, the following optional packages enable optional ZMap functionality:

- [hiredis](https://github.com/redis/hiredis) - RedisDB support in C

Install the required dependencies with the following commands.

* On Debian-based systems (including Ubuntu):
Expand All @@ -49,6 +45,12 @@ Install the required dependencies with the following commands.
brew install pkg-config cmake gmp gengetopt json-c byacc libdnet libunistring
```

* To launch a shell inside a Docker container with the build dependencies
mounted at `/src`:
```sh
docker run -it -v $(pwd):/src zmap/builder
```

### Building and Installing ZMap

Once these prerequisites are installed, ZMap can be compiled by running:
Expand All @@ -67,11 +69,6 @@ Release builds should be built with `-DENABLE_DEVELOPMENT=OFF`.
- Enabling `log_trace` can have a major performance impact and should not be used
except during early development. Release builds should be built with `-DENABLE_LOG_TRACE=OFF`.

- Redis support is not enabled by default. If you want to use ZMap with Redis,
you will first need to install hiredis. Then run cmake with `-DWITH_REDIS=ON`.
Debian/Ubuntu has packaged hiredis as `libhiredis-dev`; Fedora and RHEL/CentOS
have packaged it as `hiredis-devel`.

- Building packages for some systems like Fedora and RHEL requires a user-definable
directory (buildroot) to put files. The way to respect this prefix is to run cmake
with `-DRESPECT_INSTALL_PREFIX_CONFIG=ON`.
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ZMap: The Internet Scanner
==========================

[![Build Status](https://travis-ci.org/zmap/zmap.svg?branch=travis-configuration)](https://travis-ci.org/zmap/zmap)
![Build Status](https://github.com/zmap/zmap/actions/workflows/cmake.yml/badge.svg)

ZMap is a fast single packet network scanner designed for Internet-wide network
surveys. On a typical desktop computer with a gigabit Ethernet connection, ZMap
Expand All @@ -13,14 +13,15 @@ ZMap operates on GNU/Linux, Mac OS, and BSD. ZMap currently has fully implemente
probe modules for TCP SYN scans, ICMP, DNS queries, UPnP, BACNET, and can send a
large number of [UDP probes](https://github.com/zmap/zmap/blob/master/examples/udp-probes/README).
If you are looking to do more involved scans, e.g.,
banner grab or TLS handshake, take a look at [ZGrab](https://github.com/zmap/zgrab),
banner grab or TLS handshake, take a look at [ZGrab 2](https://github.com/zmap/zgrab2),
ZMap's sister project that performs stateful application-layer handshakes.

Installation
------------

The latest stable release of ZMap is version 2.1.1 and supports Linux, macOS, and
BSD. We recommend installing ZMap from HEAD rather than using a distro package manager.
BSD. However, the release was tagged in 2015, and since then quite a bit has changed. Accordingly,
_we strongly encourage researchers to use [ZMap 3.0.0 Beta 1](https://github.com/zmap/zmap/releases/tag/v3.0.0-beta1)._

**Instructions on building ZMap from source** can be found in [INSTALL](INSTALL.md).

Expand Down
4 changes: 2 additions & 2 deletions examples/udp-probes/README
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ memcache_11211.pkt This probe triggers a response from memcached on UDP por
mssql_1434.pkt This probe triggers a response from Microsoft SQL Server discovery services on UDP port 1434
natpmp_5351.pkt This probe triggers a response from NATPMP-enabled devices on UDP port 5351
netbios_137.pkt This probe triggers a status reply from NetBIOS services on UDP port 137
ntp_123.pkt This probe triggers a response from NTP servies on UDP port 123
ntp_123_monlist.pkt This probe triggers a response for command "monlist" from NTP servies on UDP port 123
ntp_123.pkt This probe triggers a response from NTP services on UDP port 123
ntp_123_monlist.pkt This probe triggers a response for command "monlist" from NTP services on UDP port 123
pca_nq_5632.pkt This probe triggers a response from PC Anywhere services on UDP port 5632 (network query)
pca_st_5632.pkt This probe triggers a response from PC Anywhere services on UDP port 5632 (status)
portmap_111.pkt This probe triggers a response from SunRPC portmapper services on UDP port 111
Expand Down
Binary file added examples/udp-probes/ard_3283.pkt
Binary file not shown.
Binary file added examples/udp-probes/bacnet_47808.pkt
Binary file not shown.
Binary file added examples/udp-probes/db2_523.pkt
Binary file not shown.
Binary file added examples/udp-probes/nat_port_mapping_5351.pkt
Binary file not shown.
Binary file added examples/udp-probes/netis_53413.pkt
Binary file not shown.
Binary file added examples/udp-probes/openvpn_1194.pkt
Binary file not shown.
Binary file added examples/udp-probes/pcanywhere_5632.pkt
Binary file not shown.
Binary file modified examples/udp-probes/portmap_111.pkt
Binary file not shown.
Binary file added examples/udp-probes/rdp_3389.pkt
Binary file not shown.
Binary file added examples/udp-probes/ubiquiti_10001.pkt
Binary file not shown.
Binary file added examples/udp-probes/valve_27015.pkt
Binary file not shown.
4 changes: 0 additions & 4 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ SET(LIB_SOURCES
csv.c
)

if (WITH_REDIS)
SET(LIB_SOURCES ${LIB_SOURCES} redis.c)
endif()

add_library(zmaplib STATIC ${LIB_SOURCES})

target_include_directories (zmaplib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
16 changes: 16 additions & 0 deletions lib/blocklist.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdlib.h>
#include <stdint.h>

Expand Down
18 changes: 17 additions & 1 deletion lib/constraint.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -242,7 +258,7 @@ uint32_t constraint_lookup_index(constraint_t *con, uint64_t index,
// the number of addresses in a prefix at the current level of the tree.
// If paint is specified, each node will have its count set to the number of
// leaves under it set to value.
// If exclude_radix is specified, the number of addresses will exlcude prefixes
// If exclude_radix is specified, the number of addresses will exclude prefixes
// that are a /RADIX_LENGTH or larger
static uint64_t _count_ips_recurse(node_t *node, value_t value, uint64_t size,
int paint, int exclude_radix)
Expand Down
16 changes: 16 additions & 0 deletions lib/constraint.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CONSTRAINT_H
#define CONSTRAINT_H

Expand Down
16 changes: 16 additions & 0 deletions lib/csv.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "csv.h"

int csv_find_index(char *header, const char **names, size_t names_len)
Expand Down
16 changes: 16 additions & 0 deletions lib/csv.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2021 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef ZMAP_CSV_H
#define ZMAP_CSV_H

Expand Down
Loading

0 comments on commit da0a0ca

Please sign in to comment.