Changeset 1201
- Timestamp:
- 08/12/08 22:03:02 (4 months ago)
- Files:
-
- fwknop/trunk/CREDITS (modified) (1 diff)
- fwknop/trunk/ChangeLog (modified) (1 diff)
- fwknop/trunk/Class-MethodMaker (deleted)
- fwknop/trunk/Crypt-CBC (deleted)
- fwknop/trunk/Crypt-Rijndael (deleted)
- fwknop/trunk/Digest-SHA (deleted)
- fwknop/trunk/GnuPG-Interface (deleted)
- fwknop/trunk/INSTALL (modified) (1 diff)
- fwknop/trunk/IPTables-ChainMgr (deleted)
- fwknop/trunk/IPTables-Parse (deleted)
- fwknop/trunk/Makefile (modified) (1 diff)
- fwknop/trunk/Net-IPv4Addr (deleted)
- fwknop/trunk/Net-Pcap (deleted)
- fwknop/trunk/Net-Ping-External (deleted)
- fwknop/trunk/Net-RawIP (deleted)
- fwknop/trunk/NetPacket (deleted)
- fwknop/trunk/TermReadKey (deleted)
- fwknop/trunk/Unix-Syslog (deleted)
- fwknop/trunk/deps (copied) (copied from fwknop/branches/fwknop-redhat-integration/deps)
- fwknop/trunk/fwknop (modified) (18 diffs)
- fwknop/trunk/fwknop_funcs.c (modified) (1 diff)
- fwknop/trunk/fwknop_serv (modified) (4 diffs)
- fwknop/trunk/fwknopd (modified) (27 diffs)
- fwknop/trunk/init-scripts/fwknop-init.redhat (modified) (4 diffs)
- fwknop/trunk/install.pl (modified) (4 diffs)
- fwknop/trunk/knoptm (modified) (7 diffs)
- fwknop/trunk/packaging/fwknop-nodeps.spec (copied) (copied from fwknop/branches/fwknop-redhat-integration/packaging/fwknop-nodeps.spec)
- fwknop/trunk/packaging/fwknop.spec (modified) (10 diffs)
- fwknop/trunk/test/fwknop_test.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fwknop/trunk/CREDITS
r1170 r1201 204 204 - Suggested that the "C" locale be set by default so that gpg process 205 205 output would always be correctly interpreted. 206 207 Mirek Trmac 208 - Contributed patches to allow fwknop to be bundled with Fedora. These 209 patches included the following, and all were sponsored by Red Hat: 210 211 Updates to fwknopd to remove the NetPacket module as a dependency 212 (this is a particularly important update since it assists with getting 213 fwknop bundled with Debian as well). The patch manually decodes the 214 network and transport layer headers. 215 A patch to make the fwknop init script not start fwknopd by default 216 on Red Hat systems. This patch also supports Fedora init script 217 conventions better (i.e. fwknop instead of the fwknopd name for the lock 218 file in /var/lock/subsys). 219 Updated the fwknop Makefile to respect the OPTS variable which is used 220 in the RPM spec file. 221 Bugfix in fwknop_serv to support the variable expansion code from 222 fwknopd. This was important for the TCPSERV_PID_FILE file which is 223 defined as $FWKNOP_RUN_DIR/fwknop_serv.pid. 224 Updated fwknopd to use the Net::Pcap API valid in Net::Pcap 0.14 for 225 the datalink() function (used to detect the datalink layer type). fwknop/trunk/ChangeLog
r1173 r1201 1 fwknop-1.9.7 (08//2008): 2 - Mirek Trmac from Red Hat contributed several patches so that fwknop can 3 be bundled within the Fedora Linux distribution. These patches 4 implemented the following changes: 5 6 Updates to fwknopd to remove the NetPacket module as a dependency 7 (this is a particularly important update since it assists with getting 8 fwknop bundled with Debian as well). The patch manually decodes the 9 network and transport layer headers. 10 A patch to make the fwknop init script not start fwknopd by default 11 on Red Hat systems. This patch also supports Fedora init script 12 conventions better (i.e. fwknop instead of the fwknopd name for the lock 13 file in /var/lock/subsys). 14 Updated the fwknop Makefile to respect the OPTS variable which is used 15 in the RPM spec file. 16 Bugfix in fwknop_serv to support the variable expansion code from 17 fwknopd. This was important for the TCPSERV_PID_FILE file which is 18 defined as $FWKNOP_RUN_DIR/fwknop_serv.pid. 19 Updated fwknopd to use the Net::Pcap API valid in Net::Pcap-0.14 for 20 the datalink() function (used to detect the datalink layer type). 21 22 - Updated fwknop, fwknopd, and knoptm to import perl modules out of the 23 /usr/lib/fwknop/ directory if it exists. This allows the perl module 24 path to be manipulated via the --Lib-dir command line argument and 25 'require' statements instead of the old 'use module' strategy. 26 1 27 fwknop-1.9.6 (07/18/2008): 2 28 - SPA packets are base64-encoded by the fwknop client, and this encoding fwknop/trunk/INSTALL
r679 r1201 10 10 this case fwknop can only be used as an authentication client against an 11 11 fwknop server on a different system. 12 13 DEPENDENCIES: 14 fwknop requires several perl modules that may or may not already be 15 installed on your Linux system. These modules are included in the deps/ 16 directory in the fwknop sources (unless you have installed one of the -nodeps 17 tarballs), and the list of modules is: 18 19 Class-MethodMaker 20 Crypt-CBC 21 Crypt-Rijndael 22 Digest-SHA 23 GnuPG-Interface 24 IPTables-ChainMgr 25 IPTables-Parse 26 Net-IPv4Addr 27 Net-Pcap 28 Net-RawIP 29 TermReadKey 30 Unix-Syslog fwknop/trunk/Makefile
r512 r1201 25 25 # 26 26 27 OPTS = -Wall -O 28 27 29 ### default 28 30 all : knopmd.c knopwatchd.c fwknop_funcs.c strlcpy.c strlcat.c fwknop.h 29 /usr/bin/gcc -Wall -Oknopmd.c fwknop_funcs.c strlcpy.c strlcat.c -o knopmd30 /usr/bin/gcc -Wall -Oknopwatchd.c fwknop_funcs.c strlcpy.c strlcat.c -o knopwatchd31 /usr/bin/gcc $(OPTS) knopmd.c fwknop_funcs.c strlcpy.c strlcat.c -o knopmd 32 /usr/bin/gcc $(OPTS) knopwatchd.c fwknop_funcs.c strlcpy.c strlcat.c -o knopwatchd 31 33 32 34 ### debug mode fwknop/trunk/fwknop
r1174 r1201 5 5 # File: fwknop 6 6 # 7 # URL: http://www.cipherdyne.org/fwknop 8 # 7 9 # Purpose: fwknop implements an authorization scheme known as Single Packet 8 # Authorization (SPA) that requires only a single encrypted packet 9 # to communicate various pieces of information including desired 10 # access through an iptables policy and/or specific commands to 11 # execute on the target system. The main application of this 12 # program is to protect services such as SSH with an additional 13 # layer of security in order to make the exploitation of 14 # vulnerabilities (both 0-day and unpatched code) much more 15 # difficult. For more information, see the fwknop(8) man page. 10 # Authorization (SPA) that requires only a single encrypted packet to 11 # communicate various pieces of information including desired access 12 # through an iptables/ipfw policy and/or specific commands to execute 13 # on the target system. The main application of this program is to 14 # protect services such as SSH with an additional layer of security 15 # in order to make the exploitation of vulnerabilities (both 0-day 16 # and unpatched code) much more difficult. fwknop also supports 17 # encrypted port knocking, but this is a legacy authentication mode 18 # when compared to SPA. 19 # 20 # More information can be found in the fwknop(8) and fwknopd(8) man 21 # pages, and also online here: 22 # 23 # http://www.cipherdyne.org/fwknop/docs/ 16 24 # 17 25 # Author: Michael Rash (mbr@cipherdyne.org) … … 21 29 # Copyright (C) 2004-2008 Michael Rash (mbr@cipherdyne.org) 22 30 # 23 # License (GNU Public License):31 # License - GNU Public License version 2: 24 32 # 25 33 # This program is distributed in the hope that it will be useful, … … 38 46 # 39 47 40 use lib '/usr/lib/fwknop';41 use Crypt::CBC;42 use Net::IPv4Addr qw(ipv4_in_network);43 use Net::Ping::External qw(ping);44 48 use IO::Socket; 45 49 use IO::Handle; … … 47 51 use Data::Dumper; 48 52 use POSIX; 49 use Term::ReadKey;50 53 use Getopt::Long; 51 54 use strict; … … 56 59 ($rev_num) = $revision_svn =~ m|\$Rev.*:\s+(\S+)|; 57 60 61 my $lib_dir = '/usr/lib/fwknop'; 58 62 my $print_version = 0; 59 63 my $print_help = 0; … … 258 262 $digest_type = $SHA256_DIGEST if $use_sha256; 259 263 264 ### import fwknop perl modules 265 &import_perl_modules(); 266 260 267 ### this is only necessary for older versions of perl (newer versions 261 268 ### call srand() automatically at the first usage of rand() if srand() … … 812 819 sub pcap_Rijndael_encrypt_msg() { 813 820 my $msg = shift; 821 822 require Crypt::CBC; 814 823 815 824 my $cipher = Crypt::CBC->new({ … … 1025 1034 ### the remote firewall is configued to not reply at all 1026 1035 if ($proto eq 'icmp') { 1036 require Net::Ping::External; 1037 Net::Ping::External->import(qw/ping/); 1027 1038 print " icmp echo request -> $knock_dst\n"; 1028 1039 ping(hostname => "$knock_dst", count => 1, timeout => 1); … … 1057 1068 my @encrypted_seq = (); 1058 1069 1070 require Crypt::CBC; 1071 1059 1072 my $cipher = Crypt::CBC->new({ 1060 1073 'key' => $enc_key, … … 1289 1302 my $try = 0; 1290 1303 my $max_tries = 20; 1291 ReadMode 'noecho';1304 ReadMode('noecho'); 1292 1305 KEY: while (1) { 1293 1306 $try++; … … 1299 1312 print "Encryption Key: "; 1300 1313 } 1301 my $ans = ReadLine 0;1314 my $ans = ReadLine(0); 1302 1315 next KEY unless defined $ans; 1303 1316 next KEY unless $ans =~ /\S/; … … 1316 1329 } 1317 1330 } 1318 ReadMode 'normal';1331 ReadMode('normal'); 1319 1332 print "\n"; 1320 1333 … … 1333 1346 } 1334 1347 return; 1348 } 1349 1350 sub import_perl_modules() { 1351 1352 my $mod_paths_ar = &get_mod_paths(); 1353 1354 if ($#$mod_paths_ar > -1) { ### /usr/lib/fwknop/ exists 1355 push @$mod_paths_ar, @INC; 1356 splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar; 1357 } 1358 1359 if ($debug) { 1360 print STDERR "[+] import_perl_modules(): The \@INC array:\n"; 1361 print STDERR "$_\n" for @INC; 1362 } 1363 1364 require Net::IPv4Addr; 1365 require Term::ReadKey; 1366 1367 Term::ReadKey->import(qw/ReadMode ReadLine/); 1368 Net::IPv4Addr->import(qw/ipv4_in_network/); 1369 1370 return; 1371 } 1372 1373 sub get_mod_paths() { 1374 1375 my @paths = (); 1376 1377 unless (-d $lib_dir) { 1378 my $dir_tmp = $lib_dir; 1379 $dir_tmp =~ s|lib/|lib64/|; 1380 if (-d $dir_tmp) { 1381 $lib_dir = $dir_tmp; 1382 } else { 1383 return []; 1384 } 1385 } 1386 1387 opendir D, $lib_dir or die "[*] Could not open $lib_dir: $!"; 1388 my @dirs = readdir D; 1389 closedir D; 1390 1391 push @paths, $lib_dir; 1392 1393 for my $dir (@dirs) { 1394 ### get directories like "/usr/lib/fwknop/x86_64-linux" 1395 next unless -d "$lib_dir/$dir"; 1396 push @paths, "$lib_dir/$dir" 1397 if $dir =~ m|linux| or $dir =~ m|thread|; 1398 } 1399 return \@paths; 1335 1400 } 1336 1401 … … 1432 1497 sub handle_server_auth_method() { 1433 1498 if (lc($server_auth_method) eq 'crypt') { 1434 ReadMode 'noecho';1499 ReadMode('noecho'); 1435 1500 while (1) { 1436 1501 $quiet == 1 ? print "UNIX crypt() password: " 1437 1502 : print " UNIX crypt() password: "; 1438 my $ans = ReadLine 0;1503 my $ans = ReadLine(0); 1439 1504 chomp $ans; 1440 1505 next unless $ans =~ /\S/; … … 1442 1507 last; 1443 1508 } 1444 ReadMode 'normal';1509 ReadMode('normal'); 1445 1510 print "\n"; 1446 1511 return; … … 1550 1615 'Include-gpg-prefix' => \$include_base64_gnupg_prefix, 1551 1616 'Test-mode' => \$test_mode, 1617 'Lib-dir=s' => \$lib_dir, 1552 1618 'LC_ALL=s' => \$locale, 1553 1619 'locale=s' => \$locale, … … 1795 1861 arguments as in the previous invocation. 1796 1862 The args are stored in ~/fwknop.run. 1797 - L, --Last-host <host>- Run last command line arguments for <host>.1863 --Last-host <host> - Run last command line arguments for <host>. 1798 1864 --gpg-signing-key <key ID> - ID for key used to sign GnuPG encrypted 1799 1865 message (e.g. "0xABCD1234"). … … 1924 1990 knock sequence (synonym for -D). 1925 1991 -d, --debug - Run fwknop in debugging mode. 1992 --Lib-dir <path> - Path to the perl modules directory (not 1993 usually necessary). 1926 1994 --locale <locale> - Manually define a locale setting. 1927 1995 --no-locale - Don't set the locale to anything (the fwknop/trunk/fwknop_funcs.c
r1144 r1201 60 60 61 61 /* read the first line of the pid_file, which will contain the 62 * process id of any running fwk mdprocess */62 * process id of any running fwknop process */ 63 63 if (fgets(pid_line, MAX_PID_SIZE+1, pidfile_ptr) == NULL) { 64 64 return; fwknop/trunk/fwknop_serv
r1174 r1201 62 62 63 63 ### trivial loop; we just want the local TCP stack to accept connections; 64 ### fwknopd gets itdata from pcap anyway64 ### fwknopd gets data from pcap anyway 65 65 while (my $client = $server->accept()) { 66 66 … … 94 94 ### import config 95 95 &import_config(); 96 97 ### expand any embedded vars within config values 98 &expand_vars(); 96 99 97 100 ### make sure all the vars we need are actually in the config file. … … 170 173 while (<C>) { 171 174 next if /^\s*#/; 172 for my $var (@required_vars) { 173 if (/^\s*$var\s+(\S+);/) { 174 $config{$var} = $1; 175 } 175 if (/^\s*(\S+)\s+(\S+);/) { 176 $config{$1} = $2; 176 177 } 177 178 } … … 179 180 return; 180 181 } 182 183 sub expand_vars() { 184 185 my $has_sub_var = 1; 186 my $resolve_ctr = 0; 187 188 while ($has_sub_var) { 189 $resolve_ctr++; 190 $has_sub_var = 0; 191 if ($resolve_ctr >= 20) { 192 die "[*] Exceeded maximum variable resolution counter."; 193 } 194 for my $var (keys %config) { 195 my $val = $config{$var}; 196 if ($val =~ m|\$(\w+)|) { 197 my $sub_var = $1; 198 die "[*] sub-ver $sub_var not allowed within same ", 199 "variable $var" if $sub_var eq $var; 200 if (defined $config{$sub_var}) { 201 $val =~ s|\$$sub_var|$config{$sub_var}|; 202 $config{$var} = $val; 203 } else { 204 die "[*] sub-var \"$sub_var\" not defined in ", 205 "config for var: $var." 206 } 207 $has_sub_var = 1; 208 } 209 } 210 } 211 return; 212 } fwknop/trunk/fwknopd
r1174 r1201 18 18 # page. 19 19 # 20 # More information can be found in the fwknop(8) and fwknopd(8) man 21 # pages, and also online here: 22 # 23 # http://www.cipherdyne.org/fwknop/docs/ 24 # 20 25 # Author: Michael Rash (mbr@cipherdyne.org) 21 26 # … … 24 29 # Copyright (C) 2004-2008 Michael Rash (mbr@cipherdyne.org) 25 30 # 26 # License (GNU Public License):31 # License - GNU Public License version 2: 27 32 # 28 33 # This program is distributed in the hope that it will be useful, … … 41 46 # 42 47 43 use lib '/usr/lib/fwknop';44 use Crypt::CBC;45 use Unix::Syslog qw(:subs :macros);46 use Net::IPv4Addr qw(ipv4_in_network);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; … … 93 88 my $packet_ctr = 0; 94 89 my $packet_limit = 0; 90 my $lib_dir = ''; 95 91 my $fw_list = 0; 96 92 my $fw_type = ''; … … 100 96 my $test_mode = 0; 101 97 my $verbose = 0; 102 my $ use_gpg= 0;98 my $imported_gpg = 0; 103 99 my $os_ipt_log = ''; 104 100 my $cmdline_intf = ''; … … 110 106 my $build_ipt_config = 0; 111 107 my $skipped_first_loop = 0; 108 my $imported_crypt_cbc = 0; 112 109 my $pcap_sleep_interval = 1; ### seconds 113 110 my $imported_iptables_modules = 0; … … 214 211 'T' => $tcp_timestamp_type 215 212 ); 213 214 my $ETH_HDR_LEN = 14; 215 my $MIN_IP_HDR_LEN = 20; 216 my $MIN_ICMP_HDR_LEN = 4; 217 my $UDP_HDR_LEN = 8; 218 my $MIN_TCP_HDR_LEN = 20; 216 219 217 220 my %access_keys = ( … … 286 289 ### we are parsing the pcap file created by the ulogd pcap 287 290 ### writer, or in sniffing mode against an interface 291 292 require Net::Pcap; 293 288 294 &pcap_loop(); 289 295 } … … 304 310 eval { 305 311 if (not $PCAP_COOKED_INTF and $Net::Pcap::VERSION > 0.05) { 306 if (Net::Pcap:: pcap_datalink_val_to_name(307 Net::Pcap:: pcap_datalink($pcap_t)) eq 'LINUX_SLL') {312 if (Net::Pcap::datalink_val_to_name( 313 Net::Pcap::datalink($pcap_t)) eq 'LINUX_SLL') { 308 314 print STDERR "[+] Detected Linux Cooked Interface.\n" if $debug; 309 315 $PCAP_COOKED_INTF = 1; … … 393 399 my $src_ip = ''; 394 400 my $proto = ''; 395 my $transport_ obj= '';401 my $transport_data = ''; 396 402 397 403 if ($debug) { … … 421 427 if ($config{'AUTH_MODE'} eq 'ULOG_PCAP') { 422 428 ### The ulogd pcap writer does not include link layer information 423 $ip = NetPacket::IP->decode($pkt) or return;429 $ip = &ip_decode($pkt) or return; 424 430 } else { 425 431 if ($config{'FIREWALL_TYPE'} eq 'ipfw' and $cmdline_intf eq 'lo0') { … … 429 435 $pkt =~ s/^.{4}// if $pkt =~ /^[^\x45].{3}\x45/; 430 436 431 $ip = NetPacket::IP->decode($pkt) or return;437 $ip = &ip_decode($pkt) or return; 432 438 } else { 433 439 if ($PCAP_COOKED_INTF) { 434 440 $ether_data = unpack("x[16]a*", $pkt); 435 441 } else { 436 $ether_data = NetPacket::Ethernet::strip($pkt) or return;437 } 438 $ip = NetPacket::IP->decode($ether_data) or return;442 $ether_data = ðernet_strip($pkt) or return; 443 } 444 $ip = &ip_decode($ether_data) or return; 439 445 } 440 446 } … … 447 453 448 454 if ($proto == 1) { 449 $transport_ obj = NetPacket::ICMP->decode($ip->{'data'});455 $transport_data = &icmp_decode_data($ip->{'data'}); 450 456 } elsif ($proto == 6) { 451 $transport_ obj = NetPacket::TCP->decode($ip->{'data'});457 $transport_data = &tcp_decode_data($ip->{'data'}); 452 458 } elsif ($proto == 17) { 453 $transport_ obj = NetPacket::UDP->decode($ip->{'data'});459 $transport_data = &udp_decode_data($ip->{'data'}); 454 460 } else { 455 461 return; … … 459 465 ### any valid SPA message will be longer than 10 bytes, but this 460 466 ### check is better than nothing 461 return unless defined $transport_obj->{'data'};467 return if $transport_data eq ""; 462 468 463 469 my $enc_msg_len = 0; 464 $enc_msg_len = length($transport_ obj->{'data'});470 $enc_msg_len = length($transport_data); 465 471 if (10 < $enc_msg_len and $enc_msg_len < 1500) { 466 472 print STDERR localtime() . " [+] Data len: $enc_msg_len bytes\n" … … 474 480 if ($debug) { 475 481 ### make sure not to print non-printable stuff 476 my $data_tmp = $transport_ obj->{'data'};482 my $data_tmp = $transport_data; 477 483 $data_tmp =~ s/[^\x20-\x7e]/NA/g; 478 484 print STDERR localtime() . … … 483 489 print STDERR localtime() . 484 490 " Raw packet data (hex dump, minus packet headers):\n"; 485 &hex_dump($transport_ obj->{'data'});491 &hex_dump($transport_data); 486 492 } 487 493 } … … 489 495 ### see if this packet is worthy of being granted access through 490 496 ### the firewall 491 &SPA_check_grant_access($src_ip, $enc_msg_len, $transport_ obj->{'data'});497 &SPA_check_grant_access($src_ip, $enc_msg_len, $transport_data); 492 498 493 499 &collect_warn_die_msgs(); 494 500 495 501 return; 502 } 503 504 sub ethernet_strip() { 505 my $pkt = shift; 506 507 my $eth_data = ''; 508 509 if (length($pkt) >= $ETH_HDR_LEN) { 510 $eth_data = substr($pkt, $ETH_HDR_LEN); 511 } 512 ### Silently return '' for short frames 513 return $eth_data; 514 } 515 516 sub ip_addr_bytes_to_string() { 517 my $bytes = shift; 518 519 my ($a, $b, $c, $d) = unpack('C[4]', $bytes); 520 return "$a.$b.$c.$d"; 521 } 522 523 sub ip_decode() { 524 my $pkt = shift; 525 526 my $ip = {}; 527 if (length($pkt) >= $MIN_IP_HDR_LEN and $pkt =~ /^\x45/) { 528 (my $ver_ihl, $ip->{'tos'}, $ip->{'len'}, $ip->{'id'}, my $flags_frag, 529 $ip->{'ttl'}, $ip->{'proto'}, $ip->{'cksum'}, my $src_ip, my $dest_ip) 530 = unpack("CCnnnCCna[4]a[4]", $pkt); 531 $ip->{'ver'} = $ver_ihl >> 4; 532 $ip->{'hlen'} = $ver_ihl & 0x0F; 533 $ip->{'flags'} = $flags_frag >> 13; 534 $ip->{'foffset'} = ($flags_frag & 0x1FFF) * 8; 535 $ip->{'src_ip'} = &ip_addr_bytes_to_string($src_ip); 536 $ip->{'dest_ip'} = &ip_addr_bytes_to_string($dest_ip); 537 my $data_start = $ip->{'hlen'} * 4; 538 if ($data_start >= $MIN_IP_HDR_LEN) { 539 $ip->{'data'} = substr($pkt, $data_start); 540 } 541 } 542 return $ip; 543 } 544 545 sub icmp_decode_data() { 546 my $icmp = shift; 547 548 my $icmp_data = ''; 549 if (length($icmp) >= $MIN_ICMP_HDR_LEN) { 550 $icmp_data = substr($icmp, $MIN_ICMP_HDR_LEN); 551 } 552 ### Silently return '' for short packets 553 return $icmp_data; 554 } 555 556 sub tcp_decode_data() { 557 my $tcp = shift; 558 559 my $tcp_data = ''; 560 561 if (length($tcp) >= $MIN_TCP_HDR_LEN) { 562 563 my $data_start = 4 * (ord(substr($tcp, 12, 1)) >> 4); 564 if ($data_start >= $MIN_TCP_HDR_LEN) { 565 $tcp_data = substr($tcp, $data_start); 566 } 567 } 568 ### Silently return '' for short packets 569 return $tcp_data; 570 } 571 572 sub udp_decode_data() { 573 my $udp = shift; 574 575 my $udp_data = ''; 576 if (length($udp) >= $UDP_HDR_LEN) { 577 $udp_data = substr($udp, $UDP_HDR_LEN); 578 } 579 ### Silently return '' for short packets 580 return $udp_data; 496 581 } 497 582 … … 2299 2384 &hex_dump(decode_base64($msg)); 2300 2385 } 2386 2301 2387 my $cipher = Crypt::CBC->new({ 2302 2388 'key' => $enc_key, … … 3274 3360 $access_hsh{'DATA_COLLECT_MODE'} = $ENCRYPT_SEQUENCE; 3275 3361 } elsif ($line =~ /^\s*KEY:\s*(.*)\s*;/) { 3362 require Crypt::CBC unless $imported_crypt_cbc; 3363 $imported_crypt_cbc = 1; 3276 3364 $access_hsh{'KEY'} = $1; 3277 3365 ### pad with zeros to the key size … … 3280 3368 } 3281 3369 } elsif ($line =~ /^\s*GPG_REMOTE_ID:\s*(.*)\s*;/) { 3282 require GnuPG::Interface unless $ use_gpg;3283 $ use_gpg = 1;3370 require GnuPG::Interface unless $imported_gpg; 3371 $imported_gpg = 1; 3284 3372 my @arr = split /\s*\,\s*/, $1; 3285 3373 for my $gpg_key_id (@arr) { … … 3287 3375 } 3288 3376 } elsif ($line =~ /^\s*GPG_DECRYPT_ID:\s*(.*)\s*;/) { 3289 require GnuPG::Interface unless $ use_gpg;3290 $ use_gpg = 1;3377 require GnuPG::Interface unless $imported_gpg; 3378 $imported_gpg = 1; 3291 3379 $access_hsh{'GPG_DECRYPT_ID'} = $1; 3292 3380 } elsif ($line =~ /^\s*GPG_DECRYPT_PW:\s*(.*)\s*;/) { 3293 require GnuPG::Interface unless $ use_gpg;3294 $ use_gpg = 1;3381 require GnuPG::Interface unless $imported_gpg; 3382 $imported_gpg = 1; 3295 3383 $access_hsh{'GPG_DECRYPT_PW'} = $1; 3296 3384 } elsif ($line =~ /^\s*GPG_HOME_DIR:\s*(\S+)\s*;/) { 3297 require GnuPG::Interface unless $ use_gpg;3298 $ use_gpg = 1;3385 require GnuPG::Interface unless $imported_gpg; 3386 $imported_gpg = 1; 3299 3387 $access_hsh{'GPG_HOME_DIR'} = $1; 3300 3388 } elsif ($line =~ /^\s*FILE_PCAP\s*;/) { … … 3776 3864 'LC_ALL=s' => \$cmdline_locale, 3777 3865 'locale=s' => \$cmdline_locale, 3866 'Lib-dir=s' => \$lib_dir, 3778 3867 'no-LC_ALL' => \$no_locale, 3779 3868 'no-locale' => \$no_locale, … … 3956 4045 ### make sure command paths are correct 3957 4046 &check_commands() unless $os_fprint_only; 4047 4048 ### import fwknop perl modules 4049 &import_perl_modules(); 3958 4050 3959 4051 if ($fw_del_ip) { … … 4653 4745 } 4654 4746 4747 sub import_perl_modules() { 4748 4749 my $mod_paths_ar = &get_mod_paths(); 4750 4751 if ($#$mod_paths_ar > -1) { ### /usr/lib/fwknop/ exists 4752 push @$mod_paths_ar, @INC; 4753 splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar; 4754 } 4755 4756 if ($debug) { 4757 print STDERR "[+] import_perl_modules(): The \@INC array:\n"; 4758 print STDERR "$_\n" for @INC; 4759 } 4760 4761 require Unix::Syslog unless $config{'ALERTING_METHODS'} =~ /no.?syslog/i; 4762 4763 Unix::Syslog->import(qw(:subs :macros)) 4764 unless $config{'ALERTING_METHODS'} =~ /no.?syslog/i; 4765 4766 require Net::IPv4Addr; 4767 Net::IPv4Addr->import(qw/ipv4_in_network/); 4768 4769 return; 4770 } 4771 4772 sub get_mod_paths() { 4773 4774 my @paths = (); 4775 4776 $config{'FWKNOP_MOD_DIR'} = $lib_dir if $lib_dir; 4777 4778 unless (-d $config{'FWKNOP_MOD_DIR'}) { 4779 my $dir_tmp = $config{'FWKNOP_MOD_DIR'}; 4780 $dir_tmp =~ s|lib/|lib64/|; 4781 if (-d $dir_tmp) { 4782 $config{'FWKNOP_MOD_DIR'} = $dir_tmp; 4783 } else { 4784 return []; 4785 } 4786 } 4787 4788 opendir D, $config{'FWKNOP_MOD_DIR'} 4789 or die "[*] Could not open $config{'FWKNOP_MOD_DIR'}: $!"; 4790 my @dirs = readdir D; 4791 closedir D; 4792 4793 push @paths, $config{'FWKNOP_MOD_DIR'}; 4794 4795 for my $dir (@dirs) { 4796 ### get directories like "/usr/lib/fwknop/x86_64-linux" 4797 next unless -d "$config{'FWKNOP_MOD_DIR'}/$dir"; 4798 push @paths, "$config{'FWKNOP_MOD_DIR'}/$dir" 4799 if $dir =~ m|linux| or $dir =~ m|thread|; 4800 } 4801 return \@paths; 4802 } 4803 4655 4804 sub import_digests() { 4656 4805 … … 4938 5087 SNAT_TRANSLATE_IP PROC_IP_FORWARD_FILE ENABLE_PROC_IP_FORWARD 4939 5088 MIN_SPA_PKT_LEN ENABLE_IPT_LOCAL_NAT LOCALE ENABLE_SYSLOG_FILE 4940 IPT_SYSLOG_FILE 5089 IPT_SYSLOG_FILE FWKNOP_MOD_DIR 4941 5090 ) { 4942 5091 die "[*] Required variable $var is not defined in $config_file" … … 4989 5138 key information) when running in --debug 4990 5139 and --verbose mode. 4991 - L, --Linux-cooked-intf- Force fwknopd to assume that the sniffing5140 --Linux-cooked-intf - Force fwknopd to assume that the sniffing 4992 5141 interface is a "Linux Cooked" interface. 4993 5142 This is useful when fwknopd uses a version … … 4995 5144 pcap_datalink_val_to_name() function or 4996 5145 have the pcap_datali.al file. 5146 --Lib-dir <path> - Path to the perl modules directory (not 5147 usually necessary). 4997 5148 -d, --debug - Run fwknopd in debugging mode. 4998 5149 --locale <locale> - Manually define a locale setting. fwknop/trunk/init-scripts/fwknop-init.redhat
r474 r1201 3 3 # Startup script for fwknop 4 4 # 5 # chkconfig: 34599 055 # chkconfig: - 99 05 6 6 # description: The FireWall KNock OPerator (fwknop) 7 7 # processname: fwknop … … 27 27 echo 28 28 if [ $RETVAL -eq 0 ]; then 29 touch /var/lock/subsys/fwknop d29 touch /var/lock/subsys/fwknop 30 30 fi 31 31 ;; … … 37 37 killproc fwknopd 38 38 RETVAL=$? 39 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/fwknop d39 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/fwknop 40 40 echo 41 41 if [ -f /var/run/fwknop/knopmd.pid ]; then … … 68 68 restart 69 69 ;; 70 condrestart )71 [ -f /var/lock/subsys/fwknop d] && restart || :70 condrestart|try-restart) 71 [ -f /var/lock/subsys/fwknop ] && restart || : 72 72 ;; 73 73 *) 74 74 echo "Usage: fwknop {start|stop|status|restart|reload|condrestart}" 75 exit 175 exit 3 76 76 esac fwknop/trunk/install.pl
r1150 r1201 69 69 my $data_method = ''; 70 70 my $runlevel = -1; 71 my $deps_dir = 'deps'; 71 72 my $init_dir = '/etc/init.d'; 72 73 my $init_name = 'fwknop'; … … 240 241 &import_config(); 241 242 243 ### see if the deps/ directory exists, and if not then we are installing 244 ### from the -nodeps sources so don't install any perl modules 245 $skip_module_install = 1 unless -d $deps_dir; 246 242 247 ### check to see if we are installing as a non-root user 243 248 &check_non_root_user() unless $client_install; … … 384 389 &install_perl_module($mod_href); 385 390 } 386 }387 388 ### special case the NetPacket::<proto> modules since the NetPacket389 ### directory is just for the base class, and we need to make sure390 ### we have each of the NetPacket::IP, NetPacket::ICMP, NetPacket::UDP,391 ### and NetPacket::TCP modules.392 unless ($skip_module_install or $client_install) {393 chdir 'NetPacket' or die "[*] Could not chdir NetPacket directory: $!";394 unless (-e 'Makefile.PL') {395 die "[*] Your NetPacket source directory appears to be incomplete!\n",396 " Download the latest sources from ",397 "http://www.cipherdyne.org\n";398 }399 system "$cmds{'make'} clean" if -e 'Makefile';400 system "$cmds{'perl'} Makefile.PL PREFIX=$config{'FWKNOP_MOD_DIR'} " .401 "LIB=$config{'FWKNOP_MOD_DIR'}";402 system $cmds{'make'};403 # system "$cmds{'make'} test";404 system "$cmds{'make'} install";405 chdir $src_dir or die "[*] Could not chdir $src_dir: $!";406 391 } 407 392 … … 1169 1154 sub install_perl_module() { 1170 1155 my $mod_hr = shift; 1156 1157 chdir $src_dir or die "[*] Could not chdir $src_dir: $!"; 1158 chdir $deps_dir or die "[*] Could not chdir($deps_dir): $!"; 1171 1159 1172 1160 for my $key qw/module force-install client-mode-install mod-dir/ { fwknop/trunk/knoptm
r1174 r1201 40 40 # 41 41 42 use lib '/usr/lib/fwknop';43 use Unix::Syslog qw(:subs :macros);44 use Net::IPv4Addr qw(ipv4_in_network);45 42 use IO::Socket; 46 43 use IO::Handle; … … 62 59 my $print_ver = 0; 63 60 my $debug = 0; 61 my $lib_dir = ''; 64 62 my $die_msg = ''; 65 63 my $warn_msg = ''; … … 95 93 'no-voluntary-exits' => \$no_voluntary_exits, 96 94 'no-logs' => \$no_logs, 95 'Lib-dir=s' => \$lib_dir, 97 96 'LC_ALL=s' => \$cmdline_locale, 98 97 'locale=s' => \$cmdline_locale, … … 536 535 ### make sure all the vars we need are actually in the config file. 537 536 &required_vars(); 537 538 ### import all necessary perl modules 539 &import_perl_modules(); 538 540 539 541 ### validate config … … 744 746 KNOPTM_SYSLOG_FACILITY KNOPTM_SYSLOG_PRIORITY 745 747 ENABLE_VOLUNTARY_EXITS EXIT_INTERVAL FWKNOP_PID_FILE 746 LOCALE 748 LOCALE FWKNOP_MOD_DIR 747 749 ) { 748 750 … … 844 846 } 845 847 return; 848 } 849 850 sub import_perl_modules() { 851 852 my $mod_paths_ar = &get_mod_paths(); 853 854 if ($#$mod_paths_ar > -1) { ### /usr/lib/fwknop/ exists 855 push @$mod_paths_ar, @INC; 856 splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar; 857 } 858 859 if ($debug) { 860 print STDERR "[+] import_perl_modules(): The \@INC array:\n"; 861 print STDERR "$_\n" for @INC; 862 } 863 864 require Unix::Syslog unless $config{'ALERTING_METHODS'} =~ /no.?syslog/i; 865 866 Unix::Syslog->import(qw(:subs :macros)) 867 unless $config{'ALERTING_METHODS'} =~ /no.?syslog/i; 868 869 require Net::IPv4Addr; 870 Net::IPv4Addr->import(qw/ipv4_in_network/);
