I'm trying to redirect all tcp packets to my local proxy to modify html content(adblocker like). I wanted to use WinDivert but it doesn't seem to work.
Im starting the driver like this:
handle = WinDivertOpen("outbound", WINDIVERT_LAYER_NETWORK, 0, 0);
then when capturing and modifying packets:
if (ip_header != NULL && tcp_header != NULL) {
//redirect to proxy
if (ntohs(tcp_header->DstPort) == 80)
{
UINT32 dst_addr = ip_header->DstAddr;
ip_header->DstAddr = ip_header->SrcAddr;
ip_header->SrcAddr = dst_addr;
tcp_header->DstPort = htons(PROXY);
addr.Direction = DIVERT_DIRECTION_INBOUND;
}
else if (ntohs(tcphdr->SrcPort) == PROXY)
{
// proxy to browser
uint32_t dst_addr = iphdr->DstAddr;
iphdr->DstAddr = iphdr->SrcAddr;
iphdr->SrcAddr = dst_addr;
tcphdr->SrcPort = htons(80);
addr.Direction = DIVERT_DIRECTION_INBOUND;
}
WinDivertHelperCalcChecksums(packet, packet_len, 0);
if (!WinDivertSend(handle, packet, packet_len , &addr, &send_len))
{
qWarning() << "warning: failed to reinject packet" << GetLastError() << send_len;
}
But on the proxy side i cant see any incoming traffic and pages are not loading in the web browser.