WireShark lightweight capture, can it be done? - networking

Often when I'm using WireShark, I don't really need to capture the contents of a frame. I'm essentially just making sure that some traffic is flowing, and maybe checking a few flags (FIN ACK etc). Yet the default setting is to capture everything the (filtered) NIC sees, which can fill up my HD pretty fast.
Is there a setting where you can just see the summary lines, without capturing the contents?

I don't really need to capture the contents of a frame ... I'm essentially just making sure that some traffic is flowing, and maybe checking a few flags (FIN ACK etc)
So you need only the TCP header (and all the packet data that goes before the TCP header). A typical IPv4 header is 20 bytes long, as is a typical TCP header, so, on an Ethernet, you would typically only need to capture the first 54 bytes of the packet. For IPv6, the typical header is 40 bytes long, so that, on an Ethernet, you would typically only need the first 74 bytes. However, the IPv4 and TCP headers might have options, and the IPv6 header might have extension headers, so capturing 68 bytes for IPv4 or 96 bytes for IPv4-or-IPv6 might be better
For other networks, you'd have to adjust that value based on the link-layer header length. For 802.11 when not in monitor mode, you'll probably get "fake Ethernet" headers, so the values that are used for Ethernet will work; for 802.11 in monitor mode, you might have a "radiotap" header or some other "radio metadata" header, so you'd have to look at some captures on your machine to see how big the 802.11 header + the radio metadata header would be.
Once you know the "snapshot length" you should use, you can specify it in the "Limit each packet to [ ... ] bytes" field of the interface options in Wireshark 1.8 and later or in the "Capture Options" dialog prior to 1.8.
Wireshark will still show what packet details it can given the limited amount of packet data that it captured, so you won't see only the summary lines. You will, however, get less data per packet, saving disk space.

Related

How can I tell if the current TCP segment is part of a large PDU

I'm writing a small application using libpcap, where I parse/analyze a TCP based application. I faced a situation, where application attempts to send a really large amount of data, say 64K, and TCP layer cuts it into a number of smaller segments.
Now, my question is -- how do I really tell that a TCP payload of the packet, read from pcap, is actually a chunk of a larger payload. So, in order to access original large payload, number of segments will need to be re-assembled.
TCP header has sequence field, but I don't fully understand how it can answer my question.
Also, IP header has total_length field, but it has nothing to do with TCP segmentation, it indicates IP payload size of the current packet.
I'd appreciate to get some hints. Thanks.
TCP can't help you here because it neither knows nor cares what PDUs are. You need to implement whatever protocol defines what a "large PDU" is. For example, if this is HTTP over TCP, implementing the HTTP protocol will tell you if the segment is part of a large PDU.
Because my question was - how do I tell that I have a small segment that has to be reassembled in a large packet.
That's what a message protocol is for. If, for example, the message protocol says that a PDU is a "series of characters not containing a newline character terminated by a newline character", then if you don't have a newline character, you know it's part of a larger PDU.
The concept of PDUs applies to message protocols, so if you're talking about PDUs, you must have a message protocol. The message protocol will tell you when you have an entire PDU. That's its purpose.

how to know whether the TCP ends or not?

TCP is stream to communicate and it has varying length. So in the application, how I can know whether the TCP ends or not?
In the transfom layer, The TCP packet header doesn't have a length field and its length is varying, how can the TCP layer know where is the end.
You design a protocol that runs on top of TCP that includes a length field (or a message terminator). You can look at existing protocols layered on top of TCP (such as DNS, HTTP, IRC, SMTP, SMB, and so on) to see how they do this.
To avoid pain, it helps to have a thorough understanding of several different protocols layered on top of TCP before attempting to design your own. There's a lot of subtle details you can easily get wrong.
If you look at this post, it gives a good answer.
Depending on what you are communicating with, or how you are communicating there will need to be some sort of character sequence that you look for to know that an individual message or transmission is done if you plan to leave the socket open.
n the transfom layer
I assume you mean 'transport layer'?
The TCP packet header doesn't have a length field and its length is varying
The IP header has a length field. Another one in the TCP header would be redundant.
how can the TCP layer know where is the end.
From the IP header length word, less the IP and TCP header sizes.
When a party of a TCP connection receives a FIN or RST signal it knows that the other side has stopped sending. At an API level you can call shutdown to give that signal. The other side will then get a zero length read and knows that nothing more will be coming.

Understanding [TCP ACKed unseen segment] [TCP Previous segment not captured]

We are doing some load testing on our servers and I'm using tshark to capture some data to a pcap file then using the wireshark GUI to see what errors or warnings are showing up by going to Analyze -> expert Info with my pcap loaded in..
I'm seeing various things that I'm not sure or do not completely understand yet..
Under Warnings I have:
779 Warnings for TCP: ACKed segment that wasn't captured (common at capture start)
446 TCP: Previous segment not captured (common at capture start)
An example is :
40292 0.000 xxx xxx TCP 90 [TCP ACKed unseen segment] [TCP Previous segment not captured] 11210 > 37586 [PSH, ACK] Seq=3812 Ack=28611 Win=768 Len=24 TSval=199317872 TSecr=4506547
We also ran the pcap file though a nice command that creates a command line column of data
command
tshark -i 1 -w file.pcap -c 500000
basically just saw a few things in the tcp.analysis.lost_segment column but not many..\
Anyone enlighten what might be going on? tshark not able to keep up with writing data, some other issue? False positive?
That very well may be a false positive. Like the warning message says, it is common for a capture to start in the middle of a tcp session. In those cases it does not have that information. If you are really missing acks then it is time to start looking upstream from your host for where they are disappearing. It is possible that tshark can not keep up with the data and so it is dropping some metrics. At the end of your capture it will tell you if the "kernel dropped packet" and how many. By default tshark disables dns lookup, tcpdump does not. If you use tcpdump you need to pass in the "-n" switch. If you are having a disk IO issue then you can do something like write to memory /dev/shm. BUT be careful because if your captures get very large then you can cause your machine to start swapping.
My bet is that you have some very long running tcp sessions and when you start your capture you are simply missing some parts of the tcp session due to that. Having said that, here are some of the things that I have seen cause duplicate/missing acks.
Switches - (very unlikely but sometimes they get in a sick state)
Routers - more likely than switches, but not much
Firewall - More likely than routers. Things to look for here are resource exhaustion (license, cpu, etc)
Client side filtering software - antivirus, malware detection etc.
Another cause of "TCP ACKed Unseen" is the number of packets that may get dropped in a capture. If I run an unfiltered capture for all traffic on a busy interface, I will sometimes see a large number of 'dropped' packets after stopping tshark.
On the last capture I did when I saw this, I had 2893204 packets captured, but once I hit Ctrl-C, I got a 87581 packets dropped message. Thats a 3% loss, so when wireshark opens the capture, its likely to be missing packets and report "unseen" packets.
As I mentioned, I captured a really busy interface with no capture filter, so tshark had to sort all packets, when I use a capture filter to remove some of the noise, I no longer get the error.
Acked Unseen sampleHi guys! Just some observations from what I just found in my capture:
On many occasions, the packet capture reports “ACKed segment that wasn't captured” on the client side, which alerts of the condition that the client PC has sent a data packet, the server acknowledges receipt of that packet, but the packet capture made on the client does not include the packet sent by the client
Initially, I thought it indicates a failure of the PC to record into the capture a packet it sends because “e.g., machine which is running Wireshark is slow” (https://osqa-ask.wireshark.org/questions/25593/tcp-previous-segment-not-captured-is-that-a-connectivity-issue)
However, then I noticed every time I see this “ACKed segment that wasn't captured” alert I can see a record of an “invalid” packet sent by the client PC
In the capture example above, frame 67795 sends an ACK for 10384
Even though wireshark reports Bogus IP length (0), frame 67795 is
reported to have length 13194
Frame 67800 sends an ACK for 23524
10384+13194 = 23578
23578 – 23524 = 54
54 is in fact length of the
Ethernet / IP / TCP headers (14 for Ethernt, 20 for IP, 20 for TCP)
So in fact, the frame 67796 does represent a large TCP packets (13194
bytes) which operating system tried to put on the wore
NIC driver will fragment it into smaller 1500 bytes pieces in order to transmit over the network
But Wireshark running on my PC fails to understand it is a valid packet and parse it. I believe Wireshark running on 2012 Windows
server reads these captures correctly
So after all, these “Bogus IP
length” and “ACKed segment that wasn't captured” alerts were in fact
false positives in my case
I just came across this and would like to share my observation of TCP ACKed unseen segment. In my case the client was trying to initiate connection on same source port and destination port it used previously and thus the server was confused and replied with old TCP SEQ number saying I havent seen this new packet

Which header fields characterize a packet as unique?

I'm dealing with IP packets which might contain UDP or TCP payloads.
If we only consider IP-level and transport-level headers, what could be a set of representative fields for one packet? That is, which header fields, considered as a whole, would make that packet unique? (in absence of duplicates, of course)
If we didn't consider the IP and TCP or UDP chksum fields, would a subset of the other fields be enough?
IP and UDP don't have a concept of "uniqueness". TCP does, implied by the sequence-number field. There aren't enough fields to make it clear when a packet gets duplicated or dropped in transit.
Update based on comments:
If you're writing both the sending and receiving code, you could include an IP option that identifies the packet uniquely. I'd recommend using the SATNET StreamId option (#8, see RFC 791, section 3.1) - it gives you 16 bits to work with and it's been around for over 30 years.
If you're not writing the sending code, I don't think you can do this - there just aren't any fields to base the comparison on in IP, ICMP, or UDP.
You can use the optional field of IP Header to append data for uniqueness (if you're sending) but you need to modify IHL to greater than 5.

how to reassemble tcp segment?

im now developing a project using winpcap..as i have known packets being sniffed are usually fragmented packets.
how to reassemble this TCP segements?..any ideas, suggestion or tutorials available?..
this i assume to be the only way i can view the HTTP header...
thanks!..
tcp is a byte stream protocol.
the sequence of bytes sent by your http application is encapsulated in tcp data segments and the byte stream is recreated before the data is delivered to the application on the other side.
since you are accessing the tcp datasegments using winpcap, you need to go to the data portion of the segment. the header of tcp has a fixed length of 20 bytes + an optional part which you need to determine using the winpcap api.
the length of data part in the tcp segment is determined by subtracting the tcp header length (obtained from a field in the tcp segment) and the ip header length (from a field in the ip datagram that encapsulates the tcp segment) from the total length (obtained from another field in the ip datagram).
so now you have the total segment length and the length of the data part within the segment. so you know offset where the http request data starts.
the offset is
total length-length of data part
or
length of ip-header + length of tcp header
i have not used winpcap. so you will have to find out how to get these fields using the api.
also ip datagrams may be further fragmented but i am expecting that you are provided only reassembled datagrams using this api. you are good to go!
There is no such thing as a TCP fragment. The IP protocol has fragments. TCP is a stream protocol. You can assemble the stream to its intended order by following the sequence numbers of both sides. Every TCP Packet goes to the IP level and can be fragmented there. You can assemble each packet by collecting all of the fragments and following the fragment offset from the header.
All of the information you need is in the headers. The wikipedia articles are quite useful in explaining what each field is
http://en.wikipedia.org/wiki/TCP_header#Packet_structure
http://en.wikipedia.org/wiki/IPv4#Header
PcapPlusPlus offers this capability out-of-the-box for all major OS's (including Windows). Please check out the TcpReassembly example to see a working code and the API documentation to understand how to use the TCP reassembly feature
Depending on the whose traffic you're attempting to passively reassemble, you may run into some TCP obfuscation techniques designed to confuse people trying to do exactly what you're trying to do. Check out this paper on different operating system reassembly behaviors.
libtins provides classes to perform TCP stream reassembly in a very high level way, so you don't have to worry about TCP internals to do so.

Resources