1315

FiddlerCore: how to handle TCP traffic?

Question:

I want to use fiddlercore as a reverse proxy - to parse HTTP requests and redirect them to another ports depending on HTTP headers. But I need also handle TCP requests and redirect them to some another port. Is it possible using FiddlerCore? Somehow identify that it is not an HTTP request, just TCP.

<blockquote>

I've found event named BeforeReturningError but it's not called. Only event BeforeSocketAccept is triggered but it's not enough. I haven't found any other events that might be called when FiddlerCore failed to parse HTTP headers.

</blockquote>

Answer1:

Fiddler and FiddlerCore only handle HTTP/HTTPS traffic. They are not designed to handle raw TCP traffic; you could use something like netcat for that.

Answer2:

To can TCP packets you can use Pcap library. As such fiddlercore don't work with TCP or UDP packets.

private void PacketHandler(Packet packet) { this.count = ""; this.time = ""; this.source = ""; this.destination = ""; this.protocol = ""; this.length = ""; this.tcpack = ""; this.tcpsec = ""; this.tcpnsec = ""; this.tcpsrc = ""; this.tcpdes = ""; this.udpscr = ""; this.udpdes = ""; this.httpheader = ""; this.httpver = ""; this.httplen = ""; this.reqres = ""; this.httpbody = ""; IpV4Datagram ip = packet.Ethernet.IpV4; TcpDatagram tcp = ip.Tcp; UdpDatagram udp = ip.Udp; HttpDatagram httpPacket=null; if (ip.Protocol.ToString().Equals("Tcp")) { httpPacket = tcp.Http;//Initialize http variable only if the packet was tcp if ((httpPacket.Header != null) && (!_tcp.Checked)) { protocol = "Http"; httpheader = httpPacket.Header.ToString(); count = packet.Count.ToString(); time = packet.Timestamp.ToString(); this.source = ip.Source.ToString(); this.destination = ip.Destination.ToString(); length = ip.Length.ToString(); httpver = httpPacket.Version.ToString(); httplen = httpPacket.Length.ToString(); httpbody = httpPacket.Body.ToString(); if (httpPacket.IsRequest) { reqres = "Request"; } else { reqres = "Response"; } } else { count = packet.Count.ToString(); time = packet.Timestamp.ToString(); this.source = ip.Source.ToString(); this.destination = ip.Destination.ToString(); length = ip.Length.ToString(); protocol = ip.Protocol.ToString(); tcpsrc = tcp.SourcePort.ToString(); tcpdes = tcp.DestinationPort.ToString(); tcpack = tcp.AcknowledgmentNumber.ToString(); tcpsec = tcp.SequenceNumber.ToString(); tcpnsec = tcp.NextSequenceNumber.ToString(); } } else { if ((ip.Protocol.ToString().Equals("Udp"))) { count = packet.Count.ToString(); time = packet.Timestamp.ToString(); this.source = ip.Source.ToString(); this.destination = ip.Destination.ToString(); length = ip.Length.ToString(); protocol = ip.Protocol.ToString(); udpscr = udp.SourcePort.ToString(); udpdes = udp.DestinationPort.ToString(); } else { count = packet.Count.ToString(); time = packet.Timestamp.ToString(); this.source = ip.Source.ToString(); this.destination = ip.Destination.ToString(); length = ip.Length.ToString(); protocol = ip.Protocol.ToString(); } } if (ip.Protocol.ToString().Equals("Tcp")&&(save.Checked)) { int _source = tcp.SourcePort; int _destination = tcp.DestinationPort; if (tcp.PayloadLength != 0) //not syn or ack { payload = new byte[tcp.PayloadLength]; tcp.Payload.ToMemoryStream().Read(payload, 0, tcp.PayloadLength);// read payload from 0 to length if (_destination == 80)// request from server { Packet1 packet1 = new Packet1(); int i = Array.IndexOf(payload, (byte)32, 6); byte[] t = new byte[i - 5]; Array.Copy(payload, 5, t, 0, i - 5); packet1.Name = System.Text.ASCIIEncoding.ASCII.GetString(t); if (!packets.ContainsKey(_source)) packets.Add(_source, packet1); } else if (_source == 80) if (packets.ContainsKey(_destination)) { Packet1 packet1 = packets[_destination]; if (packet1.Data == null) { if ((httpPacket.Header != null) && (httpPacket.Header.ContentLength != null)) { packet1.Data = new byte[(uint)httpPacket.Header.ContentLength.ContentLength]; Array.Copy(httpPacket.Body.ToMemoryStream().ToArray(), packet1.Data, httpPacket.Body.Length); packet1.Order = (uint)(tcp.SequenceNumber + payload.Length - httpPacket.Body.Length); packet1.Data_Length = httpPacket.Body.Length; for (int i = 0; i < packet1.TempPackets.Count; i++) { Temp tempPacket = packet1.TempPackets[i]; Array.Copy(tempPacket.data, 0, packet1.Data, tempPacket.tempSeqNo - packet1.Order, tempPacket.data.Length); packet1.Data_Length += tempPacket.data.Length; } } else { Temp tempPacket = new Temp(); tempPacket.tempSeqNo = (uint)tcp.SequenceNumber; tempPacket.data = new byte[payload.Length]; Array.Copy(payload, tempPacket.data, payload.Length); packet1.TempPackets.Add(tempPacket); } } else if (packet1.Data_Length != packet1.Data.Length) { Array.Copy(payload, 0, packet1.Data, tcp.SequenceNumber - packet1.Order, payload.Length); packet1.Data_Length += payload.Length; } if (packet1.Data != null) if (packet1.Data_Length == packet1.Data.Length) { using (BinaryWriter writer = new BinaryWriter(File.Open(@"D:\captured\" + Directory.CreateDirectory(Path.GetFileName(packet1.Name)), FileMode.Create))) { writer.Write(packet1.Data); } packets.Remove(_destination); } } } } }

<strong>This code will help you</strong>

Recommend

  • TLS v1.1 / TLS v1.2 support in RCurl
  • WCF handling CORS & Options VERB
  • JavaFX: File upload to REST service / servlet fails because of missing boundary
  • Porting struct.unpack from python 2.7 to 3
  • Plesk XML API Error 2204: Login name is empty
  • C++ force stack unwinding inside function
  • How do I append custom data in the body of a xmpp message in ejabberd
  • JAVA: Detect self when broadcasting UDP Packets
  • How to display a dictionary which contains a list in a listBox C#
  • Sending files with asmack (or any alternatives)
  • Detecting codec used in RTP stream (for dynamic PTs)
  • Python Twisted TCP socket how to set TCP_NODELAY (Disable Nagle's algorithm)?
  • WMI The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
  • How to deserialize and serialize AMF Packets in Python?
  • Javax Websocket closing due to Illegal UTF-8 Sequence
  • Enable/Disable Data Enable mechanisam in Genymotion Emulator
  • Is UDP a reliable protocol for IPC?
  • cURL sending XML incorrectly when using tag attributes
  • what is the weird usage in C language [duplicate]
  • Pcap Incomplete Type
  • How to use attribute value as a discriminator for XML polymorphic type selection?
  • OpenSSL SSL_write from multiple buffers / SSL_writev
  • How to use libavformat to concat 2 video files with same codec (re-muxing)?
  • C# Listen TCP Port [closed]
  • Keeping a socket opened in a thread, and sending commands from Main
  • SSL: can the secret key be sniffed before the actual encryption begins?
  • RTP AAC Packet Depacketizer
  • Does PHP SoapClient support HTTPS connections
  • C# - Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  • Drop an open TCP connection without sending RST
  • C#/C++ Capture local machine ip packet and drop it
  • Any specific problems running (linux) BCP on “too many” threads?
  • Bluetooth LE maximum transmission size
  • Adding Boost recipe to Yocto SDK
  • Creating raw packets to spoof UDP Packets
  • Where can I find a sample for Pcap for Diameter protocol (WireShark)? [closed]
  • How to printk the first 34 bytes (Ethernet and IP headers) of each packet (EtherType: 0x0806, Protoc
  • How to encode h.264 live stream to RTP packet with Java
  • RTCP receiver report sending interval
  • Accessing structure members with a pointer