Skip to content

Instantly share code, notes, and snippets.

@Malayke
Last active April 10, 2023 09:00
Show Gist options
  • Save Malayke/08223b1edabfd1f01a57ac2609a679c8 to your computer and use it in GitHub Desktop.
Save Malayke/08223b1edabfd1f01a57ac2609a679c8 to your computer and use it in GitHub Desktop.
parse/convert nmap grep output(gnmap) to projectdiscovery httpx target
#!/usr/bin/env python3
import sys
if not sys.stdin.isatty():
stdin = sys.stdin.read().splitlines()
gnmap = stdin
elif len(sys.argv) > 1:
target = sys.argv[1]
with open(GNMAP) as f:
gnmap = f.read().splitlines()
else:
usage = f'''usage:\n\t1. python {sys.argv[0]} result.gnmap\n\t2. cat result.gnmap | python {sys.argv[0]}'''
print(usage)
sys.exit(1)
content = []
for line in gnmap:
if 'Ports:' in line:
content.append(line)
for line in content:
host_info = line.split()
ip = host_info[1]
for items in host_info:
if '/open/' in items:
port = items.split('/')[0]
print(f"{ip}:{port}")
@Malayke
Copy link
Author

Malayke commented Jun 9, 2022

usage

$ wget https://gist.github.com/Malayke/08223b1edabfd1f01a57ac2609a679c8/raw/53248f7a6415253c4189591c818ca7ebf8e11a38/parse_nmap_to_httpx.py

add execution permision

$ chmod +x parse_nmap_to_httpx.py

copy this file to /usr/local/bin or other directory defined inPATH

$ cp parse_nmap_to_httpx.py /usr/local/bin/nmap_to_httpx

nmap scan genere grep result file

$ nmap scanme.nmap.org -oG result
Nmap scan report for scanme.nmap.org (45.33.32.156)
Host is up (0.23s latency).
Not shown: 994 closed ports
PORT      STATE    SERVICE
22/tcp    open     ssh
80/tcp    open     http
139/tcp   filtered netbios-ssn
445/tcp   filtered microsoft-ds
9929/tcp  open     nping-echo
31337/tcp open     Elite

Nmap done: 1 IP address (1 host up) scanned in 81.24 seconds

convert result

$ cat result | nmap_to_httpx
45.33.32.156:22
45.33.32.156:80
45.33.32.156:9929
45.33.32.156:31337

httpx scan.

$ cat result | nmap_to_httpx | httpx -silent
http://45.33.32.156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment