0
 private Packet BuildTcpPacket(string SourceIP, string DestIP, int sourceport, int destport,
        string payload, bool syn, bool ack, bool fin, bool rst, bool urg, bool psh, bool cwr, bool enc, bool ns, bool none)
    {
        EthernetLayer ethernetLayer = new EthernetLayer
        {
            Source = new MacAddress(tbMacVs.Text),  //doublechecked its OK
            Destination = new MacAddress(tbMacVy.Text), //OK
            EtherType = EthernetType.None, // Will be filled automatically.
        };

        IpV4Layer ipV4Layer = new IpV4Layer
        {
            Source = new IpV4Address(SourceIP), //OK
            CurrentDestination = new IpV4Address(DestIP),  //OK
            Fragmentation = IpV4Fragmentation.None,
            HeaderChecksum = null, // Will be filled automatically.
            Identification = (ushort)Convert.ToInt16("1000"), //1000
            Options = IpV4Options.None,
            Protocol = null, // Will be filled automatically.
            Ttl = (byte)Convert.ToInt16("64"), //64
            TypeOfService = 0,
        };

        TcpLayer tcpLayer = new TcpLayer();
        tcpLayer.SourcePort = (ushort)sourceport; //OK
        tcpLayer.DestinationPort = (ushort)destport; //OK
        tcpLayer.Checksum = null;// Will be filled automatically.
        tcpLayer.SequenceNumber = Convert.ToUInt16("124");
        tcpLayer.AcknowledgmentNumber = (ushort)Convert.ToUInt16("0");
        if (syn)
            tcpLayer.ControlBits = TcpControlBits.Synchronize;
        if (ack)
            tcpLayer.ControlBits = TcpControlBits.Acknowledgment;
        //if (fin)
        //    tcpLayer.ControlBits = TcpControlBits.Fin;
        //if (rst)
        //    tcpLayer.ControlBits = TcpControlBits.Reset;
        //if (urg)
        //    tcpLayer.ControlBits = TcpControlBits.Urgent;
        //if (psh)
        //    tcpLayer.ControlBits = TcpControlBits.Push;
        //if (cwr)
        //    tcpLayer.ControlBits = TcpControlBits.CongestionWindowReduced;
        //if (enc)
        //    tcpLayer.ControlBits = TcpControlBits.ExplicitCongestionNotificationEcho;
        //if (ns)
        //    tcpLayer.ControlBits = TcpControlBits.NonceSum; // not a flag, rather a tcp header bit set
        //if (none)
        //    tcpLayer.ControlBits = TcpControlBits.None;


        tcpLayer.Window = (ushort)Convert.ToUInt16("0");
        tcpLayer.UrgentPointer = 0;
        tcpLayer.Options = TcpOptions.None;

        PayloadLayer payloadLayer = new PayloadLayer
        {
            Data = new Datagram(Encoding.ASCII.GetBytes(payload)),
        };

        PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, payloadLayer);

        return builder.Build(DateTime.Now);
    }

Hello Im using Pcap.Net library to create my own TCP packet like Syn/Fin/Ack with no additional information and I need to sand this packet without establishing of TCP connection. I just need to reach to my server port with this packet.

But with this construction of TCP packet it never reach to my server. But Im sure packet is send (tested by wireshark). So please help me with construction of these packets, Im not sure all parameters are right used.

  • Please show the wireshark capture showing that the packet is sent. – Scott Chamberlain Dec 03 '14 at 00:26
  • http://i.imgur.com/FR4bpFQ.png here is screen i sending 3 packets to 3 different ports. I can show you all wireshark file if you want. – Petr Boháč Dec 03 '14 at 00:48
  • So please any advice? And guys that parameter Destination(MAC ADDRESS) in ethernetLayer its my routers MAC which way to internet right? – Petr Boháč Dec 03 '14 at 17:32
  • How do you know the packets don't reach the server? Did you try looking at regular packets being sent to the server and imitate them? – brickner Dec 20 '14 at 13:53
  • On server side run deamon which responds to TCP packets. Right now Syn, Ack works fine for me, but other still didnt work. I tested it on my lan and all was OK (I sent packet from my PC to wifi router in my LAN). I talk to some network experts and they sad, routers in way to server can stop this packet because i dont have established connection. – Petr Boháč Dec 20 '14 at 22:38

0 Answers0