Tshark - cannot display user protocol data only

I have my own protocol that runs on port 8888 (no, it's not http) and over TCP. I grabbed the packet stream into a PCAP file. The problem is that now I can not display only part of the data.

I tried the following command:

tshark -r test.pcap -R 'tcp.port==8888 && tcp.len>0' -T fields -e "tcp.data"

But it displays empty lines. Is the tcp.data strong> field that stores the TCP packet data?

How can I display only the data that I need?

+3
source share
2 answers

Wireshark has the function "Analyze / monitor the TCP stream".

TCP- , "Follow TCP stream".... Wireshark TCP- .

EDIT:

tcp.data . data.data:

tshark -r mon.pcap -R "(tcp.port == 8888) && (tcp.len > 0)" -T  fields -e data.data

wirehark , (8888), . :

tshark -r mon.pcap -R "(tcp.port == 8888) && (tcp.len > 0)" -T  fields -d tcp.port==8888,echo -e echo.data
+4

, python script, . , , , , .

#!/usr/bin/python
import subprocess
import sys
import binascii

""" Input arguments. """
if len(sys.argv) != 3 and len(sys.argv) != 4 and len(sys.argv)!= 5:
  print "[*] You didn't specify the right command line arguments."
  print "Usage:\n"
  print "\t"+sys.argv[0]+" <pcap> <port> [<src_ip> <dst_ip>]"
  print
  exit(-1)

args = len(sys.argv)
if args == 3:
  pcap = sys.argv[1]
  port = sys.argv[2]
elif args == 4:
  pcap = sys.argv[1]
  port = sys.argv[2]
  srcip = sys.argv[3]
elif args == 5:
  pcap = sys.argv[1]
  port = sys.argv[2]
  srcip = sys.argv[3]
  dstip = sys.argv[4]


""" Use tshark to read pcap file. """
targs = []
targs.append("tshark")
targs.append("-r"+pcap)
f = "-R (tcp.port=="+port+") && (tcp.len>0)"
if args == 4:
  f=f+" && (ip.src == "+srcip+")"
elif args == 5:
  f=f+" && (ip.src == "+srcip+" and ip.dst == "+dstip+")"
targs.append(f)
targs.append("-Tfields")
targs.append("-edata.data")
p = subprocess.Popen(targs, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

while True:
  """ Read a line of output from the tshark output- """
  out = p.stdout.readline()

  """ Print only non-empty lines."""
  if out != '':
    """ Parse the line appropriately and print printable characters. """
    chars = out.split(':')
    for c in chars:
      if c >= '20' and c <= '7e':
    try:
          cc = binascii.unhexlify(c)
    except:
      pass
    sys.stdout.write(cc)
      else:
        sys.stdout.write('.')
    print

  """ When there is no more data, break out of infinite loop."""
  if out == '' and p.poll() != None:
    break

p.stdout.close()

script :

-:

python tshark.py temp.pcap 8888

-:

python tshark.py temp.pcap 8888 "10.1.1.2" 

:

python tshark.py temp.pcap 8888 "10.1.1.2" "10.1.1.3"
+1

All Articles