Situation: I am trying to intercept TCP (not HTTP) traffic on a Windows machine using Python. I am posting this question as most answers I was able to find teaches how to sniff traffic.
Normal operation:-
Machine A ===> Machine A's TCP/IP stack ===> Machine B
What I am trying to do:-
Machine A ===> Intercept + modify packet ===> Machine A's TCP/IP stack ===> Machine B
Problem: Most common answers point to using scapy
module in Python to modify the traffic. However scapy
only sniffs the traffic from Machine A, and does not stop the original copy from being dispatched. As a result Machine B will receive two copies of traffic
What scapy does:-
Machine A ===> Machine A's TCP/IP stack ===> Machine B
|| /\
\/ || (2nd copy)
Scapy sniffing ===> Scapy modifications ===> Machine A's TCP/IP stack
Question: Is there any way I am able to intercept the traffic instead of sniffing it? The end goal is to have Machine B only receive one copy of the packet, which will the modified one.
Additional information 1: All modules used will need to be able to be contained within one EXE file (a la PyInstaller) for Windows.
Additional information 2: I cannot place a third machine between A and B, so I cannot perform ARP poisoning (which was a considered option).
Additional information 3: if I were to use a proxy, it must be able to intercept traffic from ports other than standard HTTP (80, 443, 8080).