Skip to content

Commit

Permalink
Added support for tcp_del_ports and udp_del_ports. Added tests for th…
Browse files Browse the repository at this point in the history
…ese new functions.
  • Loading branch information
apersaud committed Oct 2, 2008
1 parent 16f4b45 commit 83b1d12
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 249 deletions.
28 changes: 25 additions & 3 deletions Parser.pm
Expand Up @@ -6,7 +6,7 @@ use XML::Twig;
use Storable qw(dclone);
use vars qw($VERSION %D);

$VERSION = 1.16;
$VERSION = 1.17;

sub new {

Expand Down Expand Up @@ -625,6 +625,20 @@ sub extraports_state { return $_[0]->{ports}{extraports}{state}; }
sub extraports_count { return $_[0]->{ports}{extraports}{count}; }
sub distance { return $_[0]->{distance}; }

sub _del_port {
my $self = shift;
my $proto = pop; #portid might be empty, so this goes first
my @portids = @_;
@portids = grep { $_ + 0 } @portids;

unless ( scalar @portids ) {
warn "[Nmap-Parser] No port number given to del_port()\n";
return undef;
}

delete $self->{ports}{$proto}{$_} for (@portids);
}

sub _get_ports {
my $self = shift;
my $proto = pop; #param might be empty, so this goes first
Expand Down Expand Up @@ -674,6 +688,9 @@ sub udp_port_count { return $_[0]->{ports}{udp_port_count}; }
sub tcp_port_state { return _get_port_state( @_, 'tcp' ); }
sub udp_port_state { return _get_port_state( @_, 'udp' ); }

sub tcp_del_ports { return _del_port( @_, 'tcp' ); }
sub udp_del_ports { return _del_port( @_, 'udp' ); }

sub tcp_service {
my $self = shift;
my $portid = shift;
Expand Down Expand Up @@ -1204,13 +1221,18 @@ be counted as an 'open' port as well as a 'filtered' one.>
Returns the total of TCP|UDP ports scanned respectively.
=item B<tcp_del_ports($portid, [$portid, ...])>
=item B<udp_del_ports($portid, [ $portid, ...])>
Deletes the current $portid from the list of ports for given protocol.
=item B<tcp_port_state($portid)>
=item B<udp_port_state($portid)>
Returns the state of the given port, provided by the port number in $portid.
=item B<tcp_open_ports()>
=item B<udp_open_ports()>
Expand Down Expand Up @@ -1544,7 +1566,7 @@ Anthony G Persaud L<http://www.anthonypersaud.com>
=head1 COPYRIGHT
Copyright (c) <2003-2008> <Anthony G. Persaud>
Copyright (c) <2003-2009> <Anthony G. Persaud>
MIT License
Expand Down
126 changes: 63 additions & 63 deletions t/instance.xml
@@ -1,68 +1,68 @@
<?xml version="1.0"?>
<!-- nmap 3.27 scan initiated Tue Jul 1 14:48:03 2003 as: nmap -v -v -v -oX test.xml -O -sTUR -p 1-1023 localhost -->
<nmaprun scanner="nmap" args="nmap -v -v -v -oX test.xml -O -sTUR -p 1-1023 localhost" start="1057088883" version="3.27" xmloutputversion="1.0">
<scaninfo type="connect" protocol="tcp" numservices="1023" services="1-1023"/>
<scaninfo type="udp" protocol="udp" numservices="1023" services="1-1023"/>
<verbose level="3"/>
<debugging level="0"/>
<host>
<status state="up"/>
<address addr="127.0.0.3" addrtype="ipv4"/>
<hostnames>
<hostname name="host_3" type="PTR"/>
</hostnames>
<ports>
<extraports state="filtered" count="1644"/>
<port protocol="tcp" portid="112">
<state state="open"/>
<service name="rpcbind" version="2" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="113">
<state state="open"/>
<owner name="identd"/>
<service name="ident" product="OpenBSD identd" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="21">
<state state="open"/>
<owner name="root"/>
<service name="ftp" product="ProFTPD" version="1.2.5rc1" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="22">
<state state="open"/>
<owner name="root"/>
<service name="ssh" product="OpenSSH" version="3.4p1" extrainfo="protocol 1.99" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="25">
<state state="open"/>
<owner name="root"/>
<service name="smtp" product="Exim smtpd" version="3.35" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="26">
<state state="open"/>
<service name="ssh" product="OpenSSH" version="3.6.1p1" extrainfo="protocol 1.99" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="80">
<state state="open"/>
<owner name="www-data"/>
<service name="http" product="Apache httpd" version="1.3.26" extrainfo="(Unix) Debian GNU/Linux" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="953">
<state state="open"/>
<service name="rndc" method="table" conf="3"/>
</port>
<port protocol="tcp" portid="53">
<state state="open"/>
<service name="dns" method="table" conf="3"/>
</port>
<port protocol="tcp" portid="8080">
<state state="filtered"/>
<service name="https" method="table" conf="3"/>
</port>
</ports>
</host>
<runstats>
<finished time="1057088900"/>
<hosts up="1" down="0" total="1"/>
<scaninfo type="connect" protocol="tcp" numservices="1023" services="1-1023"/>
<scaninfo type="udp" protocol="udp" numservices="1023" services="1-1023"/>
<verbose level="3"/>
<debugging level="0"/>
<host>
<status state="up"/>
<address addr="127.0.0.3" addrtype="ipv4"/>
<hostnames>
<hostname name="host_3" type="PTR"/>
</hostnames>
<ports>
<extraports state="filtered" count="1644"/>
<port protocol="tcp" portid="112">
<state state="open"/>
<service name="rpcbind" version="2" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="113">
<state state="open"/>
<owner name="identd"/>
<service name="ident" product="OpenBSD identd" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="21">
<state state="open"/>
<owner name="root"/>
<service name="ftp" product="ProFTPD" version="1.2.5rc1" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="22">
<state state="open"/>
<owner name="root"/>
<service name="ssh" product="OpenSSH" version="3.4p1" extrainfo="protocol 1.99" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="25">
<state state="open"/>
<owner name="root"/>
<service name="smtp" product="Exim smtpd" version="3.35" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="26">
<state state="open"/>
<service name="ssh" product="OpenSSH" version="3.6.1p1" extrainfo="protocol 1.99" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="80">
<state state="open"/>
<owner name="www-data"/>
<service name="http" product="Apache httpd" version="1.3.26" extrainfo="(Unix) Debian GNU/Linux" method="probed" conf="10"/>
</port>
<port protocol="tcp" portid="953">
<state state="open"/>
<service name="rndc" method="table" conf="3"/>
</port>
<port protocol="tcp" portid="53">
<state state="open"/>
<service name="dns" method="table" conf="3"/>
</port>
<port protocol="tcp" portid="8080">
<state state="filtered"/>
<service name="https" method="table" conf="3"/>
</port>
</ports>
</host>
<runstats>
<finished time="1057088900"/>
<hosts up="1" down="0" total="1"/>
<!-- Nmap run completed at Tue Jul 1 14:48:20 2003; 1 IP address (1 host up) scanned in 16.970 seconds -->
</runstats>
</runstats>
</nmaprun>

0 comments on commit 83b1d12

Please sign in to comment.