Changeset 1045

Show
Ignore:
Timestamp:
03/30/08 15:51:03 (8 months ago)
Author:
mbr
Message:

- Added hex_dump() feature for fwknop client so that raw encrypted SPA
packet data can be displayed in --verbose mode.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fwknop/trunk/ChangeLog

    r1044 r1045  
    1212      IP does not have to be manually defined.  However, the external IP can 
    1313      be defined by the SNAT_TRANSLATE_IP variable. 
     14    - Added hex_dump() feature for fwknop client so that raw encrypted SPA 
     15      packet data can be displayed in --verbose mode. 
    1416    - When ENABLE_IPT_FORWARDING is set, added a check for the value of the 
    1517      /proc/sys/net/ipv4/ip_forward file to ensure that the local system 
  • fwknop/trunk/fwknop

    r1039 r1045  
    684684    } 
    685685 
     686    if ($verbose) { 
     687        print "[+] Encrypted msg hex dump (" . 
     688            length($ctext) . " bytes):\n"; 
     689        &hex_dump($ctext); 
     690    } 
     691 
    686692    my $encoded_msg = encode_base64($ctext, ''); 
    687693 
     
    696702        { 
    697703            'key'    => $enc_key, 
    698             'cipher' => $enc_alg 
     704            'cipher' => $enc_alg, 
    699705        } 
    700706    ); 
    701     my $encoded_msg = encode_base64($cipher->encrypt($msg), ''); 
     707 
     708    my $encrypted_msg = $cipher->encrypt($msg); 
     709 
     710    if ($verbose) { 
     711        print "\n[+] Encrypted msg hex dump before base64 encoding (" . 
     712            length($encrypted_msg) . " bytes):\n"; 
     713        &hex_dump($encrypted_msg); 
     714    } 
     715 
     716    my $encoded_msg = encode_base64($encrypted_msg, ''); 
    702717 
    703718    ### Crypt::CBC adds the string "Salted__" to the beginning of the 
     
    15121527        die "[*] --digest-alg can accept one of MD5, SHA1, or SHA256"; 
    15131528    } 
     1529    return; 
     1530} 
     1531 
     1532sub hex_dump() { 
     1533    my $data = shift; 
     1534 
     1535    my @chars = split //, $data; 
     1536    my $ctr = 0; 
     1537    my $ascii_str = ''; 
     1538    for my $char (@chars) { 
     1539        if ($ctr % 16 == 0) { 
     1540            print " $ascii_str\n" if $ascii_str; 
     1541            printf "        0x%.4x:  ", $ctr; 
     1542            $ascii_str = ''; 
     1543        } 
     1544        printf "%.2x", ord($char); 
     1545 
     1546        if ((($ctr+1) % 2 == 0) and ($ctr % 16 != 0)) { 
     1547            print ' '; 
     1548        } 
     1549 
     1550        if ($char =~ /[^\x20-\x7e]/) { 
     1551            $ascii_str .= '.'; 
     1552        } else { 
     1553            $ascii_str .= $char; 
     1554        } 
     1555        $ctr++; 
     1556    } 
     1557    if ($ascii_str) { 
     1558        my $remainder = 1; 
     1559        if ($ctr % 16 != 0) { 
     1560            $remainder = 16 - $ctr % 16; 
     1561            if ($remainder % 2 == 0) { 
     1562                $remainder = 2*$remainder + int($remainder/2) + 1; 
     1563            } else { 
     1564                $remainder = 2*$remainder + int($remainder/2) + 2; 
     1565            } 
     1566        } 
     1567        print ' 'x$remainder, $ascii_str; 
     1568    } 
     1569    print "\n"; 
    15141570    return; 
    15151571}