Пример #1
0
        private async Task StartSocket(Models.SocketType socketType)
        {
            if (!Spoofers.ContainsKey(socketType))
            {
                return;
            }

            // Get all local ip addresses
            socketType.IPEndPoint = new IPEndPoint(IPAddress.Any, socketType.Port);

            var result = new Socket(
                AddressFamily.InterNetwork,
                System.Net.Sockets.SocketType.Dgram,
                ProtocolType.Udp);

            // Bind the socket to start receiving
            result.Bind(socketType.IPEndPoint);

            if (socketType.MulticastAddress != null)
            {
                var multicastOption = new MulticastOption(socketType.MulticastAddress, IPAddress.Any);

                result.SetSocketOption(
                    SocketOptionLevel.IP,
                    SocketOptionName.AddMembership,
                    multicastOption);
            }

            socketType.Socket = result;

            await Task.CompletedTask;
        }
Пример #2
0
        private void AddSpoofer(Models.SocketType socketType, ISpoofer spoofer, bool run)
        {
            if (!run)
            {
                return;
            }

            if (!Spoofers.ContainsKey(socketType))
            {
                SocketTypes.Add(socketType);
                Spoofers.Add(socketType, new List <ISpoofer>());
            }

            var socketRef = Spoofers[socketType];

            socketRef.Add(spoofer);
        }
Пример #3
0
        public async Task ReadCallback(IAsyncResult result, Models.SocketType socketType)
        {
            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            SpooferPacket state  = (SpooferPacket)result.AsyncState;
            Socket        socket = socketType.Socket;

            // Read data from the client socket.
            int length = socket.EndReceiveFrom(result, ref socketType.IPEndPoint);

            if (length > 0)
            {
                foreach (var handler in Spoofers[socketType])
                {
                    await Task.Run(() => handler.HandlePacket(state));
                }
            }
            else
            {
                await Controller.Log(Name, "Couldn't read packet({0}). Dumping Hex {1}{2}",
                                     length,
                                     Environment.NewLine,
                                     ElCazador.Worker.Utils.Hex.Dump(state.Buffer));
            }

            // Fetch new packets
            state = new SpooferPacket();

            socket.BeginReceiveFrom(
                state.Buffer,
                0,
                SpooferPacket.BUFFER_SIZE,
                SocketFlags.None,
                ref socketType.IPEndPoint,
                new AsyncCallback(async(ar) => await ReadCallback(ar, socketType)),
                state);
        }
Пример #4
0
 public NBNSSpoofer(IWorkerController controller, SpooferSettings settings, Models.SocketType socketType)
     : base(controller, settings, socketType)
 {
 }
Пример #5
0
 internal BaseSpoofer(IWorkerController controller, SpooferSettings settings, Models.SocketType socketType)
 {
     Settings   = settings;
     SocketType = socketType;
     Controller = controller;
 }