2017-12-27 414 views
0

如果我在下面的文本格式,這是在fortigate或的FortiMail如何十六進制轉儲從4個十六進制數字組轉換爲2個十六進制數字組

FortiMail # diag sniffer packet port1 'tcp port 443' 3 
interfaces=[port1] 
filters=[tcp port 443] 
10.651905 192.168.0.1.50242 -> 192.168.0.2.443: syn 761714898 
0x0000 0009 0f09 0001 0009 0f89 2914 0800 4500 ..........)...E. 
0x0010 003c 73d1 4000 4006 3bc6 d157 fede ac16 .<[email protected]@.;..W.... 
0x0020 0ed8 c442 01bb 2d66 d8d2 0000 0000 a002 ...B..-f........ 
0x0030 16d0 4f72 0000 0204 05b4 0402 080a 03ab ..Or............ 
0x0040 86bb 0000 0000 0103 0303 .......... 

如何CLI數據包捕獲數據包捕獲將其轉換爲此格式,以便能夠使用text2pcap將其轉換爲pcap。因此可以在wireshark中輕鬆打開。

FortiMail # diag sniffer packet port1 'tcp port 443' 3 
interfaces=[port1] 
filters=[tcp port 443] 
10.651905 192.168.0.1.50242 -> 192.168.0.2.443: syn 761714898 
0000 00 09 0f 09 00 01 00 09 0f 89 29 14 08 00 45 00 ..........)...E. 
0010 00 3c 73 d1 40 00 40 06 3b c6 d1 57 fe de ac 16 .<[email protected]@.;..W.... 
0020 0e d8 c4 42 01 bb 2d 66 d8 d2 00 00 00 00 a0 02 ...B..-f........ 
0030 16 d0 4f 72 00 00 02 04 05 b4 04 02 08 0a 03 ab ..Or............ 
0040 86 bb 00 00 00 00 01 03 03 03 .......... 
+0

您知道初始格式,所需的格式,那麼問題是什麼?您可以使用最喜歡的編程語言編寫自己的工具,或者使用支持正則表達式的文本編輯器來進行智能文本調整。或者使用帶有宏支持的文本編輯器在多行上應用相同的操作。 –

回答

0

一個非常類似的問題被提出和回答的老Wireshark的詢問Q &站點。 Here「SA鏈接到我的回答這個問題張貼逐字下面爲了方便:


是的,你可以用text2pcap將其轉換爲一個PCAP文件,但你首先需要將數據按摩到的格式text2pcap接受,因爲描述的格式目前不支持text2pcap

因此,首先,你可以將數據通過Kurt Knochner的perl腳本轉換成合適的格式,給出的答案this問題,這裏複製的方便:

#!/usr/bin/perl 

$| = 1; 

my $regexp_time = '(\d\d:\d\d:\d\d\.\d+)'; 
my $regexp_hex = '(0x\d+:\s+)([0-9a-f ]+)+ '; 

while (<STDIN>) { 

    my $input = $_; 

    if ($input =~ /^$regexp_time/) { 
     print "$1\n"; 
    } 

    if ($input =~ /$regexp_hex/) { 
     my $counter = $1; 
     my $line = $2; 

     $line =~ s/ //g; 
     $counter =~ s/(0x|:)//g; 

     print $counter . join(' ', ($line =~ m/../g)) . "\n"; 
    } 
} 

假設tcpdump輸出被保存在一個名爲,tcpdump.txt文件,Kurt的Perl腳本保存爲convert.pl,運行:

cat tcpdump.txt | convert.pl > tcpdump_converted.txt 

一旦這樣做了,在轉換後的文件運行text2pcap

text2pcap -l 101 tcpdump_converted.txt tcpdump_converted.pcap 

請注意,這裏我指定「原始IP」封裝。有關鏈接類型,請參閱http://www.tcpdump.org/linktypes.html


我意識到不是從tcpdump產生的輸出,因此腳本可能無法正常工作究竟爲你的情況,但它不應該太困難定製以滿足您的需求如果它沒有做到你需要它開箱即用。

0

我解決了2 VIM問題替換命令

這樣一來取代所有4位十六進制爲2位十六進制

%s/\s\([0-9a-f]\{2}\)\([0-9a-f]\{2}\)/ \1 \2 /g 

而這一次刪除從行的開頭0X

%s/^0x// 

然後運行:

text2pcap in-mod.txt out.pcap 
相關問題