Commit Graph

408 Commits

Author SHA1 Message Date
David Perry 3ade136df7 HTTP dissector memory management tweaks 2023-02-04 12:28:11 +00:00
John Thacker 0e93070745 follow: Add function for sub stream id to registration
When dissectors register for Follow Stream, have them register a
function for finding the next valid sub stream id for a given
stream and substream id pair. This function is NULL if the dissector
does not use sub stream IDs.

Use this function in follow_stream_dialog to update the sub stream
id widget (and use the absence of the function to disable and hide
the widget.) Use this function in the CLI tap-follow to determine
whether to parse a sub stream id from the command line options.

This removes the dependencies on epan/dissectors from the Qt
follow_stream_dialog, and gets us closer to having dissectors
being able to register for Follow Stream without having to update
anything in the common source code.
2023-01-05 05:04:33 +00:00
John Thacker 8a67ca77e6 http: Check CitrixAGBasic Auth encoding
CitrixAGBasic Authentication has Base64 encoded values. The result of
Base64 decoding is not guaranteed to be valid UTF-8 (or ASCII), so
verify it.

Also add the username and password to the credentials tap.

Fix #18677.
2022-11-30 07:54:01 -05:00
Martin Mathieson 793365d0e0 Fix some issues seen with cppcheck 2022-11-22 20:55:24 +00:00
John Thacker dcbd3874d3 tls: add support for DESEGMENT_UNTIL_FIN, sequence numbers
Add a tlsinfo struct that is similar to tcpinfo, and carries
the sequence number (within the TLS stream) and the end of
stream notification (from the TCP FIN or close_notify alerts)
in addition to the session app handle pointer already used
by TLS heuristic dissectors.

Have HTTP use the end of stream notification in order to
handle DESEGMENT_UNTIL_FIN the same way it does when HTTP
is directly over TCP. Also have HTTP use the sequence number
in order to reduce chunked processing from O(N^2) to O(N)
similar to done over TCP.

Update all the TLS heuristic dissectors that set the app
handle to use the new structure.

Note the workaround for the issue #15159 - the TLS dissector
has to report to the TCP dissector that desegmentation at FIN
is required, so that the TCP dissector will know to call the
TLS dissector at FIN. However, the TLS dissector does not request
that the TCP dissector resend bytes belonging to records that
TLS has already desegmented (and decrypted, if possible), to
avoid decrypting twice (and upsetting the decoder state.)

This can mean the TCP dissector calling the TLS dissector to
desegment at FIN with a zero byte payload. In such as case, the
TLS dissector artificially returns "1" byte dissected to avoid
indicating rejecting the payload and having the TLS (and subdissector)
layers removed. (TCP ignores the value returned when desegmenting
at FIN.)

Fix #9154. Fix #14382.
2022-11-01 10:03:35 +00:00
John Thacker 891716800b http: Store request/response data there, not in the conversation
The host, request method, request URI, and response code are
information that are local to a request/response pair. Storing
them in the conversation data struct means that we only have access
to one set of values at any one point.

Currently they are updated every time a packet is dissected,
which is fine for sequential processing but causes unexpected
behavior when scrolling the window upwards, going directly
to a packet, or filtering, among other out of order behavior.

Store the values in the per packet data, and create the
file scoped data only on the first pass. The conversation
level data will have access to the final http_req_res_t
struct, which is useful for connections that Upgrade to a
different dissector.

Also, when a response code is in the Informational 1xx category,
that means it is an interim response and the next response could
be for the same request. (This affects 100 Continue, 103 Early
Hints, etc.)

Fix #16753.
2022-11-01 09:56:41 +00:00
John Thacker 78ce2f2907 HTTP: Validate Basic Auth against UTF-8 after Base64 decoding
The result of Base64 decoding might not be valid UTF-8, so
check it as such. Also add the decoded result as a new tvb data
source, so that it's easier to do other manipulations on it from
the GUI in case it isn't UTF-8.

Note that RFC 7617 says that the encoding is only known to be
UTF-8 if the charset parameter was used in the WWW-Authenticate
header, so perhaps this should be a FT_BYTES using
BASE_SHOW_UTF_8_PRINTABLE

Fix #18408
2022-10-11 23:19:11 +00:00
John Thacker eab41f440a http: Fix location_target length regression
The strndup expression accidentally got changed as part of
commit 71e6b0498a to use the
offset instead of the length value.
2022-09-25 07:14:05 -04:00
John Thacker 43073bff09 http: Use the header value length after sanitization
UTF-8 sanitization can change a string's byte length, so
use the correct length now that we're sanitizing it.

Fix #18372. Fix #18373.
2022-09-25 07:03:00 -04:00
John Thacker 44f733dfee http: Handle field value encoding
RFCs 9110 5.5 is explicit about allowed characters in field values:
"Specification for newly defined fields SHOULD limit their values
to visible US-ASCII octets (VCHAR), SP, and HTAB. A recipient SHOULD
treat other allowed octets in field content (i.e., obs-text [%x80-FF])
as opaque data...  Field values containing CR, LF, or NUL characters
are invalid and dangerous."

Up to RFC 7230, an obsolete "line-folding" mechanism that included
CRLF was allowed.

So NUL is not allowed, and all the known fields we support only allow
ASCII, so for display purposes it is permissible to retrieve the
value as ASCII. tvb_get_string_enc with ENC_ASCII does actually
retrieve a buffer of the full length with internal NULs if they
are in the buffer, but other functions end up truncating the value
at the first null if it exists. We should eventually have expert infos
that flag internal NULs or other invalid values with varying degrees of
severity, and display unknown header types with invalid values as
something like FT_BYTES with BASE_SHOW_ASCII_PRINTABLE.

Continue, for now, to pass along the raw value in the header_value_map
in case some dissector was using that value.

Fix #18368.
2022-09-24 01:38:05 +00:00
John Thacker d0f7af3850 HTTP: sanitize encoding header field strings
Sanitize HTTP header values before adding them to the tree.
We treat them as always US-ASCII. (Note, however, that RFC
7230 discusses that while "Newly defined header fields SHOULD
limit their field values to US-ASCII octets. A recipient SHOULD
treat other octets in field content as opaque data.")

Fix #18362. Fix #18363.
2022-09-23 00:12:37 -04:00
John Thacker 2762c64010 follow: Have followers register their stream count function
Instead of having the UI have to know about each type of follow
stream, and how to retrieve its total number of streams, have
each follow type register a function that returns the total
number of stream. (The function can be NULL, for protocols like
SIP that do not use this.)

This gets us closer to making follow stream registration generic.
2022-09-14 00:03:07 +00:00
John Thacker cd8dca85a7 http: Fix a problem with a key expiring
The tcpinfo struct is declared on the stack in dissect_tcp. If we need
to use a member of it (seq) as a key in a map that is declared at file
scope, just use the integer directly with GUINT_TO_POINTER.

Fix #17854 (at least one instance of it; the issue can crop up in a number
of subtle ways.)
2022-08-31 21:18:42 -04:00
Guy Harris 8195bdd340 Rename a bunch of things with "conversation".
A conversation in Wireshark might have two endpoints or might have no
endpoints; few if any have one endpoint.  Distinguish between
conversations and endpoints.
2022-08-25 20:02:20 -07:00
John Thacker d8e877f610 HTTP: Test the first header line in a PDU more
For a PDU where we haven't seen a request, response, or
header line yet, check to see if the header name is valid
before deciding that it is a header. Prevents many false
positives on continuation data that happens to have a line
end and a colon, where we couldn't do desegmentation for
some reason.
2022-08-25 01:08:54 +00:00
John Thacker cbe4cd926c HTTP: Send binary Continuation Data to Follow Stream
If we shortcut the HTTP header check because the file starts with
a non-ASCII character, but we think that it is Continuation Data
because we've seen real HTTP in the same conversation, mark the
data as file data and send it to the follow tap, just as we would
if it failed the more extensive checks for being a header. Deals
with cases where desegmentation isn't performed (whether because
of prefs, missing packets, bad checksums, etc.)

Related to #13918.
2022-08-22 03:58:30 +00:00
John Thacker 13df9b0b64 HTTP: Speed up chunked Transfer-Encoding on TCP
HTTP/1.1 chunked Transfer-Encoding doesn't have a overall length,
but requires scanning through variable length chunks to find the
end. If we determine that additional segments are needed, and
we have a sequence number (or other identifier) for the message,
store the position of the last chunk size found.

Use this to start scanning at that same offset when the next
segment arrives, reducing the algorithm for determining if
when we have the complete chunked message from O(N^2) to O(N),
which can be significant on captures with many chunks.

This does most of #14382, reducing the length of time to process
a file with 2 pass tshark from over 8.5 secs to under 3 seconds
on my machine. There is still some O(N^2) contribution from the
reassembly code itself with many small fragments (see #17311).

Other dissectors need some small changes to enable this for
HTTP over other transport layers. (TLS would be fairly easy and
is the other important case.)
2022-08-10 05:31:36 +00:00
John Thacker 203cd2cba9 prefs: More cleanup, auto prefs
Remove callback function from pref registrations for dissectors that
don't need a callback. In other dissectors, move registration that
only needs to be done once inside the check for initialization,
avoiding some console messages when preferences are changed
("Duplicate dissectors (anonymous) and (anonymous) for protocol...")
and the like.

Add a couple auto preferences for dissectors missed in previous waves.

Ping #14319
2022-08-09 06:21:05 +00:00
Huang Qiangxiong a618fe72a2 GRPC: Fix the bug of GRPC-WEB decompression failure over HTTP1.1
1. Passing header name/value map to sub-dissector in packet-http.c.
   Headers can also be used by dissectors other than grpc in the future.

2. Try to get the grpc-encoding header value in packet-grpc.c.
   This header contains decompression algorithm.
2022-07-28 01:10:44 +00:00
Anders Broman fed641fc27 http: Add path components to tree 2022-07-04 17:45:08 +00:00
John Thacker e49a69f361 HTTP: Add chunks as items instead of calling data dissector
HTTP chunked transfer encoding can have lots of chunks, and calling
the data dissector for each individual chunk adds a large number of
layers to the frame and doesn't really make sense. (As opposed to
calling the data dissector on the reassembled data if we can't handle
the content type, which does make sense.) In particular, this can
cause a failed assertion by adding more layers than
PINFO_LAYER_MAX_RECURSION_DEPTH.

Just add each data chunk as a FT_BYTES item. Fix #18130.
2022-06-25 20:28:10 +00:00
Roland Knall 2cf938cfa8 tap: Adding flags for tap_packet
This allows flags to be passed by the registering listener
to the collection of information
2022-06-10 05:46:15 +00:00
John Thacker 37a0054551 http: Pass data relative to the original offset to follow tap
dissect_http_message might get called with a nonzero offset into
the tvb if there are multiple messages/segments in a frame. Only
send data starting from that offset to the follow tap, instead of
starting at tvb offset 0. Fix #18006
2022-03-18 21:11:09 +00:00
João Valverde 8efad466c4 Tools: Fix fix-encoding-args.pl ASCII string validation
Do not require a useless ENC_NA parameter for string encodings.
FT_STRING and FT_STRINGZ types don't have any ndianness.

Follow-up to 6ec429622c.
2022-02-15 11:38:16 +00:00
Moshe Kaplan 67f05835ca Fix more repeated words throughout
Fixes more repeated words seen throughout
the code base.
2021-12-31 22:50:40 +00:00
João Valverde 0ccd69e530 Replace g_strdup_printf() with ws_strdup_printf()
Use macros from inttypes.h.
2021-12-19 21:21:58 +00:00
João Valverde 22ee2764a7 Replace g_snprintf() with snprintf() (dissectors)
Use macros from inttypes.h with format strings.
2021-12-19 20:25:11 +00:00
João Valverde 19dcb725b6 epan: Remove STR_ASCII and STR_UNICODE
These display bases work to replace unprintable characters so the
name is a misnomer. In addition they are the same option and this
display behaviour is not something that is configurable.

This does not affect encodings because all our internal text strings
need to be valid UTF-8 and the source encoding is specified using
ENC_*.

Remove the assertion for valid UTF-8 in proto.c because
tvb_get_*_string() must return a valid UTF-8 string, always, and we
don't need to assert that, it is expensive.
2021-12-03 04:35:56 +00:00
Evan Huus cdfab0d6e9 tvbuff: convert helper methods to pinfo->pool
A few of them just needed scratch memory, so allocate and free it
manually after doing any exception-raising checks.

A few others were returning memory, and needed conversion to accept a
wmem scope argument.
2021-09-01 03:54:52 +00:00
Nardi Ivan 26dd456e62 HTTP: fix typo in dissect_http_heur_tls()
Fixes: a1a2b536
Close #17414
2021-05-31 07:56:46 +00:00
Dirk Römmen a1a2b53663 BACnet: BACnet revision 22 secure connect datalink implementation.
- Implements the BACnet /SC datalink using encrypted TLS communication
over TCP/IP and the websocket protocol.
- Updated list of vendor ID's
- Added new BACnet services Who-Am-I / You-Are
- Some corrections for revision 22.
- Fixed bug issue #17142
2021-05-19 13:21:48 +00:00
Dario Lombardo 9d3069fe7d
http: fix compilation without zlib and brotli. 2021-05-17 10:06:08 +02:00
Uli Heilmeier 0630631e88 HTTP: Disabled decompression is not an error
When a user disabled decompression we shoudn't report this as an error.
2021-05-15 20:14:30 +00:00
Anders Broman 71e6b0498a http: Add dissection of HTTP2-Settings
Closes #17370
2021-05-08 17:14:45 +00:00
Dario Lombardo ea929d6401 wsutils: add local implementation of g_memdup2.
g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68,
we provide our own copy of g_memdup2() for older GLib versions.
2021-03-25 09:38:10 +00:00
Jaap Keuter 0250e4e2e4 HTTP: Restore SSTP support
Add exclusion for SSTP having Contents-Length and no body.
Closes #17024
2020-11-18 12:48:47 +00:00
Jamie Hare cf83a67fd3 IPPUSB Protocol
Added a dissector to reassemble IPP Over USB packets and pass them to
the HTTP dissector. Added a display filter so IPPUSB packets can be
filtered. Dissector checks to ensure semgent is IPPUSB and supports
reassembly of send-documents and print-job documents. It also supports
the reassembly and dissection of packets that are truncted or
incomplete.

Change-Id: Icc9525592c07b00baaac887a70bc9e7568273016
2020-10-16 08:49:48 +00:00
Ronnie Sahlberg 9ad3d14ea4 http: don't try to dissect zero-length bodies
Closes #16844

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2020-10-01 07:49:33 +10:00
Anders Broman 9f7a06ff88 http: Put the Digest parameters in a subtree. 2020-09-14 14:30:23 +02:00
Moshe Kaplan fd7895d37c Replace instances of wmem_alloc with wmem_new
This commit replaces instances of
  (myobj *)wmem_alloc(wmem_file_scope(), sizeof(myobj))
and replaces them with:
  wmem_new(wmem_file_scope(), myobj)
to improve the readability of Wireshark's code.

The replacement locations were identified with grep
and replaced with the Python script below.

grep command:
  egrep "wmem_alloc0?\(wmem_file_scope\(\), sizeof\([a-z_]+\)\)" . -R -l

python script:

import re
import sys
import fileinput

pattern = r'\(([^\s]+) ?\*\) ?wmem_alloc(0?)\((wmem_[a-z]+_scope\(\)), sizeof\(\1\)\)'
replacewith = r'wmem_new\2(\3, \1)'

fname = sys.argv[1]

for line in fileinput.input(fname, inplace=1, mode='rb'):
    output = re.sub(pattern, replacewith, line)
    sys.stdout.write(output)

Change-Id: Ieac246c104bf01e32cbc6e11e53e81c7f639d870
Reviewed-on: https://code.wireshark.org/review/37158
Petri-Dish: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
2020-05-07 14:47:54 +00:00
Orgad Shaneh 32679c14be Introduce AudioCodes Debug Recording (ACDR) dissector
ACDR is a protocol over UDP that is used by AudioCodes devices for
recording traffic to and from the device.

It adds a header to each packet that contains extra data about the packet.

For some packet types (like SIP), it also appends the IP and UDP/TCP
headers of the sent/received packet.

The dissector unwraps the ACDR header, and displays the packets with the
original type (and when available, with the original addresses).

Bug: 16275
Change-Id: I19ad90053a2ef73da80881dc5e94aa362de23ea3
Reviewed-on: https://code.wireshark.org/review/35417
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2020-02-13 23:26:15 +00:00
Peter Wu e9014030fe HTTP: Fix dissection of data following the HTTP Upgrade response
When a HTTP response includes HTTP headers and a subset of data for the
subdissector in the same frame, be sure to skip the HTTP headers for
reassembly of the latter data. Otherwise the HTTP headers will be
misinterpreted as the subprotocol (for example, WebSocket).

Bug: 16274
Change-Id: Ida6f6f2f7d0c463be2d498bfde5e8a9cd11a4b25
Reviewed-on: https://code.wireshark.org/review/35536
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-12-31 17:24:47 +00:00
Alexis La Goutte b0ea9e0760 HTTP: Add Too Early (425) HTTP Error code (RC8470)
Change-Id: Idbc67da75ad75803a01f17ae3ff6f8f677670db8
Reviewed-on: https://code.wireshark.org/review/35191
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-11-26 12:55:47 +00:00
Guy Harris 20800366dd HTTPS (almost) everywhere.
Change all wireshark.org URLs to use https.

Fix some broken links while we're at it.

Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c
Reviewed-on: https://code.wireshark.org/review/34089
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-26 18:44:40 +00:00
Dario Lombardo aa434673bf credentials: don't use wmem file scope but a local copy.
Change-Id: I44ca95bffd682a7f2e83b71400937a949f5886ea
Reviewed-on: https://code.wireshark.org/review/33844
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2019-07-05 12:26:44 +00:00
Dario Lombardo baa22b3829 http: make a copy of the username.
The commit 0c5b14395e fixed a leak
but introduced a regression since the username gets freed while it's
still needed. We need to make a copy here.

Change-Id: Id45c1b8f98c9649a0ead30ec6cacdd6c44b923bd
Reviewed-on: https://code.wireshark.org/review/33821
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
2019-07-03 08:21:10 +00:00
Dario Lombardo 6e17af19ee http: remove unneeded allocation.
Change-Id: I684f5e35647c6ea90fc1e8f1f2a0d02446ba3297
Reviewed-on: https://code.wireshark.org/review/33819
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2019-07-03 07:49:16 +00:00
Pascal Quantin 0c5b14395e HTTP: fix a memory leak in basic_auth_credentials()
Change-Id: I19579a4177e5f67e9fb99e603033e38d389508f2
Reviewed-on: https://code.wireshark.org/review/33802
Petri-Dish: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-07-01 15:16:32 +00:00
Pascal Quantin fd4c640b1a HTTP: check auth pointer validity
Bug: 15890
Change-Id: I60144d3f8607a4761a5673e88c9c65f2f5d21145
Reviewed-on: https://code.wireshark.org/review/33801
Reviewed-by: Pascal Quantin <pascal@wireshark.org>
Petri-Dish: Pascal Quantin <pascal@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-07-01 15:15:43 +00:00
Dario Lombardo 1af6e1f860 tap: add credentials tap.
This new tap collects credentials (username and paassword)
from the dissectors.

So far, few dissectors have been instrumented:
- http (basic auth)
- http (header auth)
- ftp
Others can be instrumented as well using the same technique.

Tshark has a new option (-z credentials) and Wireshark a new
"tools" menu: the documentation has been updated accordingly.

Change-Id: I2d0d96598c85bb3ea4fb5ec090dd8dc28b481fc9
Reviewed-on: https://code.wireshark.org/review/33453
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2019-06-26 07:09:54 +00:00