Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I hope somebody will be able to help me... The problem is with merging multiple .pcap files. Recently - like a week ago I've used a mergecap to merge mutiple pcap files into one. Everything worked fine.

Here is how i do it:

mergecap -w 28_30.11.dump.pcap testdump.pcap17  testdump.pcap19  testdump.pcap21  testdump.pcap23  testdump.pcap25

Here is the head of the output file (Notice the ASCII in the right hand side column):

00000000   D4 C3 B2 A1  02 00 04 00  00 00 00 00  00 00 00 00  FF FF 00 00  01 00 00 00  32 38 B3 50  7F 11 09 00  ........................28.P....
00000020   3C 00 00 00  3C 00 00 00  00 1F D0 03  A4 9C 00 25  9C 8B F5 3E  08 06 00 01  08 00 06 04  00 01 00 25  <...<..........%...>...........%
00000040   9C 8B F5 3E  01 00 00 01  00 00 00 00  00 00 01 00  00 02 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ...>............................
00000060   00 00 00 00  32 38 B3 50  89 11 09 00  2A 00 00 00  2A 00 00 00  00 25 9C 8B  F5 3E 00 1F  D0 03 A4 9C  ....28.P....*...*....%...>......
00000080   08 06 00 01  08 00 06 04  00 02 00 1F  D0 03 A4 9C  01 00 00 02  00 25 9C 8B  F5 3E 01 00  00 01 39 38  .....................%...>....98
000000A0   B3 50 C6 78  05 00 57 00  00 00 57 00  00 00 00 25  9C 8B F5 3E  00 1F D0 03  A4 9C 08 00  45 00 00 49  .P.x..W...W....%...>........E..I
000000C0   8F 7F 40 00  40 11 81 50  01 00 00 02  3E E9 E9 E9  A1 5A 00 35  00 35 44 D5  9A FF 01 00  00 01 00 00  ..@.@..P....>....Z.5.5D.........

All great. But... now when i do the same for any captured files and use command:

mergecap -w test3.pcap testdump.pcap133 testdump.pcap134 testdump.pcap135

The output file contains additional info on the at the top of the file (clearly visible in ASCII column on the right):

00000000   0A 0D 0D 0A  98 00 00 00  4D 3C 2B 1A  01 00 00 00  FF FF FF FF  FF FF FF FF  01 00 65 00  46 69 6C 65  ........M<+...............e.File
00000020   20 63 72 65  61 74 65 64  20 62 79 20  6D 65 72 67  69 6E 67 3A  20 0A 46 69  6C 65 31 3A  20 74 65 73   created by merging: .File1: tes
00000040   74 64 75 6D  70 2E 70 63  61 70 31 33  33 20 0A 46  69 6C 65 32  3A 20 74 65  73 74 64 75  6D 70 2E 70  tdump.pcap133 .File2: testdump.p
00000060   63 61 70 31  33 34 20 0A  46 69 6C 65  33 3A 20 74  65 73 74 64  75 6D 70 2E  70 63 61 70  31 33 35 20  cap134 .File3: testdump.pcap135
00000080   0A 00 00 00  04 00 08 00  6D 65 72 67  65 63 61 70  00 00 00 00  98 00 00 00  01 00 00 00  20 00 00 00  ........mergecap............ ...

Guys, I'm completely clueless - any advise (excluding cutting the first few bytes from the file) will be much appreciated.

The OS: Backtrack 5 R2 (Ubuntu derivative)

uname: Linux z 3.2.6 #1 SMP Fri Feb 17 10:40:05 EST 2012 i686 GNU/Linux

tcpdump version 4.3.0

libpcap version 1.0.0

Additional info:

ls /usr/local/bin/mergecap
-rwxr-xr-x 1 root root 37572 2012-10-31 08:09 /usr/local/bin/mergecap

 ~ > md5sum /usr/local/bin/mergecap
 e7dde01867c1e3f84dc48e5dae266f67  /usr/local/bin/mergecap

Why this a problem for me? Because i'm no longer able to read the merged file with tcpdump -r. Tcpdump is returning an error that the dump file is in bad format.

share|improve this question
    
Is the extra text actually a problem? It looks like it is part of the format and should be processed correctly by whatever downstream program you pass the files to. –  terdon Dec 10 '12 at 13:38
    
@terdon it is the problem. when i previously merged two files i was able to read the newly created pcap file with tcpdump easily using the tcpdump -r mergedfile.pcap now, with this additional info the tcpdump is returning an error : tcpdump: bad dump file format –  mnmnc Dec 10 '12 at 13:41
    
Also, why do you say that trimming the first n bites is not an option? That's what I would have suggested. –  user1301428 Dec 10 '12 at 13:50
    
@user1301428 because this is not something i would be doing once. I'm working on a bigger project that will involve highly automated process of merging files and reading. Since the number of bytes i would had to remove from file depends heavily on the file length of filename and number of files being merged - this is just not an option. –  mnmnc Dec 10 '12 at 13:52
    
What does tcpdump -h print? As tcpdump can't read the pcap-ng file that mergecap produced, it probably doesn't report libpcap version 1.1.0, or a later version of libpcap, as 1.1.0 and later can read some pcap-ng files, so a tcpdump using 1.1.0 or later can read them. –  Guy Harris Mar 25 at 2:10

2 Answers 2

up vote 0 down vote accepted

Ok. I've found the solution but not the cause.

I'll share it for future 'victims' of this misfortune ;)

As a hint i will add that: Recently i've done apt-get update & upgrade which might somehow affected my system but to be completely honest i have no idea how and why whould it impact the mergecap.

The solution is to specify the mergecap output file type manually. By default it should be libpcap but it seems my version of mergecap suddenly switched to other type of the output file and used the other type by default.

So if I use mergecap -F libpcap -w out.pcap test1.pcap test2.pcap now - it all works fine. There is no file listing or additional info at the beginning of the output file and the tcpdump reads the file correctly - hooray!

share|improve this answer
    
Newer versions of Wireshark support the "other type of output file" (pcap-ng) as the output file by default for all programs. Perhaps mergecap should, if all the input files are the same type of file, use that as the output file format as well. –  Guy Harris Mar 25 at 2:07

I think you must have done something strange, it seems to work perfectly well for me:

$ head oo.pcap.merged | hexdump -C


00000000  0a 0d 0d 0a 84 00 00 00  4d 3c 2b 1a 01 00 00 00  |........M<+.....|
00000010  ff ff ff ff ff ff ff ff  01 00 52 00 46 69 6c 65  |..........R.File|
00000020  20 63 72 65 61 74 65 64  20 62 79 20 6d 65 72 67  | created by merg|
00000030  69 6e 67 3a 20 0a 46 69  6c 65 31 3a 20 61 61 61  |ing: .File1: aaa|
00000040  61 2e 70 63 61 70 20 0a  46 69 6c 65 32 3a 20 62  |a.pcap .File2: b|
00000050  62 62 62 62 2e 70 63 61  70 20 0a 46 69 6c 65 33  |bbbb.pcap .File3|
00000060  3a 20 63 63 63 63 63 2e  70 63 61 70 20 0a 00 00  |: ccccc.pcap ...|
00000070  04 00 08 00 6d 65 72 67  65 63 61 70 00 00 00 00  |....mergecap....|

So, it is displaying the same behavior you describe, but then when I try to use tcpdump on the file, it seems to work:

$ tcpdump -r oo.pcap.merged | head
reading from file oo.pcap.merged, link-type EN10MB (Ethernet)

And then continues normally for 369 lines.

tcpdump version 4.3.0

Mergecap 1.8.0

share|improve this answer
    
Hey, thanks for trying to help. I've found a solution - i think you are using different version or the difference is because of linux distro difference. Either way my tcpdump does not read the files with file listing at the beginning of the pcap file. –  mnmnc Dec 10 '12 at 14:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.