Skip to content

Instantly share code, notes, and snippets.

@RoganDawes
Created October 14, 2018 13:27
Show Gist options
  • Save RoganDawes/327ddb1ac3988b1f69d636efdcb52afe to your computer and use it in GitHub Desktop.
Save RoganDawes/327ddb1ac3988b1f69d636efdcb52afe to your computer and use it in GitHub Desktop.
Convert Masscan bin files to a series of nmap invocations
#!/bin/sh
# Typical invocation would be:
# masscan_bin2list masscan.bin | parallel
#
# Example output from masscan_bin2list:
# nmap -sV -Pn -vv -n -p 443,80 -oA 10.0.0.1_V 10.0.0.1
# nmap -sV -Pn -vv -n -p 135,139,445 -oA 10.0.0.2_V 10.0.0.2
masscan --readscan $1 -oL - | \
perl -e '
use strict;
my %portmap;
while (<>) {
chomp;
next if (/^#/);
my @fields = split;
push @{ $portmap{$fields[3]} }, $fields[2];
}
for my $ip (sort keys %portmap) {
print "nmap -sV -Pn -vv -n -p ";
print join(",", sort @{ $portmap{$ip} } );
print " -oA ${ip}_V ${ip}\n";
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment