Package: divideandscan
Divide Et Impera And Scan (and also merge the scan results)DivideAndScan is used to efficiently automate port scanning routine by splitting it into 3 phases:Discover open ports for a bunch of targets.Run Nmap individually for each target with version grabbing and NSE actions.Merge the results into a single Nmap report (different formats available).For the 1st phase afast port scanner* is intended to be used, whose output is parsed and stored in a single file database (TinyDB). Next, during the 2nd phase individual Nmap scans are launched for each target with its set of open ports (multiprocessing is supported) according to the database data. Finally, in the 3rd phase separate Nmap outputs are merged into a single report in different formats (XML / HTML / simple text / grepable) withnMap_Merger. The visualization portion is provided byDrawNmap.Potential use cases:Pentest engagements / red teaming with a large scope to enumerate.Cybersecurity wargames / training CTF labs.OSCP certification exam.* Available port scanners:NmapMasscanRustScanNaabuNimScansxDISCLAIMER.All information contained in this repository is provided for educational and research purposes only. The author is not responsible for any illegal use of this tool.How It WorksHow to InstallPrerequisitesTo successfullydivide and scanwe need to get some good port scanning tools (in the examples below GitHub releases are grabbed viaeget).📑Note:if you don't feel like messing with dependecies on your host OS, skip to theDockerpart.Nmapsudoaptinstallnmapxsltproc-y
sudonmap--script-updatedbMasscanpushd/tmp
wgethttps://github.com/ivre/masscan/archive/refs/heads/master.zip-Omasscan-master.zip
unzipmasscan-master.zipcdmasscan-master
make
sudomakeinstallpopd&&rm-rf/tmp/masscan-master*RustScaneget-t2.0.1-aamd64RustScan/RustScan--to/tmp/rustscan.deb
sudodpkg-i/tmp/rustscan.deb&&rm/tmp/rustscan.deb
sudowgethttps://gist.github.com/snovvcrash/8b85b900bd928493cd1ae33b2df318d8/raw/fe8628396616c4bf7a3e25f2c9d1acc2f36af0c0/rustscan-ports-top1000.toml-O/root/.rustscan.tomlNaabusudomkdir/opt/naabu
sudoeget-slinux/amd64projectdiscovery/naabu--to/opt/naabu
sudoln-sv/opt/naabu/naabu/usr/local/bin/naabuNimScansudomkdir/opt/nimscan
sudoeget-aNimScanelddy/NimScan--to/opt/nimscan
sudoln-sv/opt/nimscan/nimscan/usr/local/bin/nimscansxsudomkdir/opt/sx
sudoeget-slinux/amd64v-byte-cpu/sx--to/opt/sx
sudoln-sv/opt/sx/sx/usr/local/bin/sxdnsxsudomkdir/opt/pd
sudoeget-slinux/amd64projectdiscovery/dnsx--to/opt/pd
sudoln-sv/opt/pd/dnsx/usr/local/bin/dnsxInstallationDivideAndScan is available on PyPI asdivideandscan, though I recommend installing it from GitHub withpipxin order to always have the bleeding-edge version:~$ pipx install -f "git+https://github.com/snovvcrash/DivideAndScan.git"~$ dasThere's also areleasepacked withshiv(large file size though):#shiv-edas.divideandscan:main-odas.pyzdivideandscan~$ wget https://github.com/snovvcrash/DivideAndScan/releases/latest/download/das.pyz && chmod +x das.pyz~$ ./das.pyzFor debbugging purposes you can set up a dev environment withpoetry:~$ git clone --recurse-submodules https://github.com/snovvcrash/DivideAndScan~$ cd DivideAndScan~$ poetry install~$ poetry run das📑Note:DivideAndScan uses sudo to run all the port scanners, so it will ask for the password when scanning commands are invoked.Using from DockerYou can run DivideAndScan in a Docker container as follows:~$ docker run --rm -it --name das -v ~/.das:/root/.das -v `pwd`:/app -p 8050:8050 snovvcrash/divideandscanSince the tool requires some input data and produces some output data, you should specify your current working directory as the mount point at/appwithin the container. Also publishing port 8050 on host allows to access theDashapp used for Nmap reports visualization.You may want to set an alias to make the base command shorter:~$ alias das='docker run --rm -it --name das -v ~/.das:/root/.das -v `pwd`:/app -p 8050:8050 snovvcrash/divideandscan'~$ dasHow to Use1. Filling the DBProvide theaddmodule a command for a fast port scanner to discover open ports in a desired range.⚠️Warning:please, make sure that you understand what you're doing, because nearly all port scanning toolscan damage the system being testedif used improperly.#Nmap,-vflagisalwaysrequiredforcorrectparsing!~$ das add nmap '-v -n -Pn -e eth0 --min-rate 1000 -T4 -iL hosts.txt -p1-65535 --open'#Masscan~$ das add masscan '--rate 1000 -iL hosts.txt -p1-65535 --open'#RustScan~$ das add rustscan '-b 1000 -t 2000 -u 5000 -a hosts.txt -r 1-65535 -g --no-config'#Naabu~$ das add naabu '-rate 1000 -iL hosts.txt -p - -silent -s s'#NimScan~$ das add nimscan '192.168.1.0/24 -vi -p:1-65535 -f:500'#sx~$ sudo sx arp -i eth0 192.168.1.0/24 --json | tee arp.cache~$ das add sx 'tcp syn -a arp.cache -i eth0 --rate 1000/s 192.168.1.0/24 -p 445,3389'When the module starts its work, a directory~/.das/dbis created where the database file and raw scan results will be put when the module routine finishes.2. Targeted ScanningLaunch targeted Nmap scans with thescanmodule. You can adjust the scan surface with either-hostsor-portsoption:#Scanbyhosts~$ das scan -hosts all -oA report1~$ das scan -hosts 192.168.1.0/24,10.10.13.37 -oA report1~$ das scan -hosts hosts.txt -oA report1#Scanbyports~$ das scan -ports all -oA report2~$ das scan -ports 22,80,443,445 -oA report2~$ das scan -ports ports.txt -oA report2To start Nmap simultaneously in multiple processes, specify the-parallelswitch and set number of workers with the-procoption (if no value is provided, it will default to the number of processors on the machine):~$ das scan -hosts all -oA report -parallel [-proc 4]The output format is selected with-oX,-oN,-oGand-oAoptions for XML+HTML formats, simple text format, grepable format and all formats respectively. When the module completes its work, a directory~/.das/nmap_<DB_NAME>is created containig Nmap raw scan reports.Also, you can inspect the contents of the database with-showoption before actually launching the scans:~$ das scan -hosts all -show3 (Optional). Merging the ReportsIn order to generate a report independently of thescanmodule, you should use thereportmodule. It will search for Nmap raw scan reports in the~/.das/nmap_<DB_NAME>directory and process and merge them based on either-hostsor-portsoption:#Mergeoutputsbyhosts~$ das report -hosts all -oA report1~$ das report -hosts 192.168.1.0/24,10.10.13.37 -oA report1~$ das report -hosts hosts.txt -oA report1#Mergeoutputsbyports~$ das report -ports all -oA report2~$ das report -ports 22,80,443,445 -oA report2~$ das report -ports ports.txt -oA report2📑Note:keep in mind that thereportmodule doesnotsearch the DB when processing the-hostsor-portsoptions, but looks for Nmap raw reports directly in~/.das/nmap_<DB_NAME>directory instead; it means that-hosts 127.0.0.1argument value will be successfully resolved only if~/.das/nmap_<DB_NAME>/127-0-0-1.*files exist, and-ports 80argument value will be successfully resolved only if~/.das/nmap_<DB_NAME>/port80.*files exist.🔥 Example 🔥Let's enumerate open ports for all live machines onHack The Box.Add mappings "host ⇄ open ports" to the database with Masscan. For demonstration purposes I will exclude dynamic port range to avoid unnecessary stuff by using-p1-49151. On the second screenshot I'm reviewing scan results by hosts and by ports:~$ das -db htb add -rm masscan '-e tun0 --rate 1000 -iL hosts.txt -p1-49151 --open'~$ das -db htb scan -hosts all -show~$ das -db htb scan -ports all -showLaunch Nmap processes for each target to enumerate only ports that we're interested in (the open ports). On the second screenshot I'm doing the same but starting Nmap processes simultaneously:~$ das -db htb scan -hosts all -oA report~$ das -db htb scan -hosts all -oA report -nmap '-Pn -sVC -O' -parallelAs a result we now have a single report in all familiar Nmap formats (simple text, grepable, XML) as well as a pretty HTML report.Bring Your Own Scanner!You can pair your favourite port scanner with DivideAndScan by implementing a singleparsemethod for its output indas/parsers/DUMMY_SCANNER.py(seeexamplefor masscan):fromdas.parsersimportIAddPortscanOutputclassAddPortscanOutput(IAddPortscanOutput):"""Child class for processing DUMMY_SCANNER output."""defparse(self):"""DUMMY_SCANNER raw output parser.:return: a pair of values (portscan raw output filename, number of hosts added to DB):rtype: tuple"""hosts=set()forlineinself.portscan_raw:# DUMMY_SCANNER parser implementationpassreturn(self.portscan_out,len(hosts))Helpusage: das [-h] [-db DB] {db,add,scan,dns,report,parse,draw,tree,help} ...

 -----------------------------------------------------------------------------------------------
|  ________  .__      .__    .___        _____              .____________                       |
|  \______ \ |__|__  _|__| __| _/____   /  _  \   ____    __| _/   _____/ ____ _____    ____    |
|   |    |  \|  \  \/ /  |/ __ |/ __ \ /  /_\  \ /    \  / __ |\_____  \_/ ___\\__  \  /    \   |
|   |    `   \  |\   /|  / /_/ \  ___//    |    \   |  \/ /_/ |/        \  \___ / __ \|   |  \  |
|  /_______  /__| \_/ |__\____ |\___  >____|__  /___|  /\____ /_______  /\___  >____  /___|  /  |
|          \/                 \/    \/        \/     \/      \/       \/     \/     \/     \/   |
|  {@snovvcrash}            {https://github.com/snovvcrash/DivideAndScan}             {vX.Y.Z}  |
 -----------------------------------------------------------------------------------------------

positional arguments:
  {db,add,scan,dns,report,parse,draw,tree,help}
    db                  utilities for manual DB manipulations
    add                 run a full port scan and add the output to DB
    scan                run targeted Nmap scans against hosts and ports from DB
    dns                 map domain names from an input file to corresponding IP addresses from the DB
    report              merge separate Nmap outputs into a single report (https://github.com/CBHue/nMap_Merger)
    parse               parse raw Nmap XML reports by service names and print entries in format {service}://{host}:{port}}
    draw                visualize Nmap XML reports (https://github.com/jor6PS/DrawNmap)
    tree                show contents of the ~/.das/ directory using tree
    help                show builtin --help dialog of a selected port scanner

options:
  -h, --help            show this help message and exit
  -db DB                DB name to work with

Psst, hey buddy... Wanna do some organized p0r7 5c4nn1n6?ToDoAddprojectdiscovery/naabuparserAddelddy/NimScanparserAddsxparserAddZMapparserStore hostnames (if there're any) next to their IP valuesAddfuffswitch to automate web directory fuzzing (addedparsemodule)