⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.pm

📁 一个rst守护程序
💻 PM
📖 第 1 页 / 共 2 页
字号:
    {	if($obj->{protocol} eq $proto)	{	    return 1;	}	else	{	    return 0;	}    }    else    {	return $obj->{protocol};    }}# extract the flagssub get_flags{    my $obj = shift;    my %opts;    $opts{'syn'} = $obj->{syn};    $opts{'ack'} = $obj->{ack};    $opts{'rst'} = $obj->{rst};    $opts{'fin'} = $obj->{fin};    $opts{'psh'} = $obj->{psh};    $opts{'urg'} = $obj->{urg};    return %opts;}# Multitarget?sub multitarget{    my $obj = shift;    return $obj->{'multitarget'};}# Multisource?sub multisource{    my $obj = shift;    return $obj->{'multisource'};}# Multi port?sub multiport{    my $obj = shift;    return $obj->{'multiport'};}# Gibt es einen Connection Eintrag?sub connection{    my $obj = shift;    if($obj->{'connection'}->[0] ne "")    {	return 1;    }    else    {	return 0;    }}# Gibt es einen Target Eintrag?sub target{    my $obj = shift;    if($obj->{'targetlist'}->[0] ne "")    {	return 1;    }    else    {	return 0;    }}# Gibt es einen Source Eintrag?sub source{    my $obj = shift;    if($obj->{'sourcelist'}->[0] ne "")    {	return 1;    }    else    {	return 0;    }}# Gibt es einen Port Eintrag?sub port{    my $obj = shift;    if($obj->{'port'}->[0] ne "")    {	return 1;    }    else    {	return 0;    }}# Check if ip address is correctsub check_ip{    my $ip = shift;    my @ip = split(/\./,$ip);# Mehr als 4 Byte?if(scalar(@ip != 4)){    print ">>>  Bad IP address $ip!\n\n";}# Ist ein Wert groesser als 256?for(@ip){    if($_ > 256)    {	print ">>> Bad IP address $ip!\n\n";    }}}# Get ipssub get_ips{    my $start = shift;    my $stop = shift;# Rechne die IP in eine Dezimalzahl um	my @start = split(/\./,$start); 	my @stop = split(/\./,$stop); 	my $start_dec = ((@start[0]*16777216)+(@start[1]*65536)+(@start[2]*256)+@start[3]);	my $stop_dec = ((@stop[0]*16777216)+(@stop[1]*65536)+(@stop[2]*256)+@stop[3]);# Berechne Start / End IP	while($start_dec < $stop_dec + 1)	{		my @bytez;		my $rem;# Rechne die Dezimal Zahl wieder in eine IP Adresse um	    	@bytez[0] = int $start_dec/16777216;	    	$rem = $start_dec % 16777216;	    	@bytez[1] = int $rem/65536;	    	$rem = $rem % 65536;	    	@bytez[2] = int $rem/256;	    	$rem = $rem % 256;	    	@bytez[3] = $rem;	  	my $ipaddr = join '.', @bytez;		push @{$obj->{'target'}}, $ipaddr;		$start_dec++;	}	}# Create a pcap expression from configurationsub pcap{    my $obj = shift;    my $pcap = "";    my @conn = ();    if($obj->multitarget)    {	for(@{$obj->get_target})	{	    $pcap .= "host $_ or ";	}	chop $pcap;	chop $pcap;	chop $pcap;    }    elsif($obj->get_target ne "")    {	$pcap .= "host " . $obj->get_target . " ";    }    elsif(scalar(@{$obj->get_connection}) > 0)    {	@conn = @{$obj->get_connection};	$pcap .= "host $conn[0] or host $conn[1] ";    }    if($pcap ne "")    {	$pcap .= "and ";    }    if($obj->multiport)    {	for(@{$obj->get_port})	{	    $pcap .= "port $_ or ";	}	chop $pcap;	chop $pcap;	chop $pcap;    }    elsif($obj->get_port ne "")    {	$pcap .= "port " . $obj->get_port . " ";    }    return $pcap;}###[ Parse a config file ]###sub readcfg{    my $opt = shift;    my $file = shift;    my($command,$wert);    my(@config);    my(%parameter);# Die Konfigurationsdatei wird gelesenopen (CONFIG,"<$file") || die "Kann Configfile $file nicht einlesen!!!\n";	while(<CONFIG>)	{		# Auskommentierte Zeilen auslassen		if($_ =~ /^#/)		{		    next;       		}		# Leere Zeilen auch       		elsif(length($_)<2)       		{		    next;       		}       		else       		{		    chomp $_;		    ($command,$wert) = split(/\s+==\s+/,$_);		    # Write a Array?		    if($opt eq "a")		    {			push @config, $command;			push @config, $wert;		    }		   else		    {		    	$parameter{$command}=$wert;		    }		}	}	close(CONFIG);if($opt eq "a"){    return @config;}else{    return %parameter;}}# Generate a config object# out of a config filesub register_config{    my $obj = shift;    my %args = @_;    $obj->set_device($args{device});    $obj->set_source($args{spoof});    $obj->set_target($args{target});    $obj->set_port($args{port});    return $obj;}1;###[ Thats the end folks ]###__END__###[ POD Documentation ]###=pod=head2 NAME    Config.pm  --  P.A.T.H Configuration=head2 SYNOPSIS    use config;    use Getopt::Std;    getopts('h:c:p:i:',%args);    $cfg = config->new();    $cfg->check(%args);        if($cfg->connection)    {	@connect = $cfg->connection;	print "Connection $connection[0] <--> $connection[1]\n";    }   if($cfg->multiport)   {	@ports = $cfg->get_port;	print "Ports: ";	for(@ports)	{	   print;	}	print "\n";   }=head2 DESCRIPTION   This module checks the configuration for P.A.T.H. scripts.   It parses the parameter like host (lists,ranges), connections,   port (lists,ranges) and device.   You can set and get config parameters.   This module can also read and parse a configuration file.=head2 METHODS   new   check   print   get_device   get_target   get_source   get_connection   get_port   get_flags   get_ipopt   get_tcpopt   get_udpopt   get_icmpopt   get_opt   set_flags   set_ipopt   set_tcpopt   set_udpopt   set_cmpopt   set_opt   set_device   set_target   set_source   set_connection   set_port   multiport   multitarget   multisource   target   source   port   connection   pcap   readcfg   register_config=head2 Description of methods=item B<new()>   $cfg = config->new()   This creates a new config object.=item B<check()>   $cfg->check(%args);   This method parses and checks the parameter in the hash %args.   %args can contain the following things:   i: device   c: connection (target1-target2)   h: host (list: host1,host2 // range host1-host3)   p: port (list or range)=item B<print()>   $cfg->print();   This will print the configuration to STDOUT.=item B<get_device()>   $cfg->get_device   This method returns the configured device.   All the other get_* methods do the same.=item B<set_device()>   $cfg->set_device("eth1");   This method changes the device configuration and   returns the new object.   All teh other set_* methods are used similar and   do the same.=item B<set_opt>    $cfg->set_opt(%config);    This method sets the packet options like TCP flags,     window size and so on. There is also a set_* method    for each supported protocol.    See the section configuration hash for a description    of the hash %config.=item B<get_opt>        %config = $cfg->get_opt();    This method can be used to receive all the packet    option from the config object. There is also a get_*    method for each supported protcol.    See the section configuration hash for a description    of the hash %config.=item B<multitarget()>   $cfg->multitarget;   This method will return the boolean value true if the   configuration contains more than one host.   The multisource and multiport method is used the same way.=item B<connection()>   $cfg->connection;   This method return the boolean value true if a connection   is found in the configuration.   The port and host method are used the same way.=item B<pcap()>   $string = $cfg->pcap();   Create a pcap expression from the configuration like:   host 192.168.1.1 and port 23 or port 21=item B<readcfg()>   %config = config::readcfg($opt,$file);   This function will parse a config file like this:   parameter == value  opt: a - Function return an array       h - Function returns a hash (default)  file: Contains the path to the config file.=item B<register_config()>    $cfg->register_config(%config);    This method stores the default values like target    and device into the config object.=item B<The configuration hash>    The configuration hash has the following values    (depeding on which protocol should be configured):    $opts{'protocol'}    $opts{'spoof'}    $opts{'target'}    $opts{'frag'}    $opts{'ttl'}    $opts{tos}    $opts{'src_port'}    $opts{'dst_port'}    $opts{'syn'}    $opts{'ack'}    $opts{'rst'}    $opts{'fin'}    $opts{'psh'}    $opts{'urg'}    $opts{'seq'}    $opts{'ack_seq'}    $opts{'win'}    $opts{'data'}    $opts{'type'}    $opts{'code'}    $opts{'gateway'}    $opts{'mtu'}    =head2 BUGS  Currently there are no known bugs...  Please send bug reports to bugs@crazydj.de=head2 AUTHOR   Bastian Ballmann [ bytebeater@crazydj.de ]   http://www.crazydj.de=head2 COPYRIGHT   This module is free software.   It is licensed under GPL.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -