Changeset 1000
- Timestamp:
- 02/02/08 18:21:40 (10 months ago)
- Files:
-
- fwknop/trunk/ChangeLog (modified) (1 diff)
- fwknop/trunk/TODO (modified) (1 diff)
- fwknop/trunk/fwknop (modified) (7 diffs)
- fwknop/trunk/fwknopd (modified) (18 diffs)
- fwknop/trunk/test/conf/client_timeout_access.conf (added)
- fwknop/trunk/test/fwknop_test.pl (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fwknop/trunk/ChangeLog
r996 r1000 3 3 - (Grant Ferley) Submitted patch to handle Linux "cooked" interfaces for 4 4 packet capture (e.g. rp-pppoe interfaces). 5 - Applied modified version of the client-defined access timeout patches 6 submitted by the PICT SPA Group. There are two new message types to 7 facilitate client timeouts; one for normal access mode, and the other 8 for the FORWARD access mode. In the access.conf file, there is also a 9 new variable "PERMIT_CLIENT_TIMEOUT" to allow each SOURCE stanza to 10 allow client-defined timeouts or not. 5 11 - Added full packet hex dumps (including packet headers) to fwknopd in 6 12 --debug --verbose mode. This is to help diagnose packet sniffing issues fwknop/trunk/TODO
r916 r1000 73 73 74 74 75 Client derived access timeouts:76 77 The current fwknopd implementation maintains access timeouts via the78 FW_ACCESS_TIMEOUT variable in the /etc/fwknop/access.conf file. This79 strategy works well enough, but it would be useful to allow the SPA client80 to set the timeout (subject to a setting in the access.conf file to permit81 this for an applicable SOURCE stanza). To support this, a new command82 line argument would need to be added to the fwknop client.83 84 85 75 Destination IP address restrictions in /etc/fwknop/access.conf: 86 76 fwknop/trunk/fwknop
r996 r1000 102 102 $ext_resolve_user_agent =~ s|-pre\d+||; 103 103 104 ### SPA message types from fwknop clients 104 ### ACCESS message: 105 ### random data :user : client_timestamp : client_version : \ 106 ### type (1) : access_request : MD5 107 my $SPA_ACCESS_MODE = 1; ### default 108 109 ### COMMAND message: 110 ### random data :user : client_timestamp : client_version : \ 111 ### type (0) : command : MD5 105 112 my $SPA_COMMAND_MODE = 0; 106 my $SPA_ACCESS_MODE = 1; ### default 113 114 ### FORWARD ACCESS message: 115 ### random data :user : client_timestamp : client_version : \ 116 ### type (2) : access_request : NAT_info : MD5 107 117 my $SPA_FORWARD_ACCESS_MODE = 2; 108 118 119 ### ACCESS message with client-defined firewall timeout: 120 ### random data :user : client_timestamp : client_version : \ 121 ### type (3) : access_request : timeout : MD5 122 my $SPA_CLIENT_TIMEOUT_ACCESS_MODE = 3; 123 124 ### FORWARD ACCESS message with client-defined firewall timeout: 125 ### random data :user : client_timestamp : client_version : \ 126 ### type (4) : access_request : NAT_info : timeout : MD5 127 my $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE = 4; 128 109 129 ### default time values 110 my $knock_interval = 60;111 my $ fw_access_timeout = 300;130 my $knock_interval = 60; 131 my $cmdl_fw_timeout = 0; 112 132 113 133 ### default to root (client must run as root in this mode) … … 215 235 die "[*] Must specify a destination server with -D <IP|Host>" 216 236 unless $knock_dst; 237 238 if ($cmdl_fw_timeout ne '0') { 239 die "[*] Must specify a firewall timeout > 0" 240 unless $cmdl_fw_timeout > 0; 241 } 217 242 218 243 my $print_mode = ''; … … 395 420 $msg .= &SPA_message(); 396 421 422 ### append FORWARD access requirement (optional) 423 $msg .= &SPA_forward_access(); 424 397 425 ### append server authentication method (optional) 398 426 $msg .= &SPA_server_auth(); 399 427 400 ### append FORWARD access requirement (optional)401 $msg .= &SPA_ forward_access();428 ### append any client defined fw timeout (optional) 429 $msg .= &SPA_client_timeout(); 402 430 403 431 ### append MD5 sum … … 461 489 return ':' . $SPA_COMMAND_MODE; 462 490 } elsif ($forward_access_str) { 463 print " Type: $SPA_FORWARD_ACCESS_MODE ", 464 "(FORWARD access mode)\n" unless $quiet; 465 return ':' . $SPA_FORWARD_ACCESS_MODE; 466 } 467 print " Type: $SPA_ACCESS_MODE (access mode)\n" 468 unless $quiet; 469 return ':' . $SPA_ACCESS_MODE; 491 if ($cmdl_fw_timeout > 0) { 492 print " Type: " . 493 "$SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE ", 494 "(FORWARD client-timeout access mode)\n" unless $quiet; 495 return ':' . $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE; 496 } else { 497 print " Type: $SPA_FORWARD_ACCESS_MODE ", 498 "(FORWARD access mode)\n" unless $quiet; 499 return ':' . $SPA_FORWARD_ACCESS_MODE; 500 } 501 } 502 if ($cmdl_fw_timeout > 0) { 503 print " Type: " . 504 "$SPA_CLIENT_TIMEOUT_ACCESS_MODE (access ", 505 "client-timeout mode)\n" unless $quiet; 506 return ':' . $SPA_CLIENT_TIMEOUT_ACCESS_MODE; 507 } else { 508 print " Type: $SPA_ACCESS_MODE (access mode)\n" 509 unless $quiet; 510 return ':' . $SPA_ACCESS_MODE; 511 } 470 512 } 471 513 … … 487 529 unless $quiet; 488 530 return ':' . encode_base64("$enc_allow_ip,$access_str"); 531 } 532 533 sub SPA_client_timeout() { 534 return unless $cmdl_fw_timeout; 535 return ':' . $cmdl_fw_timeout; 489 536 } 490 537 … … 1279 1326 'TCP-sock' => \$spa_established_tcp, 1280 1327 'Access=s' => \$access_str, 1328 'fw-timeout=i' => \$cmdl_fw_timeout, 1281 1329 'allow-IP=s' => \$enc_allow_ip, 1282 1330 'source-IP' => \$enc_source_ip, … … 1466 1514 (must use the -R option). The default user 1467 1515 agent is: $ext_resolve_user_agent 1516 -f, --fw-timeout <seconds> - Specify the time the port will remain open 1517 on the server (requires 1518 PERMIT_CLIENT_TIMEOUT in access.conf on the 1519 fwknopd server side). 1468 1520 --Save-dst - Save the command line args for this 1469 1521 invocation against the destination to the fwknop/trunk/fwknopd
r998 r1000 114 114 115 115 ### SPA message types from fwknop clients 116 117 ### ACCESS message: 118 ### random data :user : client_timestamp : client_version : \ 119 ### type (1) : access_request : MD5 120 my $SPA_ACCESS_MODE = 1; ### default 121 122 ### COMMAND message: 123 ### random data :user : client_timestamp : client_version : \ 124 ### type (0) : command : MD5 116 125 my $SPA_COMMAND_MODE = 0; 117 my $SPA_ACCESS_MODE = 1; ### default 126 127 ### FORWARD ACCESS message: 128 ### random data :user : client_timestamp : client_version : \ 129 ### type (2) : access_request : NAT_info : MD5 118 130 my $SPA_FORWARD_ACCESS_MODE = 2; 131 132 ### ACCESS message with client-defined firewall timeout: 133 ### random data :user : client_timestamp : client_version : \ 134 ### type (3) : access_request : timeout : MD5 135 my $SPA_CLIENT_TIMEOUT_ACCESS_MODE = 3; 136 137 ### FORWARD ACCESS message with client-defined firewall timeout: 138 ### random data :user : client_timestamp : client_version : \ 139 ### type (4) : access_request : NAT_info : timeout : MD5 140 my $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE = 4; 119 141 120 142 ### minimum nummber of fields within a decrypted SPA packet … … 122 144 123 145 ### default time values 124 my $knock_interval = 60;125 my $ fw_access_timeout = 300;146 my $knock_interval = 60; 147 my $default_access_timeout = 300; 126 148 127 149 my $enc_port_offset = 61000; ### default offset … … 192 214 'KNOCK_LIMIT' => '', 193 215 'PERMIT_CLIENT_PORTS' => '', 216 'PERMIT_CLIENT_TIMEOUT' => '', 194 217 'ENABLE_FORWARD_ACCESS' => 0, 195 218 'ENABLE_CMD_EXEC' => '', … … 492 515 $access_hr, $src_ip, $msg_hr); 493 516 494 if ($msg_hr->{'action_type'} == $SPA_ACCESS_MODE ) {495 if (&SPA_access($msg_hr, $src_ip, $decrypt_algo,496 $gpg_sign_id, $md5sum, $access_hr)) {497 last SOURCE;498 } else {499 next SOURCE;500 }501 } elsif ($msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE) { 517 if ($msg_hr->{'action_type'} == $SPA_ACCESS_MODE 518 or $msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE 519 or $msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE 520 or $msg_hr->{'action_type'} 521 == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 522 or $msg_hr->{'action_type'} 523 == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 524 502 525 if (&SPA_access($msg_hr, $src_ip, $decrypt_algo, 503 526 $gpg_sign_id, $md5sum, $access_hr)) { … … 602 625 603 626 print STDERR localtime() . " [+] Packet fields:\n"; 604 printf STDERR " %-1 4s %s\n %-14s %s\n %-14s %s\n" .605 " %-1 4s %s\n %-14s %s",627 printf STDERR " %-16s %s\n %-16s %s\n %-16s %s\n" . 628 " %-16s %s\n %-16s %s", 606 629 'Random data:', $msg_hr->{'random_number'}, 607 630 'Username:', $msg_hr->{'username'}, … … 616 639 } elsif ($msg_hr->{'action_type'} == $SPA_FORWARD_ACCESS_MODE) { 617 640 print STDERR " (SPA_FORWARD_ACCESS_MODE)\n"; 618 } 619 printf STDERR " %-14s %s\n", 641 } elsif ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE) { 642 print STDERR " (SPA_CLIENT_TIMEOUT_ACCESS_MODE)\n"; 643 } elsif ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 644 print STDERR " (SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE)\n"; 645 } 646 printf STDERR " %-16s %s\n", 620 647 'Action:', $msg_hr->{'action'}; 648 649 if ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 650 or $msg_hr->{'action_type'} 651 == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 652 printf STDERR " %-16s %s\n", 653 'Client timeout:', $msg_hr->{'client_timeout'}; 654 } 621 655 622 656 if ($msg_hr->{'server_auth'}) { … … 625 659 my $server_auth_crypt_pw = $2; 626 660 if ($debug) { 627 printf STDERR " %-1 4s %s", 'Server auth:', $server_auth_type;661 printf STDERR " %-16s %s", 'Server auth:', $server_auth_type; 628 662 for (my $i=0; $i<length($server_auth_crypt_pw); $i++) { 629 663 print STDERR '*'; … … 634 668 } 635 669 if ($msg_hr->{'forward_info'}) { 636 printf STDERR " %-14s %s\n", 'Forward info:', $msg_hr->{'forward_info'}; 637 } 638 printf STDERR " %-14s %s\n", 'MD5 sum:', $msg_hr->{'md5sum'}; 670 printf STDERR " %-16s %s\n", 'Forward info:', 671 $msg_hr->{'forward_info'}; 672 } 673 printf STDERR " %-16s %s\n", 'MD5 sum:', $msg_hr->{'md5sum'}; 639 674 return; 640 675 } … … 714 749 } 715 750 751 if ($msg_hr->{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 752 or $msg_hr->{'action_type'} 753 == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 754 755 if ($access_hr->{'PERMIT_CLIENT_TIMEOUT'}) { 756 $access_hr->{'FW_ACCESS_TIMEOUT'} = $msg_hr->{'client_timeout'}; 757 } else { 758 &logr('[-]', "received fw access request from $src_ip, " . 759 "with client-defined timeout, but PERMIT_CLIENT_TIMEOUT is not " . 760 "set (SOURCE line num: $access_hr->{'src_line_num'})", $NO_MAIL); 761 return 0; 762 } 763 } 764 716 765 $allow_src = $1 if $msg_hr->{'action'} =~ /($ip_re)/; 717 766 … … 1063 1112 'server_auth' => '', ### optional 1064 1113 'forward_info' => '', ### optional 1114 'client_timeout' => -1, ### optional 1065 1115 'md5sum' => '', 1066 1116 ); … … 1124 1174 if (&is_digit($fields[4])) { 1125 1175 return 0, {} unless $fields[4] == $SPA_COMMAND_MODE 1126 or $fields[4] == $SPA_ACCESS_MODE 1127 or $fields[4] == $SPA_FORWARD_ACCESS_MODE; 1176 or $fields[4] == $SPA_ACCESS_MODE 1177 or $fields[4] == $SPA_FORWARD_ACCESS_MODE 1178 or $fields[4] == $SPA_CLIENT_TIMEOUT_ACCESS_MODE 1179 or $fields[4] == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE; 1128 1180 $msg_hsh{'action_type'} = $fields[4]; 1129 1181 } else { … … 1141 1193 ### iptables FORWARD/DNAT access was introduced in 1.9.0 1142 1194 if ($msg_hsh{'numeric_version'} >= 190) { 1195 my $found = 0; 1143 1196 if ($msg_hsh{'action_type'} == $SPA_FORWARD_ACCESS_MODE) { 1144 1197 if ($#fields == $SPA_MIN_PACKET_FIELDS+1) { 1145 1198 $msg_hsh{'forward_info'} = decode_base64($fields[6]); 1199 $found = 1; 1146 1200 } 1147 } else { 1201 } elsif ($msg_hsh{'numeric_version'} >= 192) { 1202 ### client timeouts were introduced in 1.9.2 1203 if ($msg_hsh{'action_type'} == $SPA_CLIENT_TIMEOUT_ACCESS_MODE) { 1204 $msg_hsh{'client_timeout'} = $fields[6]; 1205 $found = 1; 1206 } elsif ($msg_hsh{'action_type'} 1207 == $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE) { 1208 $msg_hsh{'client_timeout'} = $fields[7]; 1209 $found = 1; 1210 } 1211 } 1212 unless ($found) { 1148 1213 if ($#fields > $SPA_MIN_PACKET_FIELDS) { 1149 1214 $msg_hsh{'server_auth'} = decode_base64($fields[6]); … … 1172 1237 "$msg_hsh{'username'}:$msg_hsh{'remote_time'}:", 1173 1238 "$msg_hsh{'remote_version'}:$msg_hsh{'action_type'}:", 1174 "$msg_hsh{'action'}:$msg_hsh{'md5sum'}"; 1239 "$msg_hsh{'action'}"; 1240 1241 if ($msg_hsh{'forward_info'}) { 1242 print STDERR ":$msg_hsh{'forward_info'}"; 1243 } 1244 1245 if ($msg_hsh{'client_timeout'}) { 1246 print STDERR ":$msg_hsh{'client_timeout'}"; 1247 } 1175 1248 1176 1249 ### careful not to display password information … … 1182 1255 print STDERR "*"; 1183 1256 } 1184 } elsif ($msg_hsh{'forward_info'}) { 1185 print STDERR ":$msg_hsh{'forward_info'}"; 1186 } 1187 print STDERR "\n"; 1257 } 1258 1259 print STDERR ":$msg_hsh{'md5sum'}\n"; 1188 1260 } 1189 1261 return 1, \%msg_hsh; … … 3048 3120 $access_hsh{'PERMIT_CLIENT_PORTS'} = 0; 3049 3121 } 3122 } elsif ($line =~ /^\s*PERMIT_CLIENT_TIMEOUT\s*;/) { 3123 $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 1; 3124 } elsif ($line =~ /^\s*PERMIT_CLIENT_TIMEOUT:\s*(\S+);/) { 3125 my $val = $1; 3126 if ($val =~ /y/i) { 3127 $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 1; 3128 } else { 3129 $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 0; 3130 } 3050 3131 } elsif ($line =~ /^\s*ENABLE_CMD_EXEC\s*;/) { 3051 3132 $access_hsh{'ENABLE_CMD_EXEC'} = 1; … … 3077 3158 } elsif ($line =~ /^\s*FW_ACCESS_TIMEOUT:\s*(\d+)\s*;/) { 3078 3159 $access_hsh{'FW_ACCESS_TIMEOUT'} = $1; 3160 } elsif ($line =~ /^\s*MAX_ACCESS_TIMEOUT:\s*(\d+)\s*;/) { 3161 $access_hsh{'FW_ACCESS_TIMEOUT'} = $1; 3079 3162 } elsif ($line =~ /^\s*REQUIRE_OS:\s*(.*)\s*;/) { 3080 3163 $access_hsh{'REQUIRE_OS'} = $1; … … 3095 3178 unless (defined $access_hsh{'PERMIT_CLIENT_PORTS'}) { 3096 3179 $access_hsh{'PERMIT_CLIENT_PORTS'} = 0; 3180 } 3181 unless (defined $access_hsh{'PERMIT_CLIENT_TIMEOUT'}) { 3182 $access_hsh{'PERMIT_CLIENT_TIMEOUT'} = 0; 3097 3183 } 3098 3184 if (&validate_src_access_hsh(\%access_hsh)) { … … 3299 3385 } 3300 3386 } else { 3301 &logr('[-]', "$config{'ACCESS_CONF'}: SOURCE: $src (line: $src_line) " . 3302 "missing FW_ACCESS_TIMEOUT, defaulting to $fw_access_timeout", 3303 $NO_MAIL); 3304 $src_href->{'FW_ACCESS_TIMEOUT'} = $fw_access_timeout; 3387 if (defined $src_href->{'PERMIT_CLIENT_TIMEOUT'}) { 3388 ### in this case we will derive the timeout from the SPA 3389 ### packet. 3390 $src_href->{'FW_ACCESS_TIMEOUT'} = 0; 3391 } else { 3392 &logr('[-]', "$config{'ACCESS_CONF'}: SOURCE: $src (line: $src_line) " . 3393 "missing FW_ACCESS_TIMEOUT, defaulting to $default_access_timeout", 3394 $NO_MAIL); 3395 $src_href->{'FW_ACCESS_TIMEOUT'} = $default_access_timeout; 3396 } 3305 3397 } 3306 3398 if (defined $src_href->{'KNOCK_LIMIT'}) { fwknop/trunk/test/fwknop_test.pl
r999 r1000 59 59 my $multi_source_access_conf = "$conf_dir/multi_source_access.conf"; 60 60 my $no_loopback_ip_match_access_conf = "$conf_dir/no_loopback_ip_match_access.conf"; 61 my $client_timeout_access_conf = "$conf_dir/client_timeout_access.conf"; 61 62 62 63 my $local_key_file = 'local_spa.key'; … … 99 100 my $ip_re = qr|(?:[0-2]?\d{1,2}\.){3}[0-2]?\d{1,2}|; 100 101 101 ### SPA message types from fwknop clients 102 ### ACCESS message: 103 ### random data :user : client_timestamp : client_version : \ 104 ### type (1) : access_request : MD5 105 my $SPA_ACCESS_MODE = 1; ### default 106 107 ### COMMAND message: 108 ### random data :user : client_timestamp : client_version : \ 109 ### type (0) : command : MD5 102 110 my $SPA_COMMAND_MODE = 0; 103 my $SPA_ACCESS_MODE = 1; ### default 111 112 ### FORWARD ACCESS message: 113 ### random data :user : client_timestamp : client_version : \ 114 ### type (2) : access_request : NAT_info : MD5 104 115 my $SPA_FORWARD_ACCESS_MODE = 2; 116 117 ### ACCESS message with client-defined firewall timeout: 118 ### random data :user : client_timestamp : client_version : \ 119 ### type (3) : access_request : timeout : MD5 120 my $SPA_CLIENT_TIMEOUT_ACCESS_MODE = 3; 121 122 ### FORWARD ACCESS message with client-defined firewall timeout: 123 ### random data :user : client_timestamp : client_version : \ 124 ### type (4) : access_request : NAT_info : timeout : MD5 125 my $SPA_CLIENT_TIMEOUT_FORWARD_ACCESS_MODE = 4; 105 126 106 127 ### make Getopts case sensitive … … 191 212 &stop_fwknopd_quiet(); 192 213 214 ### client timeout with --fw-timeout on fwknop command line 215 &test_driver('(Client timeout) Generating SPA access packet', 216 \&SPA_client_timeout_access_packet); 217 &test_driver('(Client timeout) Sniffing SPA access packet', 218 \&client_timeout_sniff_decrypt); 219 &test_driver('(Client timeout) Verifying SPA access packet format', 220 \&spa_client_timeout_access_format); 221 &test_driver('(Client timeout) Firewall access rules exist', 222 \&fw_rules_exist); 223 &fw_sleep_10(); ### give knoptm a chance to remove the rules 224 &test_driver('(Client timeout) Firewall access rules removed', 225 \&fw_rules_removed); 226 &test_driver('(Client timeout) Stopping all running fwknopd processes', 227 \&stop_fwknopd); 228 193 229 ### It is ok to append data in the current code since the Rijndael decrypt 194 230 ### only returns the actual SPA payload (may need to revist this) … … 571 607 572 608 sub non_matching_source_generation() { 573 return &get_access_packet( );609 return &get_access_packet(0); 574 610 } 575 611 … … 690 726 "rule timeout)\n "); 691 727 for (my $i=$fw_access_timeout+3; $i > 0; $i--) { 728 &logr("$i "); 729 sleep 1; 730 } 731 &logr("0\n"); 732 return; 733 } 734 735 sub fw_sleep_10() { 736 &logr(" (Sleeping for 10 seconds for firewall " . 737 "rule timeout)\n "); 738 for (my $i=10; $i > 0; $i--) { 692 739 &logr("$i "); 693 740 sleep 1; … … 881 928 } 882 929 930 sub spa_client_timeout_access_format() { 931 ### Random data: 1946117908964953 932 ### Username: root 933 ### Remote time: 1197922462 934 ### Remote ver: 1.9.0 935 ### Action type: 1 (SPA_ACCESS_MODE) 936 ### Action: 127.0.0.2,none,0 937 ### Client timeout: 5 938 ### MD5 sum: DLnVQDc5XTkazUbeJX14Og 939 my $valid_lines = 0; 940 open F, "< $fwknopd_output_file" or die "[*] Could not open ", 941 "$fwknopd_output_file: $!"; 942 while (<F>) { 943 if (/^\s+Random\s+data:\s+\d+/i) { 944 $valid_lines++; 945 } elsif (/^\s+Username:\s+\w+$/i) { 946 $valid_lines++; 947 } elsif (/^\s+Remote\s+time:\s+\d+$/i) { 948 $valid_lines++; 949 } elsif (/^\s+Remote\s+ver:\s+(\S+)$/i) { 950 $valid_lines++; 951 } elsif (/^\s+Action\s+type:\s+$SPA_CLIENT_TIMEOUT_ACCESS_MODE\s+/i) { 952 $valid_lines++; 953 } elsif (/^\s+Action:\s+$ip_re/i) { 954 $valid_lines++; 955 } elsif (/^\s+Client\s+timeout:\s+\d+/i) { 956 $valid_lines++; 957 } elsif (/^\s+MD5\s+sum:\s+\S+$/i) { 958 $valid_lines++; 959 } 960 } 961 close F; 962 unless ($valid_lines == 8) { 963 return &print_errors("fail ($test_num)\n[*] Dubious " . 964 "sniffed packet format"); 965 } 966 return 1; 967 } 968 883 969 sub spa_access_format() { 884 970 ### Random data: 1946117908964953 … … 1239 1325 } 1240 1326 1327 sub SPA_client_timeout_access_packet() { 1328 return &get_access_packet(5); 1329 } 1330 1241 1331 sub SPA_access_packet() { 1242 return &get_access_packet( );1332 return &get_access_packet(0); 1243 1333 } 1244 1334 … … 1271 1361 } 1272 1362 die "[*] Could not assign valid unauthorized port" unless $unauth_port; 1273 my $rv = &get_access_packet( );1363 my $rv = &get_access_packet(0); 1274 1364 $open_ports = $port_copy; 1275 1365 return $rv; … … 1305 1395 my $require_user_copy = $require_user; 1306 1396 $require_user = 'mbr' . $require_user; 1307 my $rv = &get_access_packet( );1397 my $rv = &get_access_packet(0); 1308 1398 $require_user = $require_user_copy; 1309 1399 return $rv; … … 1338 1428 1339 1429 sub truncated_SPA_packet() { 1340 my $rv = &get_access_packet( );1430 my $rv = &get_access_packet(0); 1341 1431 ### chop off the last 10 chars 1342 1432 $cache_encrypted_Rijndael_spa_packet =~ s|.{10}$||; … … 1345 1435 1346 1436 sub append_SPA_packet() { 1347 my $rv = &get_access_packet( );1437 my $rv = &get_access_packet(0); 1348 1438 ### append 10 garbage chars 1349 1439 $cache_encrypted_Rijndael_spa_packet .= '1234567890'; … … 1390 1480 } 1391 1481 1482 sub client_timeout_sniff_decrypt() { 1483 1484 $fwknopd_output_file = "${cmd_stderr}.$test_num"; 1485 1486 if (&run_fwknopd($cache_encrypted_Rijndael_spa_packet, 1487 $default_fwknop_conf, $client_timeout_access_conf)) { 1488 1489 ### now that fwknopd has exited, see if the SPA packet was valid 1490 open SE, "< $fwknopd_output_file" 1491 or die "[*] Could not open $fwknopd_output_file: $!"; 1492 while (<SE>) { 1493 if (/\[\-\]\s+Key\s+mis\-?match/i) { 1494 ### [-] Key mis-match or broken message checksum for SOURCE \ 1495 ### ANY (# 1 in access.conf) 1496 return &print_errors("fail ($test_num)\n[*] " . 1497 "Key mis-match"); 1498 } elsif (/\[\-\]\s+Decrypted.*not\s+conform/i) { 1499 ### [-] Decrypted message does not conform to a valid SPA packet 1500 return &print_errors("fail ($test_num)\n[*] " . 1501 "Invalid SPA packet"); 1502 } 1503 } 1504 close SE; 1505 return 1; 1506 } 1507 return &print_errors("fail ($test_num)\n[*] Sniff alarm " . 1508 "($sniff_alarm seconds) expired"); 1509 } 1510 1392 1511 sub append_SPA_sniff_decrypt() { 1393 1512 … … 1461 1580 my $spa_src_copy = $spa_src; 1462 1581 $spa_src = '0.0.0.0'; 1463 my $rv = &get_access_packet( );1582 my $rv = &get_access_packet(0); 1464 1583 $spa_src = $spa_src_copy; 1465 1584 return $rv; … … 1502 1621 for (my $i=0; $i < $NUM_RAND; $i++) { 1503 1622 1504 &get_access_packet( );1623 &get_access_packet(0); 1505 1624 1506 1625 if (defined $packet_cache{$cache_encrypted_Rijndael_spa_packet}) { … … 1626 1745 1627 1746 sub get_access_packet() { 1747 my $client_timeout = shift; 1628 1748 1629 1749 ### --Test so that SPA packet is not sent … … 1637 1757 close K; 1638 1758 1639 unless (&run_cmd("$fwknopCmd -A $open_ports --no-save --get-key " .1759 my $cmd = "$fwknopCmd -A $open_ports --no-save --get-key " . 1640 1760 "$local_key_file -D $spa_dst -a $spa_src --Test -v " . 1641 "--debug --Spoof-user $require_user")) { 1642 return &print_errors("fail ($test_num)\n[*] Could not " . 1643 "generate encrypted SPA packet"); 1761 "--debug --Spoof-user $require_user"; 1762 1763 if ($client_timeout) { 1764 $cmd .= " --fw-timeout $client_timeout"; 1765 } 1766 1767 unless (&run_cmd($cmd)) { 1768 if ($client_timeout) { 1769 return &print_errors("fail ($test_num)\n[*] Could not " . 1770 "generate client timeout encrypted SPA packet"); 1771 } else { 1772 return &print_errors("fail ($test_num)\n[*] Could not " . 1773 "generate encrypted SPA packet"); 1774 } 1644 1775 } 1645 1776 open F, "< ${cmd_stdout}.$test_num"
