How to add arrow icon to specified output of tshark? - wireshark

Default output of tshark has an arrow icon between _ws.col.Source and _ws.col.Destination like this:
13 1.001761 192.168.1.246 → dns.google ICMP 98 Echo (ping) request id=0x1d5b, seq=48154/6844, ttl=63
When I apply my own specified output, referring to this answer, the → icon disappears.
13 1.001761 192.168.1.246 dns.google ICMP 98 Echo (ping) request id=0x1d5b, seq=48154/6844, ttl=63
What should I do to show the the → icon to the output when I need to use my own filter?

You can't achieve this using -T fields, but you can by specifying the column format option.
Compare the output of this:
tshark.exe -T fields -e frame.number -e frame.time_delta -e _ws.col.Source
-e _ws.col.Destination -e _ws.col.Protocol -e ip.len -e _ws.col.Info
... with the output of this:
Windows:
tshark.exe -o
"gui.column.format:\"No.\",\"%m\",\"DeltaTime\",\"%Gt\",\"Source\",\"%s\",\"Destination\",\"%d\",\"Protocol\",\"%p\",\"IP
Length\",\"%Cus:ip.len\",\"Info\",\"%i\""
*nix:
tshark.exe -o
'gui.column.format:"No.","%m","DeltaTime","%Gt","Source","%s","Destination","%d","Protocol","%p","IP
Length","%Cus:ip.len","Info","%i"'
Run tshark -G column-formats for more information about the column formats.

Related

How to remove colon in the tcp payload using Tshark?

I run the following
sudo tshark -c 100 -f "tcp port 80" -T json -e tcp.payload
and one of the fields I am interested in is tcp.payload and I get it in the below format
{"tcp.payload": "7b:22:6e:61:6d:65:22:3a:20:22:68:65:6c:6c:6f:22:7d"}
How can I get it in the two formats below?
{"tcp.payload": "7b226e616d65223a202268656c6c6f227d"}
{"tcp.payload": {"name": "hello"}}

Exporting encrypted SNMPv3 traps to JSON with TShark

I have a pcap file with recordings of encrypted SNMPv3 traps from Wireshark (Version 3.2.2). For analyzing the traps, I want to export the protocol data to json using tshark.
tshark.exe -T ek -Y "snmp" -P -V -x -r input.pcap > output.json
Currently, I supply the infos to decrypt the packages via the "snmp_users" file in C:\Users\developer\AppData\Roaming\Wireshark.
# This file is automatically generated, DO NOT MODIFY.
,"snmp_user","SHA1","xxxxxx","AES","yyyyyyy"
Is it possible to supply the options via commandline?
I have tried:
tshark.exe -T ek -Y "snmp" -P -V -x -o "snmp.users_table.username:snmp_user" ...
But that causes an error:
tshark: -o flag "snmp.users_table.username:snmp_user" specifies unknown preference
Update 16.09.2020:
Option -Y used instead of -J:
-Y|--display-filter
Cause the specified filter (which uses the syntax of read/display
filters, rather than that of capture filters) to be applied before
printing a decoded form of packets or writing packets to a file.
You need to specify the option as a User Access Table or uat, with the specific table being the name of the file, namely snmp_users. So, for example:
On Windows:
tshark.exe -o "uat:snmp_users:\"\",\"snmp_user\",\"SHA1\",\"xxxxxx\",\"AES\",\"yyyyyyy\"" -T ek -J "snmp" -P -V -x -r input.pcap > output.json
And on *nix:
tshark -o 'uat:snmp_users:"","snmp_user","SHA1","xxxxxx","AES","yyyyyyy"' -T ek -J "snmp" -P -V -x -r input.pcap > output.json
Unfortunately, the Wireshark documentation is currently lacking in describing the uat option. There is a Google Summer of Code project underway though, of which Wireshark is participating, so perhaps documentation will be improved here.

Converting a pcap file to csv: Tshark displays multiple src,dst IP addresses in a single line for some packets

I want to convert a pcap file to csv/tsv with "Tshark" where each line corresponds to a packet and have the following format:
timestamp src_ip dst_ip protocol
I use this command:
tshark -r <file_name.pcap> -T fields -e frame.time_epoch -e ip.src -e ip.dst -e ip.proto
However, in the displayed output I see some lines to have two src,dst IP addresses and protocol number like this:
1525794300.3842 92.153.107.1,203.46.108.229 203.46.108.229,85.50.172.78 1,1
While for the rest, each line has one src IP, one dst IP and one protocol like the following:
1525794300.3843 185.61.46.124 163.218.99.213 6
Is there any reason that tshark is displaying multiple src and dst ip addresses in a single line? Can we do something so tshark does not do this?
Thanks!
The reason tshark displays multiple src and dst IP addresses as well as multiple protocol numbers is because there are multiple IP headers in the packet. In this case, it's ICMP packet carrying information about another ICMP packet, perhaps a "Time to live exceeded in transit" or some other such error. If you open the file in Wireshark or run tshark -r <file_name.pcap> -Y "icmp", you will be able to see this for yourself.
If you're only interested in the first (outer) IP src and dst addresses and protocol number, then you can limit the output to the first occurrence of each field as follows:
tshark -r <file_name.pcap> -T fields -E occurrence=f -e frame.time_epoch -e ip.src -e ip.dst -e ip.proto
Alternatively, you can specify columns while limiting the field occurrences this way:
On *nix:
tshark -r <file_name.pcap> -o 'gui.column.format:"Epoch Time","%Cus:frame.time_epoch","Src","%Cus:ip.src:1","Dst","%Cus:ip.dst:1","Proto","%Cus:ip.proto:1"'
On Windows:
tshark.exe -r <file_name.pcap> -o "gui.column.format:\"Epoch Time\",\"%Cus:frame.time_epoch\",\"Src\",\"%Cus:ip.src:1\",\"Dst\",\"%Cus:ip.dst:1\",\"Proto\",\"%Cus:ip.proto:1\""
Run tshark -G column-formats for additional help with the column formats.

Is there a way in Wireshark to save only the packets in the listing window?

I would like to know if there is a way to save only No., Time, Source, Destination, Length field in Wireshark? I do not need the contents, I want it in plain text as well. Is this possible? Thank you.
If those are your only columns configured in Wireshark, then after loading a capture file you achieve this as follows: File -> Export Packet Dissections -> as "Plain Text" file... ->, then in the Packet Format section, select only the "Packet summary line" (and optionally "Include column headings" if you wish) and deselect everything else. Choose a filename and click "Save".
If you have other columns displayed, you can either hide or remove them first or create a separate profile with only the columns of interest displayed.
You can also accomplish this with tshark, Wireshark's command-line companion. There are several ways to do this, so select a method that best fits your needs. Here are some examples:
Using specified Wireshark columns: (Note: -e _ws.col.No. doesn't work)
tshark -r file.pcap -T fields -e frame.number -e _ws.col.Time -e _ws.col.Source -e _ws.col.Destination -e _ws.col.Length > file.txt
Using named fields: (assumes IPv4 addresses in Source and Destination columns)
tshark -r file.pcap -T fields -e frame.number -e frame.time -e ip.src -e ip.dst -e frame.len > file.txt
Rely on Wireshark's configured columns:
tshark -r file.pcap > file.txt
Rely on Wireshark's configured columns for a particular profile:
tshark -r file.pcap -C profilename > file.txt
Using column option: (First on Windows, then on *nix)
tshark -r file.pcap -o "gui.column.format:\"No.\",\"%m\",\"Time\",\"%t\",\"Source\",\"%s\",\"Destination\",\"%d\",\"Length\",\"%L\"" > file.txt
tshark -r file.pcap -o 'gui.column.format:"No.","%m","Time","%t","Source","%s","Destination","%d","Length","%L"" > file.txt
(Run tshark -G column-formats for more column options.)

Wireshark Filters: Getting the packet that was sent before the filtered one

I am trying to create a filter in Wireshark that will grab all SMB responses that return "Error: STATUS_NO_SUCH_FILE". I would also like the be able to grab the packet before the filtered ones. Here's an example:
No. Time Source Destination Proto. Length Info
26482 24.832997 192.168.1.62 192.168.1.4 SMB 288 Trans2 Request, QUERY_PATH_INFO, Query File Basic Info, Path: \1_CLIENTS\CLIENTS\ACME INC
26483 24.833122 192.168.1.4 192.168.1.62 SMB 158 Trans2 Response, QUERY_PATH_INFO
26484 24.833232 192.168.1.62 192.168.1.4 SMB 306 Trans2 Request, FIND_FIRST2, Pattern: \1_CLIENTS\CLIENTS\ACME INC\<.AC_
26485 24.833909 192.168.1.4 192.168.1.62 SMB 126 Trans2 Response, FIND_FIRST2, Error: STATUS_NO_SUCH_FILE
The following filter grabs the "STATUS_NO_SUCH_FILE" packets:
((ip.src == 192.168.1.4) && (ip.dst == 192.168.1.62)) || ((ip.src == 192.168.1.62) && (ip.dst == 192.168.1.4)) && (smb.nt_status == 0xC000000F)
But I would also like to get the packet previous to that one as well so I know which file path wasn't found.
You can use TShark, part of the Wireshark distribution, to get an overview.
Run the following command:
$ tshark -r FS01-Test.pcap -R smb.nt_status==0xc000000f -T fields -e frame.number -e smb.nt_status -e smb.response_to -E header=y -E separator=, > smb.csv
Output:
frame.number,smb.nt_status,smb.response_to
6242,0xc000000f,6238
6247,0xc000000f,6246
6331,0xc000000f,6269
6338,0xc000000f,6336
Another example:
$ tshark -r FS01-Test.pcap -R smb.nt_status==0xc000000f -T fields -e frame.number -e smb.nt_status -e smb.response_to -e smb.search_pattern -E header=y -E separator=, > smb02.csv
Output:
frame.number,smb.nt_status,smb.response_to,smb.search_pattern
6242,0xc000000f,6238,\\B\\Di\\folder.jpg
6247,0xc000000f,6246,\\B\\Di\\folder.gif
6331,0xc000000f,6269,\\B\\Ex\\folder.jpg
6338,0xc000000f,6336,\\B\\Ex\\folder.gif

Resources