Changeset 1489

Show
Ignore:
Timestamp:
06/30/09 08:26:51 (8 months ago)
Author:
mbr
Message:

added --spa-dump-packets mode to fwknopd and used this as the method for acquiring SPA packet digests for the test suite - this ensures the digests always conform to how the fwknopd daemon sees them

Location:
fwknop/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • fwknop/trunk/fwknopd

    r1488 r1489  
    128128my $fw_data_file = '';  ### legacy port knocking mode 
    129129my $dump_config = 0; 
     130my $spa_dump_packets = ''; 
    130131 
    131132my $cmdline_locale = ''; 
     
    691692    my ($src_ip, $enc_msg_len, $pkt_data) = @_; 
    692693 
     694    if ($spa_dump_packets) { 
     695        if (&is_base64($pkt_data)) { 
     696            print "\nLen: $enc_msg_len, pkt: $pkt_data\n"; 
     697        } else { 
     698            print "\nLine contains non base64 chars, skipping.\n"; 
     699            return; 
     700        } 
     701    } 
     702 
    693703    ### first check to see if we have any matching access directives 
    694704    ### (in access.conf) for $src_ip, and if not we will do _nothing_ 
     
    740750                &fko_destroy_object() if $use_fko_module; 
    741751                next SOURCE; 
     752            } 
     753 
     754            if ($spa_dump_packets) { 
     755                print "    Disk write digest: $digest\n"; 
     756                for my $key (keys %$msg_hr) { 
     757                    printf "    %20s -> %s\n", $key, $msg_hr->{$key}; 
     758                } 
     759                return; 
    742760            } 
    743761 
     
    48814899        'fwknop_servCmd=s' => \$cmdline_fwknop_serv, 
    48824900        'knoptm-debug-file=s' => \$knoptm_debug_file, 
     4901        'spa-dump-packets=s' => \$spa_dump_packets, 
    48834902        'LC_ALL=s'       => \$cmdline_locale, 
    48844903        'locale=s'       => \$cmdline_locale, 
     
    49885007    } 
    49895008    return; 
     5009} 
     5010 
     5011sub spa_dump_packets() { 
     5012    my $rv = 0; 
     5013 
     5014    &import_access(); 
     5015 
     5016    print "[+] Reading in encoded/encrypted SPA packets ", 
     5017        "from file: $spa_dump_packets\n"; 
     5018    open F, "< $spa_dump_packets" or 
     5019        die "[*] Could not open $spa_dump_packets: $!"; 
     5020    while (<F>) { 
     5021        next unless /\S/; 
     5022        chomp; 
     5023        &SPA_check_grant_access('127.0.0.1', length($_), $_); 
     5024    } 
     5025    close F; 
     5026    return $rv; 
    49905027} 
    49915028 
     
    51855222    ### --Status 
    51865223    exit &status() if $status; 
     5224 
     5225    ### --spa-dump-packets (dumps decrypted SPA packets out on stdout) 
     5226    exit &spa_dump_packets() if $spa_dump_packets; 
    51875227 
    51885228    ### make sure there is not another fwknopd process already running. 
     
    60376077        } 
    60386078        close F; 
     6079    } 
     6080 
     6081    if ($debug) { 
     6082        print STDERR localtime() . " [+] digest_store hash: \n", 
     6083            Dumper(\%digest_store); 
    60396084    } 
    60406085 
  • fwknop/trunk/test/fwknop_test.pl

    r1482 r1489  
    5353 
    5454my $knoptm_debug_file = "$output_dir/knoptm.debug"; 
     55my $dump_packets_file  = "$output_dir/dump_packets";  # for digest calculation 
    5556 
    5657my $default_access_conf   = "$conf_dir/default_access.conf"; 
     
    15551556sub replay_attack() { 
    15561557 
    1557     &get_access_packet($default_fwknop_args, $NO_QUIET); 
     1558    &get_access_packet($default_fwknop_args, $default_fwknop_conf, $NO_QUIET); 
    15581559 
    15591560    ### write out the digest to the digest.cache so that we 
     
    15921593 
    15931594    ### SHA256 is the default anyway 
    1594     &get_access_packet("$default_fwknop_args --digest-alg sha256", $NO_QUIET); 
     1595    &get_access_packet("$default_fwknop_args --digest-alg sha256", 
     1596        $sha256_fwknop_conf, $NO_QUIET); 
    15951597 
    15961598    ### write out the SHA256 digest to the digest.cache file so that we 
     
    16261628sub replay_attack_sha1() { 
    16271629 
    1628     &get_access_packet("$default_fwknop_args --digest-alg sha1", $NO_QUIET); 
     1630    &get_access_packet("$default_fwknop_args --digest-alg sha1", 
     1631        $sha1_fwknop_conf, $NO_QUIET); 
    16291632 
    16301633    ### write out the SHA1 digest to the digest.cache so that we 
     
    16601663sub replay_attack_md5() { 
    16611664 
    1662     &get_access_packet("$default_fwknop_args --digest-alg md5", $NO_QUIET); 
     1665    &get_access_packet("$default_fwknop_args --digest-alg md5", 
     1666        $md5_fwknop_conf, $NO_QUIET); 
    16631667 
    16641668    ### write out the MD5 digest to the digest.cache so that we 
     
    16931697 
    16941698sub non_matching_source_generation() { 
    1695     return &get_access_packet($default_fwknop_args, $NO_QUIET); 
     1699    return &get_access_packet($default_fwknop_args, 
     1700        $default_fwknop_conf, $NO_QUIET); 
    16961701} 
    16971702 
     
    33823387    return &get_access_packet("$default_fwknop_args " . 
    33833388        "--gpg-home conf/client-gpg --gpg-recip $gpg_server_key " . 
    3384         "--gpg-sign $gpg_client_key", $NO_QUIET); 
     3389        "--gpg-sign $gpg_client_key", $default_fwknop_conf, $NO_QUIET); 
    33853390} 
    33863391 
     
    33893394        "--gpg-home conf/client-gpg --gpg-recip $gpg_server_key " . 
    33903395        "--gpg-sign $gpg_client_key --Include-gpg-prefix", 
    3391         $NO_QUIET); 
     3396        $default_fwknop_conf, $NO_QUIET); 
    33923397} 
    33933398 
     
    33963401        "--gpg-home conf/client-gpg --gpg-recip $gpg_server_key " . 
    33973402        "--gpg-sign $gpg_client_key --gpg-path $gpg2Cmd", 
    3398         $NO_QUIET); 
     3403        $default_fwknop_conf, $NO_QUIET); 
    33993404} 
    34003405 
     
    34033408        "--gpg-home conf/client-gpg --gpg-recip $gpg_server_key " . 
    34043409        "--gpg-sign $gpg_client_key --gpg-path $gpg2Cmd $http_opt", 
    3405         $NO_QUIET); 
     3410        $default_fwknop_conf, $NO_QUIET); 
    34063411} 
    34073412 
    34083413sub SPA_client_timeout_access_packet() { 
    34093414    return &get_access_packet("$default_fwknop_args --fw-timeout 5", 
    3410         $NO_QUIET); 
     3415        $default_fwknop_conf, $NO_QUIET); 
    34113416} 
    34123417 
    34133418sub SPA_access_packet_62203() { 
    34143419    return &get_access_packet("$default_fwknop_args $server_port_opt 62203", 
    3415         $NO_QUIET); 
     3420        $default_fwknop_conf, $NO_QUIET); 
    34163421} 
    34173422 
    34183423sub SPA_access_packet_plus60min() { 
    34193424    return &get_access_packet("$default_fwknop_args --time-offset-plus 60min", 
    3420         $NO_QUIET); 
     3425        $default_fwknop_conf, $NO_QUIET); 
    34213426} 
    34223427 
    34233428sub SPA_access_packet_minus60min() { 
    34243429    return &get_access_packet("$default_fwknop_args --time-offset-minus 60min", 
    3425         $NO_QUIET); 
     3430        $default_fwknop_conf, $NO_QUIET); 
    34263431} 
    34273432 
    34283433sub SPA_access_packet_icmp() { 
    34293434    return &get_access_packet("$default_fwknop_args $spoof_proto_opt icmp", 
    3430         $NO_QUIET); 
     3435        $default_fwknop_conf, $NO_QUIET); 
    34313436} 
    34323437 
    34333438sub SPA_access_packet_http() { 
    34343439    return &get_access_packet("$default_fwknop_args $http_opt", 
    3435         $NO_QUIET); 
     3440        $default_fwknop_conf, $NO_QUIET); 
    34363441} 
    34373442 
     
    34393444    return &get_access_packet("$default_fwknop_args " . 
    34403445        "--gpg-home conf/client-gpg --gpg-recip $gpg_server_key " . 
    3441         "--gpg-sign $gpg_client_key $http_opt", $NO_QUIET); 
     3446        "--gpg-sign $gpg_client_key $http_opt", $default_fwknop_conf, 
     3447        $NO_QUIET); 
    34423448} 
    34433449 
     
    34453451    if ($client_language eq 'C') { 
    34463452        return &get_access_packet("$default_fwknop_args --server-proto tcp", 
    3447             $NO_QUIET); 
     3453            $default_fwknop_conf, $NO_QUIET); 
    34483454    } else { 
    34493455        return &get_access_packet("$default_fwknop_args --TCP-sock", 
    3450             $NO_QUIET); 
     3456            $default_fwknop_conf, $NO_QUIET); 
    34513457    } 
    34523458} 
    34533459 
    34543460sub SPA_access_packet() { 
    3455     return &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3461    return &get_access_packet($default_fwknop_args, 
     3462        $default_fwknop_conf, $NO_QUIET); 
    34563463} 
    34573464 
     
    34603467        "--get-key $local_key_file -D $localhost -a $allow_src " . 
    34613468        "$test_mode_opt -v --debug $spoof_user_opt $require_user", 
    3462         $NO_QUIET); 
     3469        $default_fwknop_conf, $NO_QUIET); 
    34633470} 
    34643471 
    34653472sub SPA_access_packet_salted() { 
    34663473    return &get_access_packet("$default_fwknop_args --Include-salted", 
    3467         $NO_QUIET); 
     3474        $default_fwknop_conf, $NO_QUIET); 
    34683475} 
    34693476 
    34703477sub SPA_access_packet_rand_dest_port() { 
    34713478    return &get_access_packet("$default_fwknop_args --rand-port", 
    3472         $NO_QUIET); 
     3479        $default_fwknop_conf, $NO_QUIET); 
    34733480} 
    34743481 
    34753482sub SPA_access_packet_no_dash_A() { 
    3476     return &get_access_packet($fwknop_args_no_dash_A, $NO_QUIET); 
     3483    return &get_access_packet($fwknop_args_no_dash_A, 
     3484        $default_fwknop_conf, $NO_QUIET); 
    34773485} 
    34783486 
    34793487sub SPA_access_packet_md5() { 
    34803488    return &get_access_packet("$default_fwknop_args --digest-alg md5", 
    3481         $NO_QUIET); 
     3489        $default_fwknop_conf, $NO_QUIET); 
    34823490} 
    34833491 
     
    34863494        "$local_key_file -D $localhost -a $allow_src --Test -v " . 
    34873495        qq|--debug $spoof_user_opt $require_user --Server-cmd "$test_cmd"|, 
    3488         $NO_QUIET); 
     3496        $default_fwknop_conf, $NO_QUIET); 
    34893497} 
    34903498 
    34913499sub SPA_forward_access_packet_client_timeout() { 
    34923500    return &get_access_packet("$default_fwknop_args " . 
    3493         "--NAT-access 192.168.10.3:55000 --fw-timeout 5", $NO_QUIET); 
     3501        "--NAT-access 192.168.10.3:55000 --fw-timeout 5", 
     3502        $default_fwknop_conf, $NO_QUIET); 
    34943503} 
    34953504 
    34963505sub SPA_forward_access_packet() { 
    34973506    return &get_access_packet("$default_fwknop_args " . 
    3498         "--NAT-access 192.168.10.3:55000", $NO_QUIET); 
     3507        "--NAT-access 192.168.10.3:55000", 
     3508        $default_fwknop_conf, $NO_QUIET); 
    34993509} 
    35003510 
    35013511sub SPA_forward_access_packet_restricted_IP() { 
    35023512    return &get_access_packet("$default_fwknop_args " . 
    3503         "--NAT-access 192.168.10.5:55000", $NO_QUIET); 
     3513        "--NAT-access 192.168.10.5:55000", 
     3514        $default_fwknop_conf, $NO_QUIET); 
    35043515} 
    35053516 
    35063517sub SPA_output_access_packet() { 
    3507     return &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3518    return &get_access_packet($default_fwknop_args, 
     3519        $default_fwknop_conf, $NO_QUIET); 
    35083520} 
    35093521 
    35103522sub SPA_local_nat_access_packet() { 
    35113523    return &get_access_packet("$default_fwknop_args " . 
    3512         "--NAT-local --NAT-access $localhost:55000", $NO_QUIET); 
     3524        "--NAT-local --NAT-access $localhost:55000", 
     3525        $default_fwknop_conf, $NO_QUIET); 
    35133526} 
    35143527 
     
    35163529    return &get_access_packet("$default_fwknop_args " . 
    35173530        "--NAT-local --NAT-access $localhost --NAT-rand-port ", 
    3518         $NO_QUIET); 
     3531        $default_fwknop_conf, $NO_QUIET); 
    35193532} 
    35203533 
     
    35223535    return &get_access_packet("$default_fwknop_args " . 
    35233536        "--NAT-local --NAT-access $localhost --NAT-rand-port " . 
    3524         "--rand-port", 
    3525         $NO_QUIET); 
     3537        "--rand-port", $default_fwknop_conf, $NO_QUIET); 
    35263538} 
    35273539 
     
    35293541    return &get_access_packet("$default_fwknop_args " . 
    35303542        "--NAT-local --NAT-access $localhost:55000 --fw-timeout 5", 
    3531         $NO_QUIET); 
     3543        $default_fwknop_conf, $NO_QUIET); 
    35323544} 
    35333545 
     
    35363548        "$local_key_file -D $localhost -a $allow_src --Test -v " . 
    35373549        qq|--debug $spoof_user_opt $require_user --Server-cmd "$test_cmd"|, 
    3538         $NO_QUIET); 
     3550        $default_fwknop_conf, $NO_QUIET); 
    35393551} 
    35403552 
     
    35423554    my $key_copy = $cache_key; 
    35433555    $cache_key = 'short'; 
    3544     my $rv = &get_access_packet($default_fwknop_args, $QUIET); 
     3556    my $rv = &get_access_packet($default_fwknop_args, 
     3557        $default_fwknop_conf, $QUIET); 
    35453558    $cache_key = $key_copy; 
    35463559    if ($client_language eq 'perl') { 
     
    35543567sub unauthorized_port_request() { 
    35553568    $default_fwknop_args =~ s|\s$open_ports\s| tcp/1 |; 
    3556     my $rv = &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3569    my $rv = &get_access_packet($default_fwknop_args, 
     3570        $default_fwknop_conf, $NO_QUIET); 
    35573571    $default_fwknop_args =~ s|\stcp/1\s| $open_ports |; 
    35583572    return $rv; 
     
    35863600sub unauthorized_user() { 
    35873601    $default_fwknop_args =~ s/\s$require_user/ mbr$require_user/; 
    3588     my $rv = &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3602    my $rv = &get_access_packet($default_fwknop_args, 
     3603        $default_fwknop_conf, $NO_QUIET); 
    35893604    $default_fwknop_args =~ s/\smbr$require_user/ $require_user/; 
    35903605    return $rv; 
     
    36183633 
    36193634sub truncated_SPA_packet() { 
    3620     my $rv = &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3635    my $rv = &get_access_packet($default_fwknop_args, 
     3636        $default_fwknop_conf, $NO_QUIET); 
    36213637    ### chop off the last 11 chars 
    36223638    $cache_encrypted_spa_packet =~ s|.{11}$||; 
     
    36253641 
    36263642sub non_base64_SPA_packet() { 
    3627     my $rv = &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3643    my $rv = &get_access_packet($default_fwknop_args, 
     3644        $default_fwknop_conf, $NO_QUIET); 
    36283645    ### introduce one non-base64 encoded character "@" at the 11th position 
    36293646    $cache_encrypted_spa_packet =~ s|(.{10}).|$1@|; 
     
    36323649 
    36333650sub append_SPA_packet() { 
    3634     my $rv = &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3651    my $rv = &get_access_packet($default_fwknop_args, 
     3652        $default_fwknop_conf, $NO_QUIET); 
    36353653    ### append 10 garbage chars 
    36363654    $cache_encrypted_spa_packet .= '1234567890'; 
     
    37393757sub source_addr() { 
    37403758    $default_fwknop_args =~ s/\-a\s+$allow_src\s/-a 0.0.0.0 /; 
    3741     my $rv = &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3759    my $rv = &get_access_packet($default_fwknop_args, 
     3760        $default_fwknop_conf, $NO_QUIET); 
    37423761    $default_fwknop_args =~ s/\-a\s+0(?:\.0){3}\s/-a $allow_src /; 
    37433762    return $rv; 
     
    37793798    for (my $i=0; $i < $NUM_RAND; $i++) { 
    37803799 
    3781         &get_access_packet($default_fwknop_args, $NO_QUIET); 
     3800        &get_access_packet($default_fwknop_args, 
     3801            $default_fwknop_conf, $NO_QUIET); 
    37823802 
    37833803        if (defined $packet_cache{$cache_encrypted_spa_packet}) { 
     
    39053925    } 
    39063926 
    3907     &get_packet_data_from_fwknop_output(); 
     3927    &get_packet_data_from_fwknop_output($default_fwknop_conf); 
    39083928 
    39093929    unless ($cache_encrypted_spa_packet) { 
     
    39143934 
    39153935sub get_access_packet() { 
    3916     my ($fwknop_cmdline, $output) = @_; 
     3936    my ($fwknop_cmdline, $fwknop_conf, $output) = @_; 
    39173937 
    39183938    &write_key(); 
     
    39363956    } 
    39373957 
    3938     &get_packet_data_from_fwknop_output(); 
     3958    &get_packet_data_from_fwknop_output($fwknop_conf); 
    39393959 
    39403960    unless ($cache_encrypted_spa_packet) { 
     
    39623982 
    39633983sub get_packet_data_from_fwknop_output() { 
     3984    my $fwknop_conf = shift; 
    39643985 
    39653986    $spa_port = 0; 
    39663987    $cache_encrypted_spa_packet = ''; 
     3988    $spa_packet_digest = ''; 
    39673989 
    39683990    my $found_packet_data = 0; 
     
    39723994    while (<F>) { 
    39733995        if ($client_language eq 'perl') { 
    3974             if (/\sDigest:\s+(\S+)/i) { 
    3975                 $spa_packet_digest = $1; 
    3976                 next; 
    3977             } 
    39783996            if (/^\s*\[\+\]\s+Packet\s+data:/) { 
    39793997                $found_packet_data = 1; 
     
    39914009            } 
    39924010        } else { 
    3993             if (/^\s*SPA.*\sDigest:\s+(\S+)/) { 
    3994                 $spa_packet_digest = $1; 
    3995                 next; 
    3996             } 
    39974011            if (/^\s*Final\s+Packed.*\sData:/) { 
    39984012                $found_packet_data = 1; 
     
    40074021    } 
    40084022    close F; 
     4023 
     4024    ### now that we have the packet data, feed this data to fwknopd 
     4025    ### to get the digest that it would calculate 
     4026    die "[*] Could not acquire encrypted SPA packet from the fwknop client." 
     4027        unless $cache_encrypted_spa_packet; 
     4028 
     4029    &get_spa_digests_from_fwknopd($fwknop_conf); 
     4030 
    40094031    return; 
    40104032} 
     
    45434565 
    45444566sub fwknopd_test_fko_exists() { 
    4545     my $cmd = "$fwknopdCmd --test-FKO-exists"; 
     4567    my $cmd = "$fwknopdCmd -c $default_fwknop_conf --test-FKO-exists"; 
    45464568    open C, "$cmd 2>&1 |" or die "[*] Could not execute $cmd: $!"; 
    45474569    while (<C>) { 
     
    45524574    } 
    45534575    close C; 
     4576    return; 
     4577} 
     4578 
     4579sub get_spa_digests_from_fwknopd() { 
     4580    my $fwknop_conf = shift; 
     4581 
     4582    ### write the current packet out to the dump packets file 
     4583    open F, "> $dump_packets_file" or 
     4584        die "[*] Could not open $dump_packets_file: $!"; 
     4585    print F $cache_encrypted_spa_packet, "\n"; 
     4586    close F; 
     4587 
     4588    my $cmd = "$fwknopdCmd -c $fwknop_conf " . 
     4589        "-a $default_access_conf --spa-dump-packets $dump_packets_file"; 
     4590    open C, "$cmd 2>&1 |" or die "[*] Could not execute $cmd: $!"; 
     4591    while (<C>) { 
     4592        if (/Disk\s+write\s+digest:\s+(\S+)/) { 
     4593            $spa_packet_digest = $1; 
     4594            last; 
     4595        } 
     4596    } 
     4597    close C; 
     4598 
    45544599    return; 
    45554600}