This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/multipart-download
- Loading branch information
Showing
8 changed files
with
168 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"id": "nmap-ip-range", | ||
"name": "Nmap IP range", | ||
"description": "Scan an IP range and store found IPs.", | ||
"consumes": [ | ||
"NetBlock" | ||
], | ||
"produces": [ | ||
"IPAddressV6", | ||
"Service", | ||
"IPPort", | ||
"IPAddressV4", | ||
"IPService" | ||
], | ||
"environment_keys": [ | ||
"TOP_PORTS_TCP", | ||
"TOP_PORTS_UDP" | ||
], | ||
"scan_level": 2 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Nmap IP-range | ||
|
||
This boefje checks an IP range/NetBlock and stores any IP addresses that seem to be active. | ||
|
||
### Options | ||
|
||
This Nmap boefje has the following hardcoded options: | ||
|
||
| Option | Function | | ||
| ----------- | ----------- | | ||
| `T4` | assume a fast and reliable network | | ||
| `Pn` | skips host discovery, treats hosts as online | | ||
|`-r` | scan ports in order | | ||
|`-v10` |use verbosity level 10 | | ||
|`-oX` |Output in XML | | ||
|
||
For TCP `-sS` is used, for UDP `-sU` is used. Both have their own TOP_PORTS argument. | ||
|
||
### Input OOIs | ||
|
||
Nmap expects an NetBlock as input. | ||
|
||
### Output OOIs | ||
|
||
Nmap outputs the following OOIs: | ||
|
||
|OOI type|Description| | ||
|---|---| | ||
|IPAddressV4 | IPv4 | | ||
|IPAddressV6 | IPv6 | | ||
|IpPort|Open ports of IpAddress| | ||
|Service|Services that are found| | ||
|IpService|IpService that couples a service to an open port| | ||
|
||
The boefje uses the same normalizer and structure as the generic `kat_nmap` boefje. | ||
|
||
**Cat name**: Elsje (inverted, mirrored) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from os import getenv | ||
from ipaddress import ip_network, IPv6Network | ||
from typing import List, Tuple, Union | ||
|
||
import docker | ||
from boefjes.job_models import BoefjeMeta | ||
|
||
NMAP_IMAGE = "instrumentisto/nmap:latest" | ||
TOP_PORTS_MAX = 65535 | ||
TOP_PORTS_DEFAULT = 250 | ||
TOP_PORTS_MIN = 1 | ||
|
||
|
||
def run_nmap(args: List[str]) -> str: | ||
"""Run Nmap in Docker.""" | ||
client = docker.from_env() | ||
return client.containers.run(NMAP_IMAGE, args, remove=True).decode() | ||
|
||
|
||
def build_nmap_arguments(ip_range: str, top_ports: int, protocol_str: str) -> List[str]: | ||
"""Build nmap arguments from the hosts IP with the required ports.""" | ||
if protocol_str not in ["S", "U"]: | ||
raise ValueError('Protocol should be "S" or "U"') | ||
if not TOP_PORTS_MIN <= top_ports <= TOP_PORTS_MAX: | ||
raise ValueError(f"{TOP_PORTS_MIN} <= TOP_PORTS: {top_ports} <= {TOP_PORTS_MAX} is invalid.") | ||
|
||
args = ["nmap", "-T4", "-Pn", "-r", "-v10", f"-s{protocol_str}", "--top-ports", str(top_ports)] | ||
if isinstance(ip_network(ip_range), IPv6Network): | ||
args.append("-6") | ||
args.extend(["-oX", "-", ip_range]) | ||
|
||
return args | ||
|
||
|
||
def run(boefje_meta: BoefjeMeta) -> List[Tuple[set, Union[bytes, str]]]: | ||
"""Build Nmap arguments and return results to normalizer.""" | ||
ip_range = f"{boefje_meta.arguments['input']['start_ip']['address']}/{str(boefje_meta.arguments['input']['mask'])}" | ||
top_ports_tcp = int(getenv("TOP_PORTS_TCP", 250)) | ||
top_ports_udp = int(getenv("TOP_PORTS_UDP", 10)) | ||
if not top_ports_tcp and not top_ports_udp: | ||
raise ValueError("At least one TOP_PORTS argument should be non-zero") | ||
|
||
results = [] | ||
if top_ports_tcp: | ||
results.append(run_nmap(build_nmap_arguments(ip_range=ip_range, top_ports=top_ports_tcp, protocol_str="S"))) | ||
if top_ports_udp: | ||
results.append(run_nmap(build_nmap_arguments(ip_range=ip_range, top_ports=top_ports_udp, protocol_str="U"))) | ||
|
||
return [(set(), "\n\n".join(results))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"title": "Arguments", | ||
"type": "object", | ||
"properties": { | ||
"TOP_PORTS_TCP": { | ||
"title": "TOP_PORTS_TCP", | ||
"type": "integer", | ||
"description": "Scan TOP_PORTS most common TCP ports. Defaults to 250." | ||
}, | ||
"TOP_PORTS_UDP": { | ||
"title": "TOP_PORTS_UDP", | ||
"type": "integer", | ||
"description": "Scan TOP_PORTS most common UDP ports. Defaults to 10." | ||
} | ||
}, | ||
"required": [] | ||
} |