| 1 | # -*- mode: cperl; cperl-indent-level: 4; -*- | ||||||||||||||||||||||||||||
| 2 | # vi:ai:sm:et:sw=4:ts=4 | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # $Id: IPTables.pm,v 1.9 2005/11/18 23:40:00 paulv Exp $ | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package POE::Filter::Log::IPTables; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use POE::Filter::Line; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | croak "$class requires an even number of parameters" if @_ and @_ & 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and @_ & 1
MC/DC0%0/2
@_ and @_ & 1
@_
@_ & 1
Truth table33%1/3
A and B
A= @_B= @_ & 1
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my %params = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | my $self = {}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | $self->{line} = POE::Filter::Line->new(); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # the types of ICMP messages that require us to do further | ||||||||||||||||||||||||||||
| 27 | # processing | ||||||||||||||||||||||||||||
| 28 | 2 | $self->{icmp_types} = ['3', # destination unreachable | |||||||||||||||||||||||||||
| 29 | '4', # source quench | ||||||||||||||||||||||||||||
| 30 | '11', # time exceeded | ||||||||||||||||||||||||||||
| 31 | ]; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | if (defined $params{Debug} and $params{Debug} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params{"Debug"} and $params{"Debug"} > 0
MC/DC0%0/2
defined $params{"Debug"} and $params{"Debug"} > 0
defined $params{"Debug"}
$params{"Debug"} > 0
Truth table33%1/3
A and B
A= defined $params{"Debug"}B= $params{"Debug"} > 0
| |||||||||||||||||||||||||||||
| 34 | 0 | $self->{debug} = 1; | |||||||||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||||||||||
| 36 | 2 | $self->{debug} = 0; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | if (defined $params{Syslog} and $params{Syslog} > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params{"Syslog"} and $params{"Syslog"} > 0
MC/DC0%0/2
defined $params{"Syslog"} and $params{"Syslog"} > 0
defined $params{"Syslog"}
$params{"Syslog"} > 0
Truth table33%1/3
A and B
A= defined $params{"Syslog"}B= $params{"Syslog"} > 0
| |||||||||||||||||||||||||||||
| 40 | 2 | $self->{syslog} = 1; | |||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||
| 42 | 0 | $self->{syslog} = 0; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | bless ($self, $class); | |||||||||||||||||||||||||||
| 46 | 2 | return $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 8 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | 8 | my $chunk = shift; | |||||||||||||||||||||||||||
| 52 | 8 | my @queue; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 8 | my $lines = $self->{line}->get($chunk); | |||||||||||||||||||||||||||
| 55 | 8 | foreach my $line (@$lines) { | |||||||||||||||||||||||||||
| 56 | 8 | push(@queue, $self->_parse($line)); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 8 | return \@queue; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 9 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=13 SCAR=25.8
| |||||||||||||||||||||||||||||
| 62 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | 9 | my $line = shift; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 9 | my $ds; | |||||||||||||||||||||||||||
| 66 | my $leftover; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # save the whole line so the user can twiddle it if she wants. | ||||||||||||||||||||||||||||
| 69 | 9 | $ds->{line} = $line; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # strip off syslog stuff | ||||||||||||||||||||||||||||
| 72 | 9 | ▶ | if ($self->{syslog}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | # Jan 11 17:30:35 hostname kernel: | ||||||||||||||||||||||||||||
| 74 | 9 | $line =~ s/^\w\w\w\s+\d+ \d\d:\d\d:\d\d (?:\w|-|\.|_)+ //; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # remove prefix | ||||||||||||||||||||||||||||
| 78 | 9 | $line =~ s/kernel: (.{0,29}) ?IN/IN/; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # IN, OUT, and MAC | ||||||||||||||||||||||||||||
| 81 | 9 | ▶ | print "base: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # inbound interface | ||||||||||||||||||||||||||||
| 84 | 9 | ▶ | if ($line =~ /^IN=(\w+)? /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 8 | $ds->{in_int} = $1; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 8 | ▶ | if ($1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 8 | $line =~ s/IN=$1 //; | |||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||
| 90 | 0 | $line =~ s/IN= //; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # outbound interface | ||||||||||||||||||||||||||||
| 95 | 9 | ▶ | if ($line =~ / ?OUT=([A-Za-z0-9]+)? /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 8 | $ds->{out_int} = $1; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 8 | ▶ | if ($1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | $line =~ s/ ?OUT=$1 //; | |||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||
| 101 | 8 | $line =~ s/ ?OUT= //; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # input MAC address | ||||||||||||||||||||||||||||
| 106 | 9 | ▶ | if ($line =~ / ?MAC=([0-9A-F:]+)? /i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 8 | $ds->{mac} = $1; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 8 | ▶ | if ($1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 3 | $line =~ s/ ?MAC=$1 //; | |||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||
| 112 | 5 | $line =~ s/ ?MAC= //; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 9 | ▶ | print "BASE done: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # the IP header | ||||||||||||||||||||||||||||
| 119 | 9 | ($line, $ds->{ip}) = $self->_parseIP($line); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # everything else | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # ICMP has to be done first because ICMP messages sometimes have IP | ||||||||||||||||||||||||||||
| 124 | # headers in them. | ||||||||||||||||||||||||||||
| 125 | 9 | ▶ | if ($line =~/ ?PROTO=ICMP /) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 126 | 2 | $line =~ s/^PROTO=ICMP //g; | |||||||||||||||||||||||||||
| 127 | 2 | $ds->{ip}->{type} = "icmp"; | |||||||||||||||||||||||||||
| 128 | 2 | ($ds->{ip}->{icmp}, $leftover) = $self->_parseICMP($line); | |||||||||||||||||||||||||||
| 129 | } elsif ($line =~ / ?PROTO=TCP /) { | ||||||||||||||||||||||||||||
| 130 | 4 | $line =~ s/^PROTO=TCP //g; | |||||||||||||||||||||||||||
| 131 | 4 | $ds->{ip}->{type} = "tcp"; | |||||||||||||||||||||||||||
| 132 | 4 | ($ds->{ip}->{tcp}, $leftover) = $self->_parseTCP($line); | |||||||||||||||||||||||||||
| 133 | } elsif ($line =~/ ?PROTO=UDP /) { | ||||||||||||||||||||||||||||
| 134 | 2 | $line =~ s/^PROTO=UDP //g; | |||||||||||||||||||||||||||
| 135 | 2 | $ds->{ip}->{type} = "udp"; | |||||||||||||||||||||||||||
| 136 | 2 | ($ds->{ip}->{udp}, $leftover) = $self->_parseUDP($line); | |||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||
| 138 | # $line =~ s/^PROTO=//g; | ||||||||||||||||||||||||||||
| 139 | 1 | ($ds->{ip}->{type}, $leftover) = $self->_parseUnknown($line); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 9 | $ds->{leftover} = $leftover; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 9 | return $ds; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 9 | ▶ | sub _parseIP { | ||||||||||||||||||||||||||
|
Subroutine
_parseIP: called CC=13 SCAR=26.0
| |||||||||||||||||||||||||||||
| 148 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 149 | 9 | my $line = shift; | |||||||||||||||||||||||||||
| 150 | 9 | my $ds; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 9 | ▶ | print "IP: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # source address | ||||||||||||||||||||||||||||
| 155 | 9 | ▶ | if ($line =~ / ?SRC=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 9 | $ds->{src_addr} = $1; | |||||||||||||||||||||||||||
| 157 | 9 | $line =~ s/ ?SRC=$1 //; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # destination address | ||||||||||||||||||||||||||||
| 161 | 9 | ▶ | if ($line =~ / ?DST=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 9 | $ds->{dst_addr} = $1; | |||||||||||||||||||||||||||
| 163 | 9 | $line =~ s/ ?DST=$1 //; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # length | ||||||||||||||||||||||||||||
| 167 | 9 | ▶ | if ($line =~ / ?LEN=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 9 | $ds->{len} = $1; | |||||||||||||||||||||||||||
| 169 | 9 | $line =~ s/ ?LEN=$1 //; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # type of service | ||||||||||||||||||||||||||||
| 173 | 9 | ▶ | if ($line =~ / ?TOS=(0x[0-9A-Z]{2}) /i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 9 | $ds->{tos} = $1; | |||||||||||||||||||||||||||
| 175 | 9 | $line =~ s/ ?TOS=$1 //; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # PREC? | ||||||||||||||||||||||||||||
| 179 | 9 | ▶ | if ($line =~ / ?PREC=(0x[0-9A-Z]{2}) /i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 9 | $ds->{prec} = $1; | |||||||||||||||||||||||||||
| 181 | 9 | $line =~ s/ ?PREC=$1 //; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # time to live | ||||||||||||||||||||||||||||
| 185 | 9 | ▶ | if ($line =~ / ?TTL=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 9 | $ds->{ttl} = $1; | |||||||||||||||||||||||||||
| 187 | 9 | $line =~ s/ ?TTL=$1 //; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # ip id | ||||||||||||||||||||||||||||
| 191 | 9 | ▶ | if ($line =~ / ?ID=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 9 | $ds->{id} = $1; | |||||||||||||||||||||||||||
| 193 | 9 | $line =~ s/ ?ID=$1 //; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # congestion | ||||||||||||||||||||||||||||
| 197 | 9 | ▶ | if ($line =~ /^CE /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 1 | push(@{$ds->{fragment_flags}}, "CE"); | |||||||||||||||||||||||||||
| 199 | 1 | $line =~ s/^CE //; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | # don't fragment | ||||||||||||||||||||||||||||
| 203 | 9 | ▶ | if ($line =~ /^DF /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 3 | push(@{$ds->{fragment_flags}}, "DF"); | |||||||||||||||||||||||||||
| 205 | 3 | $line =~ s/^DF //; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # more fragments | ||||||||||||||||||||||||||||
| 209 | 9 | ▶ | if ($line =~ /^MF /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 1 | push(@{$ds->{fragment_flags}}, "MF"); | |||||||||||||||||||||||||||
| 211 | 1 | $line =~ s/^MF //; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 9 | ▶ | print "IP done: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 9 | return ($line, $ds); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 4 | ▶ | sub _parseTCP { | ||||||||||||||||||||||||||
|
Subroutine
_parseTCP: called CC=18 SCAR=29.2
| |||||||||||||||||||||||||||||
| 220 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 221 | 4 | my $line = shift; | |||||||||||||||||||||||||||
| 222 | 4 | my $ds; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 4 | ▶ | print "TCP: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | # SPT=36073 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0 | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # source port | ||||||||||||||||||||||||||||
| 229 | 4 | ▶ | if ($line =~ /SPT=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 4 | $ds->{src_port} = $1; | |||||||||||||||||||||||||||
| 231 | 4 | $line =~ s/SPT=$1 //; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # destination port | ||||||||||||||||||||||||||||
| 235 | 4 | ▶ | if ($line =~ /DPT=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 4 | $ds->{dst_port} = $1; | |||||||||||||||||||||||||||
| 237 | 4 | $line =~ s/DPT=$1 //; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # window length | ||||||||||||||||||||||||||||
| 241 | 4 | ▶ | if ($line =~ /WINDOW=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 4 | $ds->{window} = $1; | |||||||||||||||||||||||||||
| 243 | 4 | $line =~ s/WINDOW=$1 //; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # reserved bits | ||||||||||||||||||||||||||||
| 247 | 4 | ▶ | if ($line =~ /RES=(0x[0-9A-Z]{2}) /i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 4 | $ds->{res} = $1; | |||||||||||||||||||||||||||
| 249 | 4 | $line =~ s/RES=$1 //; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | # flags | ||||||||||||||||||||||||||||
| 253 | # | ||||||||||||||||||||||||||||
| 254 | # CWR ECE URG ACK PSH RST SYN FIN | ||||||||||||||||||||||||||||
| 255 | # CWR - Congestion Window Reduced | ||||||||||||||||||||||||||||
| 256 | # ECE - Explicit Congestion Notification echo | ||||||||||||||||||||||||||||
| 257 | # URG - Urgent | ||||||||||||||||||||||||||||
| 258 | # ACK - Acknowledgement | ||||||||||||||||||||||||||||
| 259 | # PSH - Push | ||||||||||||||||||||||||||||
| 260 | # RST - Reset | ||||||||||||||||||||||||||||
| 261 | # SYN - Synchronize | ||||||||||||||||||||||||||||
| 262 | # FIN - Finished | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 4 | ▶ | if ($line =~ /CWR /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 2 | push(@{$ds->{flags}}, "CWR"); | |||||||||||||||||||||||||||
| 266 | 2 | $line =~ s/CWR //; | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 4 | ▶ | if ($line =~ /ECE /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 2 | push(@{$ds->{flags}}, "ECE"); | |||||||||||||||||||||||||||
| 271 | 2 | $line =~ s/ECE //; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 4 | ▶ | if ($line =~ /URG /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 2 | push(@{$ds->{flags}}, "URG"); | |||||||||||||||||||||||||||
| 276 | 2 | $line =~ s/URG //; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 4 | ▶ | if ($line =~ /ACK /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 3 | push(@{$ds->{flags}}, "ACK"); | |||||||||||||||||||||||||||
| 281 | 3 | $line =~ s/ACK //; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 4 | ▶ | if ($line =~ /PSH /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 2 | push(@{$ds->{flags}}, "PSH"); | |||||||||||||||||||||||||||
| 286 | 2 | $line =~ s/PSH //; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 4 | ▶ | if ($line =~ /RST /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 3 | push(@{$ds->{flags}}, "RST"); | |||||||||||||||||||||||||||
| 291 | 3 | $line =~ s/RST //; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 4 | ▶ | if ($line =~ /SYN /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 3 | push(@{$ds->{flags}}, "SYN"); | |||||||||||||||||||||||||||
| 296 | 3 | $line =~ s/SYN //; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 4 | ▶ | if ($line =~ /FIN /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 2 | push(@{$ds->{flags}}, "FIN"); | |||||||||||||||||||||||||||
| 301 | 2 | $line =~ s/FIN //; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | # urgent pointer | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 4 | ▶ | if ($line =~ /URGP=(\d+) ?/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 4 | $ds->{urgp} = $1; | |||||||||||||||||||||||||||
| 308 | 4 | $line =~ s/URGP=$1 ?//; | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 4 | ▶ | print "TCP done: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 4 | ▶ | if ($line and $line !~ /^\s+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line and not $line =~ /^\s+$/
MC/DC0%0/2
$line and not $line =~ /^\s+$/
$line
not $line =~ /^\s+$/
Truth table33%1/3
A and not(B)
A= $lineB= not $line =~ /^\s+$/
| |||||||||||||||||||||||||||||
| 314 | 0 | return ($ds, $line); | |||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||
| 316 | 4 | return ($ds, undef); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 2 | ▶ | sub _parseUDP { | ||||||||||||||||||||||||||
|
Subroutine
_parseUDP: called CC=8 SCAR=22.4
| |||||||||||||||||||||||||||||
| 321 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 322 | 2 | my $line = shift; | |||||||||||||||||||||||||||
| 323 | 2 | my $ds; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 2 | ▶ | print "UDP: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # SPT=10890 DPT=33440 LEN=12 | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | # source port | ||||||||||||||||||||||||||||
| 330 | 2 | ▶ | if ($line =~ /SPT=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 2 | $ds->{src_port} = $1; | |||||||||||||||||||||||||||
| 332 | 2 | $line =~ s/SPT=$1 //; | |||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | # destination port | ||||||||||||||||||||||||||||
| 336 | 2 | ▶ | if ($line =~ /DPT=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 2 | $ds->{dst_port} = $1; | |||||||||||||||||||||||||||
| 338 | 2 | $line =~ s/DPT=$1 //; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | # length | ||||||||||||||||||||||||||||
| 342 | 2 | ▶ | if ($line =~ /LEN=(\d+) ?/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 2 | $ds->{len} = $1; | |||||||||||||||||||||||||||
| 344 | 2 | $line =~ s/LEN=$1 ?//; | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 2 | ▶ | print "UDP done: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 2 | ▶ | if ($line and $line !~ /^\s+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line and not $line =~ /^\s+$/
MC/DC0%0/2
$line and not $line =~ /^\s+$/
$line
not $line =~ /^\s+$/
Truth table33%1/3
A and not(B)
A= $lineB= not $line =~ /^\s+$/
| |||||||||||||||||||||||||||||
| 350 | 0 | return ($ds, $line); | |||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||
| 352 | 2 | return ($ds, undef); | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 2 | ▶ | sub _parseICMP { | ||||||||||||||||||||||||||
|
Subroutine
_parseICMP: called CC=13 SCAR=26.4
| |||||||||||||||||||||||||||||
| 358 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 359 | 2 | my $line = shift; | |||||||||||||||||||||||||||
| 360 | 2 | my $ds; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 2 | ▶ | print "ICMP: [$line]\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 2 | ▶ | if ($line =~ /TYPE=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | 2 | $ds->{type} = $1; | |||||||||||||||||||||||||||
| 366 | 2 | $line =~ s/TYPE=$1 //; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 2 | ▶ | if ($line =~ /CODE=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 2 | $ds->{code} = $1; | |||||||||||||||||||||||||||
| 371 | 2 | $line =~ s/CODE=$1 //; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 2 | my $packet; | |||||||||||||||||||||||||||
| 375 | 2 | foreach my $type (@{$self->{icmp_types}}) { | |||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 6 | ▶ | if ($type == $ds->{type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 1 | ▶ | if ($line =~ /\[(.+)\]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 1 | $packet = $1; | |||||||||||||||||||||||||||
| 380 | 1 | $ds->{error_header} = $self->_parse($packet); | |||||||||||||||||||||||||||
| 381 | } else { | ||||||||||||||||||||||||||||
| 382 | 0 | carp("got a ICMP packet with type of $type, but couldn't " . | |||||||||||||||||||||||||||
| 383 | "extract the IP header..."); | ||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | # strip out the thing | ||||||||||||||||||||||||||||
| 389 | 2 | ▶ | if ($packet) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 1 | my $quoted = quotemeta($packet); | |||||||||||||||||||||||||||
| 391 | 1 | $line =~ s/\[$quoted\]//; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 2 | ▶ | if ($line =~ /ID=(\d+) /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 395 | 1 | $ds->{id} = $1; | |||||||||||||||||||||||||||
| 396 | 1 | $line =~ s/ID=$1 //; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 2 | ▶ | if ($line =~ /SEQ=(\d+) ?/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 1 | $ds->{seq} = $1; | |||||||||||||||||||||||||||
| 401 | 1 | $line =~ s/SEQ=$1 ?//; | |||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 2 | ▶ | print "ICMP done: ($line)\n" if $self->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 2 | ▶ | if ($line and $line !~ /^\s+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line and not $line =~ /^\s+$/
MC/DC0%0/2
$line and not $line =~ /^\s+$/
$line
not $line =~ /^\s+$/
Truth table33%1/3
A and not(B)
A= $lineB= not $line =~ /^\s+$/
| |||||||||||||||||||||||||||||
| 407 | 0 | return ($ds, $line); | |||||||||||||||||||||||||||
| 408 | } else { | ||||||||||||||||||||||||||||
| 409 | 2 | return ($ds, undef); | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 1 | ▶ | sub _parseUnknown { | ||||||||||||||||||||||||||
|
Subroutine
_parseUnknown: called CC=5 SCAR=17.4
| |||||||||||||||||||||||||||||
| 414 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 415 | 1 | my $line = shift; | |||||||||||||||||||||||||||
| 416 | 1 | my $proto; | |||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 1 | ▶ | if ($line =~ /PROTO=(\w+) ?/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 1 | $proto = (getprotobynumber($1))[0]; | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 1 | ▶ | if (not defined($proto)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | 1 | $proto = "unknown"; | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 1 | $line =~ s/PROTO=$1 ?//; | |||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 1 | ▶ | if ($line and $line !~ /^\s+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line and not $line =~ /^\s+$/
MC/DC0%0/2
$line and not $line =~ /^\s+$/
$line
not $line =~ /^\s+$/
Truth table33%1/3
A and not(B)
A= $lineB= not $line =~ /^\s+$/
| |||||||||||||||||||||||||||||
| 429 | 0 | return ($proto, $line); | |||||||||||||||||||||||||||
| 430 | } else { | ||||||||||||||||||||||||||||
| 431 | 1 | return ($proto, undef); | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 2 | 1; | |||||||||||||||||||||||||||
| 437 | __END__ | ||||||||||||||||||||||||||||