0

This is the problem I'm trying to solve,

I want to write an application that will read outbound http request packets on the same machine's network card. This would then be able to extract the GET url from it.On basis of this information, I want to be able to stop the packet, or redirect it , or let it pass.

However I want my application to be running in promiscuous mode (like wireshark does), and yet be able to eat up (stop) the outbound packet.

I have searched around a bit on this..

libpcap / pcap.h allows to me read packets at the network card, however I haven't yet been able to figure out a way to stop these packets or inject new ones into the network.

Certain stuff like twisted or scapy in python, allows me set up a server that is listening on some local port, I can then configure my browser to connect to it, using proxy configurations. This app can then do the stuff.. but my main purpose of being promiscuous is defeated here..

Any help on how I could achieve this would be greatly appreciated ..

unwind
  • 391,730
  • 64
  • 469
  • 606
Rohan
  • 139
  • 1
  • 5
  • 4
    You have to state your O.S. for this question. What you ask is feasible under Linux (and possibly other unixes) by using iptables rules. – jsbueno Aug 22 '12 at 11:59

4 Answers4

3

I'd suggest that you approach this at the application layer and use a transparent proxy (e.g. squid) and iptables based interception of outbound port-80 traffic.

The reason I suggest this is that that it will avoid issues with the request being split between packets.

However, if you still want to go ahead with packet interception, you can do it in userspace using netfilters in netlink. I believe there are python wrappers for libnl around.

Essentially you create an iptables rule pointing to "QUEUE" for the traffic you want to intercept and write a program using a netlink library to process the queue, accepting, rejecting and/or modifying packets.

MattH
  • 37,273
  • 11
  • 82
  • 84
0

Using pcap you cannot stop the packets, if you are under windows you must go down to the driver level... but you can stop only packets that your machine send.

A solution is act as a pipe to the destination machine: You need two network interfaces (without address possibly), when you get a packet that you does not found interesting on the source network card you simply send it on the destination network card. If the packet is interesting you does not send it, so you act as a filter. I have done it for multimedia performance test (adding jitter, noise, etc.. to video streaming)

0

You are confusing several things here:

  • "Promiscuous" usually refers to a mode of a hardware ethernet network card where it delivers all packets in its collision domain up to the kernel network stack and have it sort out delivery (vs. just unicast to given MAC, subscribed multicast, and broadcast in normal operating mode of the card). This is on the receive path.

  • All the data outbound from your machine will go through (one of) the network cards on the machine, so "promiscuous" does not at all apply here.

  • You are working on filtering TCP-based protocol (HTTP), but talk in terms of packets. This is wrong. TCP connection is a stream that could be (as far as socket readers and writers are concerned) arbitrarily split into IP datagrams. That URL from HTTP request header could be split across multiple link-layer frames. You would have to stitch them back together and parse the stream anyway. Then you have no chance even at that if SSL is in use.

If you are interested in HTTP filtering then read HTTP RFCs, and read existing open-source code, e.g. squid, nginx, etc.

If you are digging through network stack for better understaning then read W. Richard Stevens books, look into existing code in open-source operating systems, check out BPF and netlink.

Hope this clears it a little.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
0

I have implemented this module in Windows by using two separate NICs and using a socket/pipe(whatever you like) between them in this thread

Community
  • 1
  • 1
Abhinav
  • 992
  • 2
  • 11
  • 26