This project is read-only.

Can't see TCP request on server

Dec 13, 2012 at 3:47 PM

Here is my code, i can see request in wireshark but i can't see this request on my vps server, please help for working.

LAN IP address and server ip address

IpV4Address srcIP = new IpV4Address("192.168.111.254"); // my LAN ip address
IpV4Address dstIP = new IpV4Address("111.99.99.99"); // my vps server ip address

Full code

using System;
using System.Collections.Generic;
using System.Linq;
using PcapDotNet.Core;
using PcapDotNet.Packets;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.Transport;

namespace PcapTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Retrieve the device list from the local machine
            IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;

            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            // Print the list
            for (int i = 0; i != allDevices.Count; ++i)
            {
                LivePacketDevice device = allDevices[i];
                Console.Write(String.Format("{0}. {1}", (i + 1), device.Name));
                if (device.Description != null)
                    Console.WriteLine(String.Format(" ({0})", device.Description));
                else
                    Console.WriteLine(" (No description available)");
            }

            int deviceIndex = 0;
            do
            {
                Console.WriteLine(String.Format("Enter the interface number (1-{0}):", allDevices.Count));
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > allDevices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            // Take the selected adapter
            PacketDevice selectedDevice = allDevices[deviceIndex - 1];

            // Open the output device
            using (PacketCommunicator communicator = selectedDevice.Open(100, // name of the device
                                                                         PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                                                         1000)) // read timeout
            {
                EthernetLayer ethernet = new EthernetLayer();
                IpV4Layer ip4 = new IpV4Layer();
                TcpLayer tcp;

                MacAddress dstMac = new MacAddress("02:02:02:02:02:02");
                MacAddress srcMac = new MacAddress("01:01:01:01:01:01");

                //ethernet packet
                ethernet.Source = srcMac;
                ethernet.Destination = dstMac;
                ethernet.EtherType = EthernetType.IpV4;

                //ipv4 layer
                IpV4Address srcIP = new IpV4Address("192.168.111.254");
                IpV4Address dstIP = new IpV4Address("111.99.99.99");
                ip4.Source = srcIP;
                ip4.CurrentDestination = dstIP;
                ip4.Protocol = IpV4Protocol.Tcp;
                ip4.Ttl = 128;
                ip4.Fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.DoNotFragment, 0);


                //tcp layer
                tcp = new TcpLayer();
                tcp.SourcePort = 9999;
                tcp.DestinationPort = 80;
                tcp.Window = 100;
                tcp.SequenceNumber = 13154; //for teting

                tcp.ControlBits = TcpControlBits.Synchronize;

                //build and send packet

                PacketBuilder pb = new PacketBuilder(ethernet, ip4, tcp);

                // Build the packet
                Packet packet = pb.Build(DateTime.Now);

                // Send down the packet
                communicator.SendPacket(packet);
            }
        }
    }
}

Dec 28, 2012 at 4:20 PM

Hi vietnguyen09,

 

You probably need to create a TCP session in order for your server to accept this packet.

This is done by a 3-way handshake.

Sending a single TCP packet, which isn't a SYN packet would be ignored by your server.

If you need more information regarding this, I suggest you read a bit on TCP sessions or TCP connections.

 

I hope this helps,

 

Boaz.