Changeset 1183
- Timestamp:
- 08/04/08 08:35:33 (1 year ago)
- Files:
-
- fwknop/branches/fwknop-redhat-integration/fwknopd (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fwknop/branches/fwknop-redhat-integration/fwknopd
r1174 r1183 46 46 use Net::IPv4Addr qw(ipv4_in_network); 47 47 use Net::Pcap; 48 use NetPacket::IP;49 use NetPacket::UDP;50 use NetPacket::TCP;51 use NetPacket::ICMP;52 use NetPacket::Ethernet;53 48 use IO::Socket; 54 49 use IO::Handle; … … 393 388 my $src_ip = ''; 394 389 my $proto = ''; 395 my $transport_ obj= '';390 my $transport_data = ''; 396 391 397 392 if ($debug) { … … 421 416 if ($config{'AUTH_MODE'} eq 'ULOG_PCAP') { 422 417 ### The ulogd pcap writer does not include link layer information 423 $ip = NetPacket::IP->decode($pkt) or return;418 $ip = &ip_decode($pkt) or return; 424 419 } else { 425 420 if ($config{'FIREWALL_TYPE'} eq 'ipfw' and $cmdline_intf eq 'lo0') { … … 429 424 $pkt =~ s/^.{4}// if $pkt =~ /^[^\x45].{3}\x45/; 430 425 431 $ip = NetPacket::IP->decode($pkt) or return;426 $ip = &ip_decode($pkt) or return; 432 427 } else { 433 428 if ($PCAP_COOKED_INTF) { 434 429 $ether_data = unpack("x[16]a*", $pkt); 435 430 } else { 436 $ether_data = NetPacket::Ethernet::strip($pkt) or return;437 } 438 $ip = NetPacket::IP->decode($ether_data) or return;431 $ether_data = ðernet_strip($pkt) or return; 432 } 433 $ip = &ip_decode($ether_data) or return; 439 434 } 440 435 } … … 447 442 448 443 if ($proto == 1) { 449 $transport_ obj = NetPacket::ICMP->decode($ip->{'data'});444 $transport_data = &icmp_decode_data($ip->{'data'}); 450 445 } elsif ($proto == 6) { 451 $transport_ obj = NetPacket::TCP->decode($ip->{'data'});446 $transport_data = &tcp_decode_data($ip->{'data'}); 452 447 } elsif ($proto == 17) { 453 $transport_ obj = NetPacket::UDP->decode($ip->{'data'});448 $transport_data = &udp_decode_data($ip->{'data'}); 454 449 } else { 455 450 return; … … 459 454 ### any valid SPA message will be longer than 10 bytes, but this 460 455 ### check is better than nothing 461 return unless defined $transport_obj->{'data'};456 return if $transport_data eq ""; 462 457 463 458 my $enc_msg_len = 0; 464 $enc_msg_len = length($transport_ obj->{'data'});459 $enc_msg_len = length($transport_data); 465 460 if (10 < $enc_msg_len and $enc_msg_len < 1500) { 466 461 print STDERR localtime() . " [+] Data len: $enc_msg_len bytes\n" … … 474 469 if ($debug) { 475 470 ### make sure not to print non-printable stuff 476 my $data_tmp = $transport_ obj->{'data'};471 my $data_tmp = $transport_data; 477 472 $data_tmp =~ s/[^\x20-\x7e]/NA/g; 478 473 print STDERR localtime() . … … 483 478 print STDERR localtime() . 484 479 " Raw packet data (hex dump, minus packet headers):\n"; 485 &hex_dump($transport_ obj->{'data'});480 &hex_dump($transport_data); 486 481 } 487 482 } … … 489 484 ### see if this packet is worthy of being granted access through 490 485 ### the firewall 491 &SPA_check_grant_access($src_ip, $enc_msg_len, $transport_ obj->{'data'});486 &SPA_check_grant_access($src_ip, $enc_msg_len, $transport_data); 492 487 493 488 &collect_warn_die_msgs(); 494 489 495 490 return; 491 } 492 493 sub ethernet_strip() { 494 my $pkt = shift; 495 496 ### Silently return '' for short frames 497 return substr($pkt, 14); 498 } 499 500 sub ip_addr_bytes_to_string() { 501 my $bytes = shift; 502 503 my ($a, $b, $c, $d) = unpack('C[4]', $bytes); 504 return "$a.$b.$c.$d"; 505 } 506 507 sub ip_decode() { 508 my $pkt = shift; 509 510 my $ip = {}; 511 (my $ver_ihl, $ip->{'tos'}, $ip->{'len'}, $ip->{'id'}, my $flags_frag, 512 $ip->{'ttl'}, $ip->{'proto'}, $ip->{'cksum'}, my $src_ip, my $dest_ip) 513 = unpack("CCnnnCCna[4]a[4]", $pkt); 514 $ip->{'ver'} = $ver_ihl >> 4; 515 $ip->{'hlen'} = $ver_ihl & 0x0F; 516 $ip->{'flags'} = $flags_frag >> 13; 517 $ip->{'foffset'} = ($flags_frag & 0x1FFF) * 8; 518 $ip->{'src_ip'} = &ip_addr_bytes_to_string($src_ip); 519 $ip->{'dest_ip'} = &ip_addr_bytes_to_string($dest_ip); 520 my $data_start = $ip->{'hlen'} * 4; 521 if ($data_start < 20) { 522 $data_start = 20; 523 } 524 $ip->{'data'} = substr($pkt, $data_start); 525 return $ip; 526 } 527 528 sub icmp_decode_data() { 529 my $icmp = shift; 530 531 ### Silently return '' for short packets 532 return substr($icmp, 4); 533 } 534 535 sub tcp_decode_data() { 536 my $tcp = shift; 537 538 ### Silently return '' for short packets 539 if (length($tcp) < 20) { 540 return ''; 541 } 542 my $data_start = 4 * (ord(substr($tcp, 12, 1)) >> 4); 543 if ($data_start < 20) { 544 $data_start = 20; 545 } 546 return substr($tcp, $data_start); 547 } 548 549 sub udp_decode_data() { 550 my $udp = shift; 551 552 ### Silently return '' for short packets 553 return substr($udp, 8); 496 554 } 497 555
