Skip to content

Instantly share code, notes, and snippets.

@gedsic
Created August 12, 2015 08:40
Show Gist options
  • Select an option

  • Save gedsic/5e92702ace5fd26f9d88 to your computer and use it in GitHub Desktop.

Select an option

Save gedsic/5e92702ace5fd26f9d88 to your computer and use it in GitHub Desktop.
Get top 1000 UDP ports from nmap records
cat /usr/share/nmap/nmap-services | grep "/udp" | sort -k3 -n -r | head -n 1000 | grep -o "[0-9]*/udp" | sed 's/\/udp//g'
@gedsic
Copy link
Author

gedsic commented Aug 12, 2015

To have that as a comma-separated list, just add another paste pipe: | paste -d, -s

So we have

cat /usr/share/nmap/nmap-services | grep "/udp" | sort -k3 -n -r | head -n 1000 | grep -o "[0-9]*/udp" | sed 's/\/udp//g' | paste -d, -s

Example output:
631,161,137,123,138,1434,445,135,67,53,139,500 [...]

@gedsic
Copy link
Author

gedsic commented Aug 12, 2015

Originally, I wanted to import this list of UDP ports into OpenVAS. That, however, is no fun with the GSA gui. So I did it with omp:

$ UDPPORTS=$(cat /usr/share/nmap/nmap-services | grep "/udp" | sort -k3 -n -r | head -n 1000 | grep -o "[0-9]*/udp" | sed 's/\/udp//g' | paste -d, -s)
$ omp -u username -w password --xml="<create_port_list><name>All TCP and Nmap 6.47 top 1000 UDP</name><comment></comment><port_range>T:1-65535,U:${UDPPORTS}</port_range></create_port_list>"

If you get status_text="OK, resource created" status="201" in the result, it worked!

@Jineeshak
Copy link

YOU ARE A HERO!!!

@gedsic
Copy link
Author

gedsic commented Jul 22, 2020

YOU ARE A HERO!!!

Thanks, I'm glad this helped :)

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