protected override bool CheckRules(SpooferPacket state) { var nameLen = (int)state.Buffer[12]; state.Buffer = state.Buffer.Take(StaticPacketLength + nameLen).ToArray(); return(Networking.IsIPv4(state.Buffer)); }
public async Task HandleRequestPacket(SpooferPacket state) { var name = GetName(state); // We have to write everything as once as this is threaded await Controller.Log(Protocol, "Received {0} request for {1} from {2}{3}", Protocol, name, ((IPEndPoint)SocketType.IPEndPoint).Address.ToString(), (Settings.Inspect)? "" : " > Sending response"); }
public async Task HandlePacket(SpooferPacket state) { var ip = ((IPEndPoint)SocketType.IPEndPoint).Address; if (Controller.WorkerSettings.IP.Equals(ip) || !CheckRules(state)) { return; } await HandleRequestPacket(state); if (!Settings.Inspect) { await SpoofPacket(state); } }
private async Task BeginReceiveSockets() { foreach (var socketType in SocketTypes.Where(s => s.ProtocolType == ProtocolType.Udp)) { var state = new SpooferPacket(); socketType.Socket.BeginReceiveFrom( state.Buffer, 0, SpooferPacket.BUFFER_SIZE, SocketFlags.None, ref socketType.IPEndPoint, new AsyncCallback(async(ar) => await ReadCallback(ar, socketType)), state); } await Task.CompletedTask; }
public async Task SpoofPacket(SpooferPacket state) { var data = state.Buffer; var ip = Controller.WorkerSettings.IP.GetAddressBytes(); var packet = GetPacket(data, ip).Build(); try { SocketAsyncEventArgs e = new SocketAsyncEventArgs(); e.RemoteEndPoint = SocketType.IPEndPoint; e.SetBuffer(packet, 0, packet.Length); e.SocketFlags = SocketFlags.None; SocketType.Socket.SendToAsync(e); } catch (Exception) { await Controller.Log(Protocol, "{0} Could not send response", Environment.NewLine); } }
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); }
protected override string GetName(SpooferPacket state) { return(DecodeName(state.Buffer.Skip(13).Take(32).ToArray())); }
protected override bool CheckRules(SpooferPacket state) { var result = state.Buffer[2] == 0x01 && state.Buffer[3] == 0x10; return(result); }
protected override string GetName(SpooferPacket state) { var nameLen = (int)state.Buffer[12]; return(Encoding.Default.GetString(state.Buffer.Skip(13).Take(nameLen).ToArray())); }
protected abstract string GetName(SpooferPacket state);
protected abstract bool CheckRules(SpooferPacket state);