what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

TCP SYN Port Scanner

TCP SYN Port Scanner
Posted Sep 1, 2024
Authored by Kris Katterjohn | Site metasploit.com

Enumerate open TCP services using a raw SYN scan.

tags | exploit, tcp
SHA-256 | 14ea35b0026142850f8db65ecd2b7e60368fa5164e89ff0b57e95fdff4677928

TCP SYN Port Scanner

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Capture
include Msf::Auxiliary::Report
include Msf::Auxiliary::Scanner

def initialize
super(
'Name' => 'TCP SYN Port Scanner',
'Description' => %q{
Enumerate open TCP services using a raw SYN scan.
},
'Author' => 'kris katterjohn',
'License' => MSF_LICENSE
)

register_options([
OptString.new('PORTS', [true, "Ports to scan (e.g. 22-25,80,110-900)", "1-10000"]),
OptInt.new('TIMEOUT', [true, "The reply read timeout in milliseconds", 500]),
OptInt.new('BATCHSIZE', [true, "The number of hosts to scan per set", 256]),
OptInt.new('DELAY', [true, "The delay between connections, per thread, in milliseconds", 0]),
OptInt.new('JITTER', [true, "The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds.", 0]),
OptString.new('INTERFACE', [false, 'The name of the interface'])
])

deregister_options('FILTER','PCAPFILE')
end

# No IPv6 support yet
def support_ipv6?
false
end

def run_batch_size
datastore['BATCHSIZE'] || 256
end

def run_batch(hosts)
ports = Rex::Socket.portspec_crack(datastore['PORTS'])
if ports.empty?
raise Msf::OptionValidateError.new(['PORTS'])
end

jitter_value = datastore['JITTER'].to_i
if jitter_value < 0
raise Msf::OptionValidateError.new(['JITTER'])
end

delay_value = datastore['DELAY'].to_i
if delay_value < 0
raise Msf::OptionValidateError.new(['DELAY'])
end

open_pcap
pcap = self.capture

to = (datastore['TIMEOUT'] || 500).to_f / 1000.0

# we copy the hosts because some may not be reachable and need to be ejected
host_queue = hosts.dup
# Spread the load across the hosts
ports.each do |dport|
host_queue.each do |dhost|
shost, sport = getsource(dhost)

self.capture.setfilter(getfilter(shost, sport, dhost, dport))

# Add the delay based on JITTER and DELAY if needs be
add_delay_jitter(delay_value,jitter_value)

begin
probe = buildprobe(shost, sport, dhost, dport)

unless capture_sendto(probe, dhost)
host_queue.delete(dhost)
next
end

reply = probereply(self.capture, to)

next if not reply

if (reply.is_tcp? and reply.tcp_flags.syn == 1 and reply.tcp_flags.ack == 1)
print_good(" TCP OPEN #{dhost}:#{dport}")
report_service(:host => dhost, :port => dport)
end
rescue ::Exception
print_error("Error: #{$!.class} #{$!}")
end
end
end

close_pcap
end

def getfilter(shost, sport, dhost, dport)
# Look for associated SYN/ACKs and RSTs
"tcp and (tcp[13] == 0x12 or (tcp[13] & 0x04) != 0) and " +
"src host #{dhost} and src port #{dport} and " +
"dst host #{shost} and dst port #{sport}"
end

def getsource(dhost)
# srcip, srcport
[ Rex::Socket.source_address(dhost), rand(0xffff - 1025) + 1025 ]
end

def buildprobe(shost, sport, dhost, dport)
p = PacketFu::TCPPacket.new
p.ip_saddr = shost
p.ip_daddr = dhost
p.tcp_sport = sport
p.tcp_flags.ack = 0
p.tcp_flags.syn = 1
p.tcp_dport = dport
p.tcp_win = 3072
p.recalc
p
end

def probereply(pcap, to)
reply = nil
begin
Timeout.timeout(to) do
pcap.each do |r|
pkt = PacketFu::Packet.parse(r)
next unless pkt.is_tcp?
reply = pkt
break
end
end
rescue Timeout::Error
end
return reply
end
end
Login or Register to add favorites

File Archive:

October 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Oct 1st
    39 Files
  • 2
    Oct 2nd
    23 Files
  • 3
    Oct 3rd
    18 Files
  • 4
    Oct 4th
    20 Files
  • 5
    Oct 5th
    0 Files
  • 6
    Oct 6th
    0 Files
  • 7
    Oct 7th
    0 Files
  • 8
    Oct 8th
    0 Files
  • 9
    Oct 9th
    0 Files
  • 10
    Oct 10th
    0 Files
  • 11
    Oct 11th
    0 Files
  • 12
    Oct 12th
    0 Files
  • 13
    Oct 13th
    0 Files
  • 14
    Oct 14th
    0 Files
  • 15
    Oct 15th
    0 Files
  • 16
    Oct 16th
    0 Files
  • 17
    Oct 17th
    0 Files
  • 18
    Oct 18th
    0 Files
  • 19
    Oct 19th
    0 Files
  • 20
    Oct 20th
    0 Files
  • 21
    Oct 21st
    0 Files
  • 22
    Oct 22nd
    0 Files
  • 23
    Oct 23rd
    0 Files
  • 24
    Oct 24th
    0 Files
  • 25
    Oct 25th
    0 Files
  • 26
    Oct 26th
    0 Files
  • 27
    Oct 27th
    0 Files
  • 28
    Oct 28th
    0 Files
  • 29
    Oct 29th
    0 Files
  • 30
    Oct 30th
    0 Files
  • 31
    Oct 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close