This week I overheard a colleague in the office having exactly that problem and thought it wouldn't be too hard to build a utility to time shift pcap files by a specified amount. So here it is:
Installation
As explained in the readme, it should be possible to compile on any system with gcc using only the standard libraries. Just download the capshift.c and capshift.h files and compile (gcc -o capshift capshift.c), or download a binary if one exists for your system.
Usage
Capshift takes three arguments, all mandatory:
- The input pcap file, specified using -r
- The output pcap file, specified using -w
- The time offset value (positive or negative), specified using -o
Here's an example:
Harrys-MacBook-Air:capshift foeh$ tshark -ta -r before.cap
1 15:30:45.978539 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4748/35858, ttl=128
2 15:30:45.979407 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4748/35858, ttl=255
3 15:30:46.979315 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4749/36114, ttl=128
4 15:30:46.980274 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4749/36114, ttl=255
5 15:30:47.980323 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4750/36370, ttl=128
6 15:30:47.981215 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4750/36370, ttl=255
7 15:30:48.981387 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4751/36626, ttl=128
8 15:30:48.982277 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4751/36626, ttl=255
Harrys-MacBook-Air:capshift foeh$ capshift -r before.cap -w after.cap -o -0.5
Parsing capfile, attempting to shift backward by 0.500000 seconds...
8 frames processed.
Harrys-MacBook-Air:capshift foeh$ tshark -ta -r after.cap
1 15:30:45.478539 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4748/35858, ttl=128
2 15:30:45.479407 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4748/35858, ttl=255
3 15:30:46.479315 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4749/36114, ttl=128
4 15:30:46.480274 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4749/36114, ttl=255
5 15:30:47.480323 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4750/36370, ttl=128
6 15:30:47.481215 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4750/36370, ttl=255
7 15:30:48.481387 192.168.1.25 -> 192.168.1.1 ICMP 74 Echo (ping) request id=0x0001, seq=4751/36626, ttl=128
8 15:30:48.482277 192.168.1.1 -> 192.168.1.25 ICMP 74 Echo (ping) reply id=0x0001, seq=4751/36626, ttl=255
As usual, if you find this useful or have any feedback (good or bad) please leave a comment!
No comments:
Post a Comment