Nmap
Ruby-nmap gem is a Ruby interface to nmap, the exploration tool and security / port scanner.
- Provides a Ruby interface for running nmap.
- Provides a Parser for enumerating nmap XML scan files.
scan = Nmap::Program.scan(:targets => '192.168.0.15', :verbose => true)
each option like nmap.syn_scan
or nmap.xml
is considered as a Task. Documentation shows the list of that are supported by the lib.
#!/usr/bin/env ruby
# KING SABRI | @KINGSABRI
require 'nmap/program'
Nmap::Program.scan do |nmap|
# Target
nmap.targets = '192.168.0.1'
# Verbosity and Debugging
nmap.show_reason = true
nmap.syn_scan = true # You can use nmap.all like -A in nmap
# Service/Version Detection:
nmap.service_scan = true
nmap.os_fingerprint = true
nmap.version_all = true
# Script scanning
nmap.script = "all"
nmap.all_ports # nmap.ports = (0..65535).to_a
# Firewall/IDS Evasion and Spoofing:
nmap.decoys = ["google.com","yahoo.com","hotmail.com","facebook.com"]
nmap.spoof_mac = "00:11:22:33:44:55"
nmap.max_parallelism = 130
# Scan outputs
nmap.output_all = 'rubyfu_scan'
end
I quoted the code from official documentation (https://github.com/sophsec/ruby-nmap)
require 'nmap/xml'
Nmap::XML.new(ARGV[0]) do |xml|
xml.each_host do |host|
puts "[#{host.ip}]"
# Print: Port/Protocol port_status service_name
host.each_port do |port|
puts " #{port.number}/#{port.protocol}\t#{port.state}\t#{port.service}"
end
end