Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Metasploit portscanner module


n3w7yp3's Avatar
Member
0 0

Hey all, with the release of Metasploit 3.0 release 1 alpha, I noticed that it included a port scanner. So, I decided to code one for the 2.x branch. Simply put the following code in the exploits dir on the framework root:

##
# This file is part of a series of add-ons for the Metasploit framework 2.x branch.
# It was coded by n3w7yp3 of Newage Hackers Labs.
# It can be distributed under the Newage Hackers Labs License agreement.
# Metasploit is avalible for free download at http://www.metasploit.com
# Enjoy, and use responsibly
##

# DISCLIAMER: The author hereby takes no responsibility for what you use this software for.
# Note: This is not actually part of Metasploit, its part of a series of expansions being coded by NHL. 

package Msf::Exploit::msf_scan;
#use strict;
use base "Msf::Exploit";
use Pex::DCERPC;
use Pex::NDR;
use Pex::Text;
use Pex::x86;
use IO::Socket::INET;
# use IO::Socket::SSL;

our $info = 
{
	'Name' => 'Metasploit Portscanner',
	'Version' => 'Revision: 1.0.0 $',
	'Authors' => [ 'n3w7yp3 <n3w7yp3 [at] gmail.com>' ],

	'UserOpts' => 
	{
		'RHOST' => [ 1, 'ADDR', 'The host to scan' ],
		'SPORT' => [ 1, 'PORT', 'Start port' ],
		'STPORT' => [ 1, 'PORT1', 'Stop port' ],
		'PROTO' => [ 1, 'PROTO', 'Ptotocol to use', 'tcp'],
	},
	'Description' => Pex::Text::Freeform(
	qq{
		This is a recon module that is capable of doing a TCP or UDP portscan against a host. SPORT is the start port, STPORT is the stop port.
}
	),
	'Keys' => ['scan'],
	'Release date' => '2005-12-16',
};
sub new
{
	my $class = shift;
	my $self = $class -> SUPER::new({'Info' => $info}, @_);
	return ($self);
}
sub Exploit
{
	my $self = shift;
	my $host = $self -> GetVar('RHOST');
	my $port1 = $self -> GetVar('SPORT');
	my $port2 = $self -> GetVar('STPORT');
	my $proto = $self -> GetVar('PROTO');
	my $port = 0;
	$self -> PrintLine ("[*] Starting Metasploit Port scanner by n3w7yp3...");
	$self -> PrintLine ("[*] Scanning ports $port1 through $port2 on $host...");
	$self -> PrintLine ("[*] Results of scan follow:");
	for($port = $port1 ; $port <= $port2 ; $port++)
	{
		my $socket = IO::Socket::INET -> new (Proto => $proto, PeerAddr => $host, PeerPort => $port, Timeout => 1);
		if($socket)
		{
			$self -> PrintLine ("\t$port\/$proto\tOPEN");
		}
	}
	$self -> PrintLine ("[*] Scan complete");
	return;
}


It is run like so:

msf > use msf_scan
msf msf_scan > set RHOST 127.0.0.1
RHOST -> 127.0.0.1
msf msf_scan > set SPORT 20
SPORT -> 20
msf msf_scan > set STPORT 30
STPORT -> 30
msf msf_scan > exploit
[*] Starting Metasploit Port scanner by n3w7yp3...
[*] Scanning ports 20 through 30 on 127.0.0.1...
[*] Results of scan follow:
        22/tcp  OPEN
        25/tcp  OPEN
[*] Scan complete

Enjoy!


ghost's Avatar
0 0

sweet if i used metasploit im sur eits be awesome.