TCP Port Scanner - Metasploit


This page contains detailed information about how to use the auxiliary/scanner/portscan/tcp metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: TCP Port Scanner
Module: auxiliary/scanner/portscan/tcp
Source code: modules/auxiliary/scanner/portscan/tcp.rb
Disclosure date: -
Last modification time: 2017-07-24 06:26:21 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: -
Target network port(s): -
List of CVEs: -

Enumerate open TCP services by performing a full TCP connect on each port. This does not need administrative privileges on the source machine, which may be useful if pivoting.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


This module is a scanner module, and is capable of testing against multiple hosts.

msf > use auxiliary/scanner/portscan/tcp
msf auxiliary(tcp) > show options
    ... show and set options ...
msf auxiliary(tcp) > set RHOSTS ip-range
msf auxiliary(tcp) > exploit

Other examples of setting the RHOSTS option:

Example 1:

msf auxiliary(tcp) > set RHOSTS 192.168.1.3-192.168.1.200 

Example 2:

msf auxiliary(tcp) > set RHOSTS 192.168.1.1/24

Example 3:

msf auxiliary(tcp) > set RHOSTS file:/tmp/ip_list.txt

Required Options


  • RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

Knowledge Base


Description


This module will enumerate open TCP services by performing a full TCP connect on each port. This will establish a complete three-way handshake (SYN -> SYN/ACK -> ACK) on the target port. This does not need administrative privileges on the source machine, which may be useful if pivoting.

Vulnerable Application


Any reachable TCP endpoint is a potential target.

Options


PORTS

This is the list of ports to test for TCP Scan on each host. Formats like 1-3, 1,2,3, 1,2-3, etc. are all supported. Default options is to scan 1-10000 ports.

ConnectTimeout

This options states the maximum number of seconds to establish a tcp connection. Default value if 10.

VERBOSE

Gives detailed message about the scan of all the ports. It also shows the ports that were closed.

Verification Steps


  1. Do: use auxiliary/scanner/portscan/tcp
  2. Do: set RHOSTS [IP]
  3. Do: set PORTS [PORTS]
  4. Do: run

Scenarios


Metaspliotable 2

msf > use auxiliary/scanner/portscan/tcp
msf auxiliary(tcp) > set RHOSTS 192.168.45.159
msf auxiliary(tcp) > set PORTS 1-10000
msf auxiliary(tcp) > run
[*] 192.168.45.159:       - 192.168.45.159:25 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:21 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:23 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:22 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:53 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:80 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:111 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:139 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:445 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:513 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:514 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:512 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:1099 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:1524 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:2049 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:2121 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:3306 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:3632 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:5432 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:5900 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:6000 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:6667 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:6697 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:8009 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:8180 - TCP OPEN
[*] 192.168.45.159:       - 192.168.45.159:8787 - TCP OPEN
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

Go back to menu.

Msfconsole Usage


Here is how the scanner/portscan/tcp auxiliary module looks in the msfconsole:

msf6 > use auxiliary/scanner/portscan/tcp

msf6 auxiliary(scanner/portscan/tcp) > show info

       Name: TCP Port Scanner
     Module: auxiliary/scanner/portscan/tcp
    License: Metasploit Framework License (BSD)
       Rank: Normal

Provided by:
  hdm <[email protected]>
  kris katterjohn <[email protected]>

Check supported:
  No

Basic options:
  Name         Current Setting  Required  Description
  ----         ---------------  --------  -----------
  CONCURRENCY  10               yes       The number of concurrent ports to check per host
  DELAY        0                yes       The delay between connections, per thread, in milliseconds
  JITTER       0                yes       The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds.
  PORTS        1-10000          yes       Ports to scan (e.g. 22-25,80,110-900)
  RHOSTS                        yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  THREADS      1                yes       The number of concurrent threads (max one per host)
  TIMEOUT      1000             yes       The socket connect timeout in milliseconds

Description:
  Enumerate open TCP services by performing a full TCP connect on each 
  port. This does not need administrative privileges on the source 
  machine, which may be useful if pivoting.

Module Options


This is a complete list of options available in the scanner/portscan/tcp auxiliary module:

msf6 auxiliary(scanner/portscan/tcp) > show options

Module options (auxiliary/scanner/portscan/tcp):

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   CONCURRENCY  10               yes       The number of concurrent ports to check per host
   DELAY        0                yes       The delay between connections, per thread, in milliseconds
   JITTER       0                yes       The delay jitter factor (maximum value by which to +/- DELAY) in milliseconds.
   PORTS        1-10000          yes       Ports to scan (e.g. 22-25,80,110-900)
   RHOSTS                        yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   THREADS      1                yes       The number of concurrent threads (max one per host)
   TIMEOUT      1000             yes       The socket connect timeout in milliseconds

Advanced Options


Here is a complete list of advanced options supported by the scanner/portscan/tcp auxiliary module:

msf6 auxiliary(scanner/portscan/tcp) > show advanced

Module advanced options (auxiliary/scanner/portscan/tcp):

   Name                 Current Setting  Required  Description
   ----                 ---------------  --------  -----------
   CHOST                                 no        The local client address
   CPORT                                 no        The local client port
   ConnectTimeout       10               yes       Maximum number of seconds to establish a TCP connection
   Proxies                               no        A proxy chain of format type:host:port[,type:host:port][...]
   SSL                  false            no        Negotiate SSL/TLS for outgoing connections
   SSLCipher                             no        String for SSL cipher - "DHE-RSA-AES256-SHA" or "ADH"
   SSLVerifyMode        PEER             no        SSL verification method (Accepted: CLIENT_ONCE, FAIL_IF_NO_PEER_CERT, NONE, PEER)
   SSLVersion           Auto             yes       Specify the version of SSL/TLS to be used (Auto, TLS and SSL23 are auto-negotiate) (Accepted: Auto, TLS, SSL23, SSL3, TLS1, TLS1.1, TLS1.2)
   ShowProgress         true             yes       Display progress messages during a scan
   ShowProgressPercent  10               yes       The interval in percent that progress should be shown
   VERBOSE              false            no        Enable detailed status messages
   WORKSPACE                             no        Specify the workspace for this module

Auxiliary Actions


This is a list of all auxiliary actions that the scanner/portscan/tcp module can do:

msf6 auxiliary(scanner/portscan/tcp) > show actions

Auxiliary actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the scanner/portscan/tcp auxiliary module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 auxiliary(scanner/portscan/tcp) > show evasion

Module evasion options:

   Name                Current Setting  Required  Description
   ----                ---------------  --------  -----------
   TCP::max_send_size  0                no        Maxiumum tcp segment size.  (0 = disable)
   TCP::send_delay     0                no        Delays inserted before every send.  (0 = disable)

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

PORTS


Here is a relevant code snippet related to the "PORTS" error message:

40:	    timeout = datastore['TIMEOUT'].to_i
41:	
42:	    ports = Rex::Socket.portspec_crack(datastore['PORTS'])
43:	
44:	    if ports.empty?
45:	      raise Msf::OptionValidateError.new(['PORTS'])
46:	    end
47:	
48:	    jitter_value = datastore['JITTER'].to_i
49:	    if jitter_value < 0
50:	      raise Msf::OptionValidateError.new(['JITTER'])

JITTER


Here is a relevant code snippet related to the "JITTER" error message:

45:	      raise Msf::OptionValidateError.new(['PORTS'])
46:	    end
47:	
48:	    jitter_value = datastore['JITTER'].to_i
49:	    if jitter_value < 0
50:	      raise Msf::OptionValidateError.new(['JITTER'])
51:	    end
52:	
53:	    delay_value = datastore['DELAY'].to_i
54:	    if delay_value < 0
55:	      raise Msf::OptionValidateError.new(['DELAY'])

DELAY


Here is a relevant code snippet related to the "DELAY" error message:

50:	      raise Msf::OptionValidateError.new(['JITTER'])
51:	    end
52:	
53:	    delay_value = datastore['DELAY'].to_i
54:	    if delay_value < 0
55:	      raise Msf::OptionValidateError.new(['DELAY'])
56:	    end
57:	
58:	    while(ports.length > 0)
59:	      t = []
60:	      r = []

<IP>:<PORT> exception <E.CLASS> <E> <E.BACKTRACE>


Here is a relevant code snippet related to the "<IP>:<PORT> exception <E.CLASS> <E> <E.BACKTRACE>" error message:

85:	          rescue ::Rex::ConnectionError, ::IOError, ::Timeout::Error
86:	          rescue ::Rex::Post::Meterpreter::RequestError
87:	          rescue ::Interrupt
88:	            raise $!
89:	          rescue ::Exception => e
90:	            print_error("#{ip}:#{port} exception #{e.class} #{e} #{e.backtrace}")
91:	          ensure
92:	            if s
93:	              disconnect(s) rescue nil
94:	            end
95:	          end

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • hdm
  • kris katterjohn

Version


This page has been produced using Metasploit Framework version 6.1.27-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.