Skip to content

Commit b01cfb3

Browse files
authored
Merge pull request #5 from zakkg3/main
make networks configurable for zmap
2 parents 91e79c5 + 9bfc8ff commit b01cfb3

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
network_mode: "host"
88
environment:
99
PORTS: "80,443,22,21,25565,27017,143,6379"
10+
NETWORKS: "10.0.0.0/8 192.168.0.0/16"
1011
depends_on:
1112
rabbitmq:
1213
condition: service_healthy

rigour/common/common/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ def get_mongo_db(default: str = "rigour") -> str:
1414
def get_rabbitmq_uri(default: str = "amqp://localhost:5672/") -> str:
1515
return os.environ.get("RABBITMQ_URL", default)
1616

17+
@staticmethod
18+
def get_networks(default: str = "10.0.0.0/8") -> str:
19+
return os.environ.get("NETWORKS", default)
20+
21+
@staticmethod
22+
def get_ports(default: str = "80") -> str:
23+
return os.environ.get("PORTS", default)
24+
1725
@staticmethod
1826
def get_scan_collection() -> str:
1927
return "scans"

rigour/ports/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import asyncio
2-
import os
32
from dataclasses import asdict
43
from datetime import datetime
54

65
import geoip2.database
76
import geoip2.errors
87
from common import utils
8+
from common.config import Config
99
from common.database.mongodb import Database
1010
from common.queue.rabbitmq_asyncio import AsyncRabbitMQQueueManager
1111
from common.types import Host, HostMessage, Location
@@ -46,7 +46,8 @@ def main():
4646
db = Database()
4747
queue = AsyncRabbitMQQueueManager()
4848
reader = geoip2.database.Reader("geolite2-city.mmdb")
49-
ports = os.getenv("PORTS", "80")
49+
ports = Config.get_ports()
50+
networks = Config.get_networks()
5051

5152
logger.info(f"Starting port scanner for port/s: {ports}")
5253

@@ -60,7 +61,7 @@ async def callback(result: ZMapResult) -> None:
6061
await queue.publish(route_key, asdict(host))
6162
save(db, host)
6263

63-
command = ZMapCommand(ports)
64+
command = ZMapCommand(ports, networks)
6465
zmap = ZMap(command)
6566
loop = asyncio.get_event_loop()
6667
loop.run_until_complete(zmap.run(callback))

rigour/ports/zmap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55

66
class ZMapCommand:
7-
def __init__(self, ports: str):
7+
def __init__(self, ports: str, networks: str):
88
self.ports = ports
9+
self.networks = networks
910

1011
def build(self):
1112
return [
@@ -16,6 +17,7 @@ def build(self):
1617
"--quiet", # Suppress status updates
1718
"--rate=200", # Send 100 packets per second
1819
'--output-filter="success = 1"', # Filter successful results
20+
self.networks,
1921
]
2022

2123

0 commit comments

Comments
 (0)