start capturing with command line in libpcap format - wireshark

I try to start capturing with Wireshark using command line but the default output file is pcap extension but Wireshark - pcapng file type and I need libpcap file type.
My command is
tshark.exe" -i interfacenumber -W MyFile.pcap
I also tried
tshark.exe" -i 1 -F libpcap -W MyFile.pcap
and in this case no file created on my disk although I can see the packets in the command line window

tshark.exe -i 1 -F libpcap -w MyFile.pcap`
is the right answer (note the lower case 'w').
(-W does something different. There's lot's of tshark options, so you need to look carefully at the tshark -h output to make sure you're using the right option).

Since the -F libpcap option is not working for me either, I'm using another command line tool in the same directory:
editcap -F libpcap currentFile.pcap(ng) libpcapConvertedFile.pcap where "currentFile.whatever" is the pcapng-formatted file and "libpcapConvertedFile.whatever" is the outputted legacy libpcap format.
I run this once tshark is done capturing the original file.

I think that in the newest Wireshark versions (1.8.x or 1.10.x) you cannot start capturing in libpcap format and the default format is pcapng (also pcap extension - try to use verion 1.6.x)
That's what solve my problem
http://www.wireshark.org/download/win64/all-versions/
http://www.wireshark.org/download/win32/all-versions/

Related

Where packets are stored on tshark using live capture?

I'm writing a real time sniffer using python and tshark and I'm a bit worried about where packets or data are stored in tshark. The idea is being able to execute the python script for days or weeks without stopping it and I'm not really sure if this concern could be a problem.
I have studied and have tried to understand tshark source code from here but I didn't found any line of code concerning this issue.
Is there anyone who knows how this works?
Thank you.
So, by query, the packets captured on the interfaces are applied with the "filter" of the TShark options, and then redirected to the stdout. However, there exists provision to redirect it to specific log file, in specified format.
For Example:
tshark -T json -i eth0 -O UDP -n > log.out
For more options, refer here.

Used `tar -xz` without `f` and now program stuck

Strangely, I had assumed the -f option was for "force", not for "file".
I ran tar -xz because I wanted to see if any files would be overwritten. Now it has extracted all the files but has not returned control back to me. Should I just kill the process? Is it waiting for input?
-f commands tar to read the archive from a file. Without it, it tries to read it from stdin.
You can input Ctrl-C to kill it or Ctrl-D (Ctrl-Z in Windows) to send it EOF (at which point, it'll probably complain about incorrect archive format).
Without an -f option, tar will attempt to read from the TAPE device specified by the TAPE environment variable, or a file built into tar (usually something like /dev/st0 or stdin) if TAPE isn't set to anything.

How to extract the "info" field from a pcap file?

I have a pcap file with me and I opened it in Wireshark, I want to extract a specific field basically the "Info" field from the pcap trace and port it to a text file, which I can then parse and use for data analysis. I looked up certain StackOverflow posts and those posts mentioned to use TShark, but I couldn't find any way of extracting the "info" field using TShark. It would be great if someone could point me to an automated way of dumping field specific data to a text file. I have also pasted the image of the wireshark dump for convenience.
With tshark version 1.12.0 or later:
tshark -r inFile.pcap -T fields -e _ws.col.Info > outFile.csv
tshark -r FILE -T fields -e col.info
All of these options are documented in the manual: http://www.wireshark.org/docs/man-pages/tshark.html

Setting ESP Preferences from commandline using tshark

There is a scripting need where i have to set the ESP preferences using tshark commandline. Does any one have idea how to pass this preferences from tshark commandline Ex: below
tshark -R "sip" -2 -r 131104_pcap.pcap -o esp.enable_null_encryption_decode_heuristic:true
I tried using the above command but getting the error "unknown preference" (May be because -o specifies change in preferences rather than esap_sa) I am using wireshark 1.8 on my pc. I see a file esp_sa in \Appdata\wireshark\ with below line "IPv4","","","*","AES-CBC [RFC3602]","0x3732297C3619A67029FA2C045869EDE1","HMAC-MD5-96 [RFC2403]","0x2B9F652AC3C0E6AEF19B82B060F28E6A" after adding the same from GUI. Also i see preferences file in the same location
So Is there any way to change this esp_qa using tshark line ??
The above command (with, of course, a different SIP capture file) works with my 1.8 version of tshark (i.e. no "unknown preference" message).
So: is this a "regions and languages" localization issue ?
Are you able to specify any preference ? For example:
tshark -o tcp.summary_in_tree:false

How to make output of any shell command unbuffered?

Is there a way to run shell commands without output buffering?
For example, hexdump file | ./my_script will only pass input from hexdump to my_script in buffered chunks, not line by line.
Actually I want to know a general solution how to make any command unbuffered?
Try stdbuf, included in GNU coreutils and thus virtually any Linux distro. This sets the buffer length for input, output and error to zero:
stdbuf -i0 -o0 -e0 command
The command unbuffer from the expect package disables the output buffering:
Ubuntu Manpage: unbuffer - unbuffer output
Example usage:
unbuffer hexdump file | ./my_script
AFAIK, you can't do it without ugly hacks. Writing to a pipe (or reading from it) automatically turns on full buffering and there is nothing you can do about it :-(. "Line buffering" (which is what you want) is only used when reading/writing a terminal. The ugly hacks exactly do this: They connect a program to a pseudo-terminal, so that the other tools in the pipe read/write from that terminal in line buffering mode. The whole problem is described here:
http://www.pixelbeat.org/programming/stdio_buffering/
The page has also some suggestions (the aforementioned "ugly hacks") what to do, i.e. using unbuffer or pulling some tricks with LD_PRELOAD.
You could also use the script command to make the output of hexdump line-buffered (hexdump will be run in a pseudo terminal which tricks hexdump into thinking its writing its stdout to a terminal, and not to a pipe).
# cf. http://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe/
stty -echo -onlcr
script -q /dev/null hexdump file | ./my_script # FreeBSD, Mac OS X
script -q -c "hexdump file" /dev/null | ./my_script # Linux
stty echo onlcr
One should use grep or egrep "--line-buffered" options to solve this. no other tools needed.

Resources