141 Commits
Author SHA1 Message Date
basil00 97101072db Fix previous commit 8bda0af
Fix #294

Previous commit was incomplete.
2022-04-10 06:51:38 +08:00
basil00 8bda0aff7b Fix handling of FwpmTransaction*() errors.
Fixes #294
2022-04-09 09:49:45 +08:00
basil00 8cdddce6ac Send an ICMP(V6) message if the packet is too big
Fix #278

The Miniport driver will reject any outbound
packet that is larger than the MTU.  However the
error flows back to the sending application as
an error code/condition, which is disrupted by
WinDivert, meaning the error is lost.

This change translates the error code into an
ICMP(V6) "packet too big" message, allowing for
the error to flow back to the origin in some
form.

This change required some refactoring.
2021-10-22 07:34:23 +08:00
basil00 227a6b1e78 Fix #283 2021-09-11 07:09:51 +08:00
basil00 134dd37bd0 Insert all WinDivert sublayers at the max weight. 2020-09-03 08:12:39 +08:00
basil00 97056af256 Cleanup the provider code. 2020-06-26 08:53:18 +08:00
Zhou Yicheng 32af280add Install provider to pass HLK test 2020-06-22 11:08:51 +08:00
basil00 091ffb3d49 Reformatting 2019-10-06 08:19:23 +08:00
zzzjim 160d983960 Inject on different handles for inbound/outbound 2019-10-04 19:11:25 -07:00
basil00 69b4620277 Log a system event on driver (un)load.
This allows WinDivert to be detected without
using the REFLECT API.
2019-10-04 08:57:30 +08:00
basil00 0c773bc08f Fix batch parsing bug. 2019-09-29 07:27:04 +08:00
basil00 eba2e59e3b Ensure RC file included in MSVC build. 2019-09-29 07:15:41 +08:00
basil00 a1173fe08f Coalesce filter interpreter implementations.
Replace the dual kernel/user-mode filter
interpreters with a single shared implementation.
2019-08-17 09:31:46 +08:00
basil00 a240329323 Add "fragment" to filter language.
True if the packet is an IPv4/IPv6 fragment.
2019-08-15 09:08:46 +08:00
basil00 317e6f1099 Implement new packet parser(s) for WinDivert.
The new parser should better handle fragments
as well as be consistent with the kernel-mode
parser.  The new parser can also handle truncated
packets.
2019-08-12 07:50:49 +08:00
basil00 194d9afa1e Towards WinDivert version 2.1 release.
- inbounds/outbound now work for SOCKET layer.
- passthru.exe now uses MTU_MAX to prevent 122
  errors.
- Further header parsing code hardening.
- Fix bug where Reserved2 was not zeroed.
2019-08-04 08:11:43 +08:00
basil00 69e4edade7 Add new WINDIVERT_FLAG_FRAGMENTS flag (fix #191).
This flag only affects inbound packets at the
WINDIVERT_LAYER_NETWORK layer.

If set, the handle will capture IP fragments,
but not reassembled IP packets.

If unset (the default), the handle will capture
reassembled IP packets, but not IP fragments.
2019-08-02 08:32:50 +08:00
basil00 6eb82d08e0 Fix WinDivert 2.0 driver bugs.
- BSOD for incomplete transport headers (#202).
- Fix enforcement of wrong MTU.
- Fix missing endpoint handles for IPV6 flow
  layer.
2019-07-31 08:46:01 +08:00
basil00 5d62e2a938 Add a Visual Studio build system (fix #118).
Currently the VS build system targets VS2015, but
may also work for later versions (not tested).
To use:
- Download & install VS2015.
- Install WDK.
- Open a Developer Command Prompt.
- Run the msvc-build.bat script.
2019-04-19 09:52:36 +08:00
basil00 40a22f0cf5 Fix #168 2019-03-21 19:25:46 +08:00
basil00 e306d0058b WinDivert filter language improvements.
- Add "length" for total packet length.
- Add "timestamp" for timestamp filtering.
- All filter language numbers are now signed.
- Add new macros: TRUE, FALSE, TCP, UDP, ICMP &
  ICMPV6.
- Future-proof the WINDIVERT_FILTER struct.
2019-03-15 08:01:10 +08:00
basil00 d29688ea83 Redesign the WinDivert SOCKET layer.
- Socket (& flow) events are now associated with
  a endpointId/parentEndpointId pair that allows
  the tracking of socket operations.
- A single socket CLOSE event replaces the UNBIND
  and DISCONNECT events.
- A new flag addr.Sniffed indicates if the event
  was sniffed or not.  Some events (CLOSE) are
  always sniffed, regardless of the flags.
- All filter language numbers are now 128bit.
- socketdump.exe can now optionally block events.
2019-03-13 08:33:12 +08:00
basil00 4289e7ec2b Fix 64/32 driver & DLL compatibility. 2019-03-11 07:27:00 +08:00
basil00 a5e525d436 WinDivert driver refactoring + bug fixes. 2019-03-08 09:17:52 +08:00
basil00 20382a9a75 Reverse order of WinDivert handle priorities.
Higher values now correspond to higher
priorities.
2019-03-06 09:08:48 +08:00
basil00 45e0ea4e12 Fix 32bit build. 2019-03-02 08:31:51 +08:00
basil00 d0e8106158 Update copyright year. 2019-03-02 08:20:19 +08:00
basil00 eb75e63431 Add WINDIVERT_PARAM_VERSION_* parameters.
This makes it possible for the user application
to determine the exact driver version.

Also update documentation and tests.
2019-02-28 09:23:08 +08:00
basil00 c084c8239b WinDivert security improvements.
(1) WinDivert will now reference the PROCESS that
opened the handle, and will not deref until the
handle is closed & all corresponding REFLECT
events have been completed.  This means the OPEN
REFLECT event will always return a valid PID.

(2) The packet queue size now also accounts for
internal overheads.
2019-02-27 08:57:10 +08:00
basil00 7fa04945c0 Various WinDivert improvements.
- Add UNBIND/DISCONNECT events to the SOCKET
  layer.  These events can only be sniffed.
- Remove the RECV_PARTIAL flag.  The user
  application can just ignore the error code
  instead.
- WINDIVERT_ADDRESS is now 64bytes.  Some extra
  padding added for future-proofing.
- Ignore SOCKET-layer REAUTHORIZE.
- The REFLECT layer returns the filter object
  directly (no IPv4 "pseudo" packet).
2019-02-25 09:15:33 +08:00
basil00 32c5aa90f4 Redesign the WinDivert IOCTL interface.
The idea is to make future versions of the
WinDivert DLL compatible with older SYS and vice
versa.

The interface has also been streamlined so less
system calls are required when the handle is first
opened.
2019-02-23 09:38:18 +08:00
basil00 b7860e3ff5 Add a new WinDivertHelperDecrementTTL() function.
This function decrements the ip.TTL or
ipv6.HopLimit field.  For ipv4, it also updates
the checksum.

Also:
- Make WinDivertHelperParsePacket() work on a
  single packet unless the pNext parameters are
  provided.
- Update documentation.
2019-02-20 07:57:40 +08:00
basil00 ab50ffebd5 Minor API improvements.
- addr.Pseudo*Checksum flags replaced by simpler
  addr.*Checksum flags.
- WinDivertHelperParsePacket() can now handle
  batched packets.
- WinDivertHelperParsePacket() can now return the
  transport protocol.
- WinDivertHelperCalcChecksums() can now handle
  batched packets.
- WinDivertHelperCalcChecksums() now sets address
  checksum flags that were calculated.
- A bunch of WINDIVERT_* macros have been moved
  to windivert.h for windivert_device.h.
2019-02-17 11:08:10 +08:00
basil00 22a5ad0996 Expand test suite & fix bugs. 2018-11-28 08:28:38 +08:00
basil00 2e334c9133 Fix bignum bug & add more tests. 2018-11-25 09:47:27 +08:00
basil00 ebe1af330b Add "priority" filtering for the REFLECT layer. 2018-11-24 08:00:17 +08:00
basil00 1c4075ed51 Add a recv "fast-path" to help reduce overheads.
WinDivert will now process some packets in-band
if the queue is empty and there is a read
request.  When activated, this saves 1xcopy,
1x(de)allocation, and 1xcontext-switch, and
reduces latency from ~60usec to ~20usec on my
test system.
2018-11-21 07:57:49 +08:00
basil00 29c6fda167 Improve & expand WinDivert test suite.
- Include tests for random*.
- Include latency timings in microseconds.
- More tests.
2018-11-19 07:21:54 +08:00
basil00 edbe5ea942 Optimize based on event expressions.
E.g., if "event == CONNECT" then do not install
a callout for LISTEN, etc.
2018-11-15 07:58:44 +08:00
basil00 67ad628a1f Add pseudo-random pkt matching to WinDivert (#156)
- Adds 3 new "pseudo-random" filter expressions:
  * random8 (8bit)
  * random16 (16bit)
  * random32 (32bit)
  Not really "random", but these values are based
  on a hash of the packet headers & timestamp.
  These are useful for traffic sampling, e.g.:
  "random8 < 100" matches ~39% of all packets.
- Add new WinDivertHelperHashPacket() helper
  function.  The algorithm is an xxHash variant.
2018-11-14 09:40:17 +08:00
basil00 312050accb Add a new WinDivertShutdown() function (#156).
This function allows the user application to
"shutdown" a handle in anticipation of a
call to WinDivertClose().  When a handle has
been shutdown, new packets will no longer be
queued.  However, existing queued packets can
still be read by WinDivertRecv().  When the
queue is emptied, WinDivertRecv() will fail
with ERROR_NO_DATA.

The WinDivertShutdown() function is analogous
to the shutdown() socket function.

This change also simplifies events.
2018-11-11 09:44:24 +08:00
basil00 0a74b5528c Update driver and inf version information. 2018-11-09 07:29:05 +08:00
basil00 084c78e4af Code cleanup & improve const correctness in API. 2018-11-09 07:21:56 +08:00
basil00 33a461eef6 Add packet/payload matching to WinDivert (#156).
Adds the follow terms to the filter language:
- packet[idx]: 8bit packet value at idx.
- packet16[idx]: 16bit packet value at idx.
- packet32[idx]: 32bit packet value at idx.
- PROTO.Payload[idx]: 8bit payload value at idx.
- PROTO.Payload16[idx]: 16bit payload value at
  idx.
- PROTO.Payload32[idx]: 32bit payload value at
  idx.
where PROTO is {tcp,udp}.

16 and 32bit values assume network byte ordering.

The index may be:
- An undecorated integer, in which case the
  packet or payload is treated as a 8/16/32bit
  value array, similar to C arrays.
- A 'b' decorated integer, (e.g, packet32[17b]),
  in which case the integer is interpreted as a
  byte offset.
- A negative (un)decorated integer, in which
  case indexing begins at the *end* of the
  packet or payload.  E.g., packet32[-1] is the
  last 32bits of the packet.

If the index is out-of-bounds, then the test
is deemed to be equivalent to "false".
2018-11-07 07:54:32 +08:00
basil00 1ccf486132 Calculate full checksums for reinjected packets. 2018-11-04 08:47:39 +08:00
basil00 4f7ff88664 Add batched recv/send to WinDivert (#156).
This change allows multiple packets to be
received/sent at once, reducing overheads.  To
exploit this feature, applications need to use
the WinDivertRecvEx()/WinDivertSendEx()
functions with the new addrLen parameter.  The
passthru example has been modified to use
batching.

The DEBUG flag has been retired since it
conflicts with batching, and was not very
useful anyway.
2018-11-03 08:40:34 +08:00
basil00 3966ec1287 Add a WINDIVERT_FLAG_PARTIAL flag.
This suppresses ERROR_INSUFFICIENT_BUFFER errors
if the passed buffer is too small.  Applications
can set this flag if they want to do partial
reads.
2018-10-30 08:56:43 +08:00
basil00 fc868feb3e Add type-safe get-fixed-val routines.
This prevents possible bsods when values are
missing.  Also add missing windivert_shared.c
file.
2018-10-30 05:36:44 +08:00
basil00 de4245f95e Event & REFLECT layer fixes.
- Make event bitwise-OR-able.
- Simplify event names.
- Fix REFLECT serialization.
  (setting AutomaticSerialization=TRUE does not
   work.)
- Preallocate REFLECT memory.
2018-10-29 05:40:03 +08:00
basil00 316765aa92 Fix impostor packet checksums. 2018-10-27 06:52:14 +08:00