Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing of TCP packets sent by the SYSTEM process using windows-redirector.exe #204

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions mitmproxy-windows/redirector/src/main2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,29 @@
if address.process_id() == 4 {
// We get some weird operating system events here, which are not useful.
debug!("Skipping PID 4");

clear_connections(
connection_id,

Check failure on line 237 in mitmproxy-windows/redirector/src/main2.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.80, --exclude macos-certificate-truster)

cannot find value `connection_id` in this scope
&mut connections,
&inject_handle,
&mut ipc_tx,
address,
).await;

continue;
}

let Ok(proto) = TransportProtocol::try_from(address.protocol()) else {
warn!("Unknown transport protocol: {}", address.protocol());

clear_connections(
connection_id,

Check failure on line 251 in mitmproxy-windows/redirector/src/main2.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest, 1.80, --exclude macos-certificate-truster)

cannot find value `connection_id` in this scope
&mut connections,
&inject_handle,
&mut ipc_tx,
address,
).await;

continue;
};
let connection_id = ConnectionId {
Expand All @@ -246,6 +264,15 @@
};

if connection_id.src.ip().is_multicast() || connection_id.dst.ip().is_multicast() {

clear_connections(
connection_id,
&mut connections,
&inject_handle,
&mut ipc_tx,
address,
).await;

continue;
}

Expand Down Expand Up @@ -396,6 +423,47 @@
}
}

async fn clear_connections(
connection_id: ConnectionId,
connections: &mut LruCache<ConnectionId, ConnectionState>,
inject_handle: &WinDivert<NetworkLayer>,
ipc_tx: &mut UnboundedSender<ipc::PacketWithMeta>,
address: WinDivertAddress<SocketLayer>,
) {
match address.event() {
WinDivertEvent::SocketConnect | WinDivertEvent::SocketAccept => {
let make_entry = match connections.get(&connection_id) {
None => true,
Some(e) => matches!(e, ConnectionState::Unknown(_)),
};

debug!(
"{:<15?} make_entry={} pid={} {}",
address.event(),
make_entry,
address.process_id(),
connection_id
);

if !make_entry {
return;
}

let action = ConnectionAction::None;
let _ = insert_into_connections(
connection_id,
&action,
&address.event(),
connections,
inject_handle,
ipc_tx,
)
.await;
}
_ => {}
}
}

async fn handle_ipc(
mut ipc: NamedPipeClient,
mut ipc_rx: UnboundedReceiver<ipc::PacketWithMeta>,
Expand Down
Loading