How to find out tshark boolean filter is empty? - tshark

I have a tshark with the following usage:
tshark -r my_pcap_file.pcap -Y 'my and boolean statement'
Now, I want to write a capture file with -w , But before any writing file, I have to find out my tshark is empty or not.
How to can I do it?

Related

tshark show payload as text

I am trying to get tshark to show the payload of packages in clear text and I am failing in that. Which makes me really sad.
tshark -r pcap -T fiels -e data (or data.text) gives blank results.
tshark -r pcap -T fiels -e tcp.payload gives hex results.
So the question is how do I get tshark to show the tcp.payload als text (ascii).

tshark - how to avoid to select null or empty http.referer fileds

On Tshark v. 3.0.5., I am trying to run these commands in order to select URLs typed directly from the user. So I need to exclude http.referer filed that are empty (on null).
tshark -Y "http.request == 1 and **!http.referer**" -T fields -e frame.time -e http.referer -e http.host -r traffic.pcap > no_referer.txt
bash: !http.referer: event not found
tshark -Y "http.request == 1 and **http.referer == ""**" -T fields -e frame.time -e http.referer -e http.host -r traffic.pcap > no_referer.txt
Running as user "root" and group "root". This could be dangerous.
tshark: Unexpected end of filter string.
Do you have any idea about how can I select this data on tshark?
Bash will expand ** in your display filter to something you probably don't want because you are using double quotes. You can use single quotes to ensure that bash doesn't change the contents of the display filter.
Per wireshark http docs, http.referer is a string, so checking against empty values is checking against "". So use http.referer and !http.referer == "" to get packets that have this field, but also where the field is not empty.
tshark -Y 'http.request == 1 and http.referrer and !http.referer == ""' ...
Note: field != value and !field == value are different, and the latter is preferred. dftest can be used to demonstrate why this is.

Determining throughput from pcap containing flow records

I have a single packet capture (acquired via tcpdump) that contains flow records between an exporter and a collector.
I want to determine throughput across a given interface using the bytes (octets) field in the v9 record. I have filtered down to the network that I want like so:
tshark -r input.pcap -Y "ip.src == X.X.X.X" -F pcap -w filtered.pcap
I further filtered to the interface that I needed like so:
tshark -r filtered.pcap -Y "cflow.inputint == Y" -F pcap -w filtered2.pcap
I'm lost after that. Is there a better tool to aggregate across the flows to get throughput?
Any help would be greatly appreciated!
You may try to print netflow fields and then process the results.
For example:
tshark -T fields -e cflow.version -e cflow.srcaddr -e cflow.dstaddr -e cflow.octets -e cflow.timedelta -e cflow.abstimestart
Field names are visible in wireshark status bar when you select packet details.
Better option:
install or compile https://github.com/phaag/nfdump with --enable-readpcap flag.
process your pcap nfcapd -f <path to your pcap file> -l <path to output directory> -T all
count statistics nfdump -o extended -r <path to output directory>

Searching through many pcap files with tcpdump

I have a bunch of pcap files that I got with tcpdump. I need to search through all of them for specific keywords and record which files contain these strings. Is there a way to automate the search for these keywords using a tcpdump command perhaps?
Probably the most generic solution using tshark would be to run something like:
tshark -r file.pcap -Y "frame contains foo"
... where foo is the string you're searching for. Refer to the wireshark-filter man page for more information on filtering using the contains and other operators, such as the matches operator which supports Perl compatible regular expressions.
Using that command, the output you'll see will be a 1-line summary of each packet matching the filter. You could tailor the output using a number of methods, but for example, suppose you only wanted to know the frame number of the matching packet, you could run:
tshark -r file.pcap -Y "frame contains foo" -T fields -e frame.number
Refer to the tshark man page for more information on the -T and -e options, as well as other options which may be of use to you.
There is more powerful version of tcpdump, tshark (it is the command line tool from wireshark package). You could use tshark -T fields|pdml|ps|psml|text to dump packets in format you like, and just grep it. tshark could read tcpdump dumps.

how to retrive a perl file using wget and execute it using a one-liner?

I'm looking to use wget to retrieve a perl file and execute it in one line. Does anyone know if this is possible/how I would go about doing this?
In order to use wget for this purpose, you would use the -O flag and give it the '-' character as an argument. From the manpage:
-O file
--output-document=file
Giving '-' as the "file" option to -O tells it to send it's output to stdout, which can then be piped into the Perl command.
You can provide the -q flag as well to turn off wget's own warning and message output:
-q
--quiet
Turn off Wget's output.
This will make things look cleaner in the shell.
So you would end up with something like:
wget -qO - http://127.0.0.1/myscript.pl | perl -
For more information on I/O redirection take a look at this:
http://www.tldp.org/LDP/abs/html/io-redirection.html
Just download and pipe to perl
curl -L http://your_location.pl | perl -
You'll sometimes see code like for install modules like cpanm.