4
votes

I have to send packets with a wifi adapter to another computer without connecting to any network, targeting Windows 7 and above. First of all, ad-hoc (as I understand) doesn't fit my needs because it requires connection.

I had two ideas:

  1. create something similar to a broadcast packet which identify networks. This can be used on wireless card

  2. send fake but valid packet and which doesn't need a specific IP/MAC address (they can be broadcasts for example).

What I use: C# with a Win7 PC and a Win7 laptop for testing the program. SharpPcap to send packets. Wireshark to check if they are arrived.

I tried the second method:

static void Main(string[] args)
{
    WinPcapDeviceList devs = WinPcapDeviceList.Instance;
    foreach (WinPcapDevice wdev in devs)
    {
        System.Console.Write("Device: ");
        System.Console.WriteLine(wdev.Description);
        foreach (var addr in wdev.Addresses)
            System.Console.WriteLine(addr.Addr);
        System.Console.WriteLine("--------------");
    }

    System.Console.Write("Select device: #");
    int selected = int.Parse(System.Console.ReadLine());
    var dev = devs[selected]; //yes, no checking for oob...
    dev.Open();

    while (true)
    {
        byte[] physBroad = new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
        EthernetPacket etherPacket = new EthernetPacket(
            dev.MacAddress,
            new PhysicalAddress(physBroad),
            EthernetPacketType.IpV4);

        IPv4Packet ip4Packet = new IPv4Packet(
            new IPAddress(0),
            IPAddress.Broadcast);

        ip4Packet.Protocol = IPProtocolType.UDP;

        etherPacket.PayloadPacket = ip4Packet;

        UdpPacket udpPacket = new UdpPacket(
            80, //tried with different port setups
            80);

        udpPacket.PayloadData = Encoding.UTF8.GetBytes("test packet");
        ip4Packet.PayloadPacket = udpPacket;

        dev.SendPacket(etherPacket);
    }
}

Without connecting to the same network they are discarded (not arrive at Wireshark). I can only see the packets if they are on the same network.

For the first one, I know about IEEE 802.11, but I can't find anything about how to craft and send those packets. Is it possible to do this without dedicated hardware like AirPcap? I'd like to avoid writing a driver too if not necessary.

ps: I have an Edimax Wireless LAN card in my PC, and a Mediatek MT763E 802.11bgn Wifi-Adapter in my laptop. I installed the same version of Wireshark on both of them, but I can't turn the monitor mode on, and cannot set the link-layer type to IEEE-802.11, only to Ethernet and DOCSIS types.

1
Broadcast packets only work with someone (a router) to actually perform the broadcast. You can't just throw packets into the air and have something catch them. Why can't you have a network. This is impossible without one.BradleyDotNET
Thats what I'm afraid of. It's for a contest. It is said that it should work on win7/8 without connection to a network using laptops with wifi adapters. It should work like a bluetooth system but with wireless cards. Sending ieee802.11 frames would be the best, but not on Windows.David Szalai
Its a contest, so rules are rules, but it seems like you are basically writing the ad-hoc networking protocol. If I was doing this in industry, I would take advantage of the already existing one :).BradleyDotNET
I'm just reading about WinPcap on Windows. Its harder than I thought, it seems I can't send/sniff wifi packets because they get converted to/from Ethernet frames, so without a full new driver (which I'm not going to finish in 2 weeks) it's impossible.David Szalai
Probably. Sounds like a really hard programming contest to me. The best of luck to you though. WinPcap is definitely not easy to work with. I used it to send Ethernet packets, but you can't even do that without an already existing network, and it wasn't exactly simple.BradleyDotNET

1 Answers

3
votes

Change your WiFi SSID to the message :-)

enter image description here

Or this:

enter image description here