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

📄 config.pm

📁 一个rst守护程序
💻 PM
📖 第 1 页 / 共 2 页
字号:
package config;# Central P.A.T.H Configuration Module## For more information please read the POD documentation## Programmed by Bastian Ballmann [ bytebeater@crazydj.de ]# http://www.crazydj.de## Last Update: 27.11.2002## This code is licensed under the GPL###[ Loading modules ]###use strict;###[ Klassenvariablen ]#### Config Objectmy (%obj,$obj,%opts);my ($target,$source,$port);# Create a new config objectsub new{    my $class = shift;    $obj{'target'} = [];    $obj{'source'} = [];    $obj{'connection'} = [];    $obj{'port'} = [];    $obj{'multitarget'} = 0;    $obj{'multisource'} = 0;    $obj{'multiport'} = 0;    $obj{'device'} = "eth0";    $obj = bless \%obj, $class;    return $obj;}# Check the configurationsub check{    my $obj = shift;    my %args = @_;# Device configif($args{'i'}){    $obj->{'device'} = $args{'i'};}# Target Configif($args{'h'}){    $target = $args{'h'};# Target list    if($target =~ /\,/g)    {	@{$obj->{'targetlist'}} = split(/\,/,$target);	$obj->{'multitarget'} = 1;    }# Target range    elsif($target =~ /\-/)    {	my ($start,$stop) = split(/\-/,$target);	&check_ip($start);	&check_ip($stop);	@{$obj->{targetlist}} = get_ips($start,$stop);	$obj->{'multitarget'} = 1;    }# Einzelnes Target    else    {	&check_ip($target);	$obj->{'targetlist'}->[0] = $target;    }}# Source Configif($args{'s'}){    $source = $args{'s'};# Source list    if($source =~ /\,/g)    {	@{$obj->{'sourcelist'}} = split(/\,/,$source);	$obj->{'multisource'} = 1;    }# Source range    elsif($source =~ /\-/)    {	my ($start,$stop) = split(/\-/,$source);	&check_ip($start);	&check_ip($stop);	@{$obj->{sourcelist}} = get_ips($start,$stop);	$obj->{'multisource'} = 1;    }    else    {	$obj->{'sourcelist'}->[0] = $source;	&check_ip($source);    }}# Connection Config# Es soll nur eine bestimmte Connection resettet werdenif($args{'c'}){    @{$obj->{'connection'}} = split(/\-/,$args{'c'});    if(scalar(@{$obj->{connection}}) > 2)    {	die "A connection looks like this: xxx.xxx.xxx.xxx-xxx.xxx.xxx.xxx\n";    }    for(@{$obj->{'connection'}})    {	check_ip($_);    }}# Port Config# Wir sollen nur Packete fuer einen bestimmten Port resettenif($args{'p'}){    $port = $args{'p'};	# Port List?	if($port =~ /\,/)	{		@{$obj->{'port'}} = split(/\,/,$port);		$obj->{'multiport'} = 1;	}	# Port Range?	elsif($port =~ /\-/)	{		my($start,$stop) = split(/\-/,$port);		for(my $i=$start; $i <= $stop; $i++)		{			push @{$obj->{'port'}}, $i;		}		$obj->{'multiport'} = 1;	}       # Ein einsamer Port       else       {	   $obj{'port'}->[0] = $args{'p'};       }}return $obj;}# Print configurationsub print{    my $obj = shift;# Device     print "---:[ Device $obj->{'device'} ]:---\n\n";# Port Config    if(defined $obj->{'port'})    {	if($obj->multiport())	{	    print "---:[ Ports ";	    for(@{$obj->{'port'}})	    {		print "$_ ";	    }	    print "]:---\n\n";	}	else	{	    print "---:[ Port " . $obj->{'port'}->[0] . " ]:---\n\n";	}    }# Target Config    if(defined $obj->{'targetlist'}->[0])    {	if($obj->multitarget())	{	    print "---:[ Targets ";	    for(@{$obj->{'targetlist'}})	    {		print "$_ ";	    }	    print "]:---\n\n";	}	else	{	    print "---:[ Target $obj->{'targetlist'}->[0] ]:---\n\n";	}    }# Source Config    if(defined $obj->{'sourcelist'}->[0])    {	if($obj->multisource())	{	    print "---:[ Source ";	    for(@{$obj->{'sourcelist'}})	    {		print "$_ ";	    }	    print "]:---\n\n";	}	else	{	    print "---:[ Source $obj->{'sourcelist'}->[0] ]:---\n\n";	}    }# Connection    if(defined $obj->{'connection'}->[0])    {	print "---:[ Connection $obj->{'connection'}->[0] <--> $obj->{'connection'}->[1] ]:---\n\n";    }}# Change targetsub set_target{    my $obj = shift;    my @host = @_;    @{$obj->{'targetlist'}} = @host;    return $obj;}# Change sourcesub set_source{    my $obj = shift;    my @host = @_;    @{$obj->{'sourcelist'}} = @host;    return $obj;}# Change connectionsub set_connection{    my $obj = shift;    my $connection = shift;    $obj->{'connection'} = $connection;    return $obj;}# Change portsub set_port{    my $obj = shift;    my @port = @_;    @{$obj->{'port'}} = @port;    return $obj;}# Change devicesub set_device{    my $obj = shift;    my $device = shift;    $obj->{'device'} = $device;    return $device;}# Set flagssub set_flags{    my $obj = shift;    my %flags = @_;    $obj->{'syn'} = $flags{'syn'};    $obj->{'ack'} = $flags{'ack'};    $obj->{'rst'} = $flags{'rst'};    $obj->{'fin'} = $flags{'fin'};    $obj->{'psh'} = $flags{'psh'};    $obj->{'urg'} = $flags{'urg'};    return $obj;}# Set TCP optionssub set_tcpopt{    my $obj = shift;    my %opts = @_;    $obj->set_flags(%opts);    $obj->{'win'} = $opts{'win'};    $obj->{data} = $opts{data};    $obj->{seq} = $opts{seq};    $obj->{'ack_seq'} = $opts{'ack_seq'};    $obj->{'src_port'} = $opts{'src_port'};    $obj->{'dst_port'} = $opts{'dst_port'};    $obj->{protocol} = "tcp";    return $obj;}# Set UDP optionssub set_udpopt{    my $obj = shift;    my %opts = @_;    $obj->{'src_port'} = $opts{'src_port'};    $obj->{'dst_port'} = $opts{'dst_port'};    $obj->{data} = $opts{data};    $obj->{protocol} = "udp";    return $obj;}# Set ICMP optionssub set_icmpopt{    my $obj = shift;    my %opts = @_;    $obj->{type} = $opts{type};    $obj->{code} = $opts{code};    $obj->{gateway} = $opts{gateway};    $obj->{mtu} = $opts{mtu};    $obj->{data} = $opts{data};    $obj->{protocol} = "icmp";    return $obj;    }# Set IP optionssub set_ipopt{    my $obj = shift;    my %opts = @_;    $obj->{ttl} = $opts{ttl};    $obj->{tos} = $opts{tos};    $obj->{frag} = $opts{frag};    $obj->{sourcelist}->[0] = $opts{spoof};    $obj->{targetlist}->[0] = $opts{target};    return $obj;    }# Set general packet optionssub set_opt{        my $obj = shift;	my %opts = @_;	$obj->set_ipopt(%opts);	$obj->{protocol} = $opts{protocol};	if($opts{protocol} eq "tcp")	{	    $obj->set_tcpopt(%opts);	}	elsif($opts{protocol} eq "udp")	{	    $obj->set_udpopt(%opts);	}	elsif($opts{protocol} eq "icmp")	{	    $obj->set_icmpopt(%opts);	}	return $obj;}# Extract target host(s)sub get_target{    my $obj = shift;    if($obj->{'multitarget'})    {	return $obj->{'targetlist'};    }    else    {	return $obj->{'targetlist'}->[0];    }}# Extract source host(s)sub get_source{    my $obj = shift;    if($obj->{'multisource'})    {	return $obj->{'sourcelist'};    }    else    {	return $obj->{'sourcelist'}->[0];    }}# Extract connection(s)sub get_connection{    my $obj = shift;    return $obj->{'connection'};}# Extract port(s)sub get_port{    my $obj = shift;    if($obj->{'multiport'})    {	return $obj->{'port'};    }    else    {	return $obj->{'port'}->[0];    }}# Extract devicesub get_device{    my $obj = shift;    return $obj->{'device'};}# Get IP optionssub get_ipopt{    my $obj = shift;# Momentan noch kein Multisource, -target oder -port Support    $opts{'spoof'} = $obj->{sourcelist}->[0];    $opts{'target'} = $obj->{targetlist}->[0];    $opts{'frag'} = $obj->{frag};    $opts{'ttl'} = $obj->{ttl};    $opts{tos} = $obj->{tos};    return %opts;}# Get TCP optionssub get_tcpopt{    my $obj = shift;    $opts{'src_port'} = $obj->{'src_port'};    $opts{'dst_port'} = $obj->{'dst_port'};    $opts{'syn'} = $obj->{syn};    $opts{'ack'} = $obj->{ack};    $opts{'rst'} = $obj->{rst};    $opts{'fin'} = $obj->{fin};    $opts{'psh'} = $obj->{psh};    $opts{'urg'} = $obj->{urg};    $opts{'seq'} = $obj->{seq};    $opts{'ack_seq'} = $obj->{'ack_seq'};    $opts{win} = $obj->{win};    $opts{data} = $obj->{data};    return %opts;}# Get UDP optionssub get_udpopt{    my $obj = shift;    $opts{'src_port'} = $obj->{'src_port'};    $opts{'dst_port'} = $obj->{'dst_port'};     $opts{data} = $obj->{data};    return %opts;}# Get ICMP optionssub get_icmpopt{    my $obj = shift;    $opts{type} = $obj->{type};    $opts{code} = $obj->{code};    $opts{gateway} = $obj->{gateway};    $opts{data} = $obj->{data};    $opts{mtu} = $obj->{mtu};    return %opts;}# Get general packet optionssub get_opt{    my $obj = shift;    %opts = $obj->get_ipopt();    if($obj->{protocol} eq "tcp")    {	%opts = $obj->get_tcpopt();    }    elsif($obj->{protocol} eq "udp")    {	%opts = $obj->get_udpopt();    }    elsif($obj->{protocol} eq "icmp")    {	%opts = $obj->get_icmpopt();    }    return %opts;}# extract the used protocolsub get_protocol{    my $obj = shift;    my $proto = shift;    if($proto ne "")

⌨️ 快捷键说明

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