Exemplo n.º 1
0
        public static void ui_script_delete_script(string proxy_id, string stream_id, string script_name)
        {
            List <cProxyProcess> proxy_processes = ui_proxy_process_get();

            foreach (var proxy_process in proxy_processes)
            {
                if (proxy_process.proxy_name == proxy_id)
                {
                    byte[] bytes_stream_name = Encoding.UTF8.GetBytes("Global");
                    byte[] bytes_script_name = Encoding.UTF8.GetBytes(script_name);

                    List <List <byte> > delete_parameters = new List <List <byte> >();

                    delete_parameters.Add(bytes_stream_name.ToList());
                    delete_parameters.Add(bytes_script_name.ToList());

                    cCommand delete_script_command = new cCommand
                    {
                        command    = "delete_script",
                        parameters = delete_parameters,
                    };

                    string string_delete_command = JsonConvert.SerializeObject(delete_script_command);

                    lock (_proxy_process_mutex)
                    {
                        proxy_process.proxy_management_stream.Client.Send(Encoding.UTF8.GetBytes(string_delete_command));
                    }

                    return;
                }
            }

            throw new Exception("Error: script can't be loaded because the proxy process was not found");
        }
Exemplo n.º 2
0
        public static void ui_toggle_global_intercept()
        {
            string toggle = cGlobalState.global_intercept_flag == true ? "true" : "false";

            byte[] bytes_toggle = Encoding.UTF8.GetBytes(toggle);
            List <List <byte> > command_parameters = new List <List <byte> >();

            command_parameters.Add(bytes_toggle.ToList());

            cCommand toggle_global_intercept_command = new cCommand
            {
                command    = "global_intercept",
                parameters = command_parameters,
            };

            string string_toggle_intercept_command = JsonConvert.SerializeObject(toggle_global_intercept_command);

            lock (_proxy_process_mutex)
            {
                foreach (cProxyProcess process in _proxy_process_list)
                {
                    process.proxy_management_stream.Client.Send(Encoding.UTF8.GetBytes(string_toggle_intercept_command));
                }
            }
        }
Exemplo n.º 3
0
        private static void background_update_scripts()
        {
            cCommand scripts_struct = new cCommand
            {
                command    = "active_scripts",
                parameters = new List <List <byte> >(),
            };

            string scripts_command = JsonConvert.SerializeObject(scripts_struct);

            List <cProxyProcess> proxy_list = ui_proxy_process_get();

            foreach (var proxy in proxy_list)
            {
                string string_received = send_and_receive_command(proxy, scripts_command);

                try
                {
                    Dictionary <string, Dictionary <string, cPythonScript> > scripts = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, cPythonScript> > >(string_received);

                    lock (_script_list_mutex)
                    {
                        _script_list[proxy.proxy_name] = scripts;
                    }
                }
                catch (Exception e)
                {
                    continue;
                }
            }
        }
Exemplo n.º 4
0
        private static void background_update_udp_streams()
        {
            cCommand active_streams_struct = new cCommand
            {
                command    = "active_udp_streams",
                parameters = new List <List <byte> >(),
            };

            string active_streams_command = JsonConvert.SerializeObject(active_streams_struct);

            lock (_udp_streams_mutex)
            {
                _udp_streams.Clear();
            }

            List <cProxyProcess> proxy_list = ui_proxy_process_get();

            foreach (var proxy in proxy_list)
            {
                string string_received = send_and_receive_command(proxy, active_streams_command);

                try
                {
                    List <cUDPStream> udp_streams = JsonConvert.DeserializeObject <List <cUDPStream> >(string_received);

                    for (int i = 0; i < udp_streams.Count; i++)
                    {
                        udp_streams[i].source_process_name = proxy.proxy_process_metadata;
                    }

                    lock (_udp_streams_mutex)
                    {
                        _udp_streams.AddRange(udp_streams);
                    }
                }
                catch (Exception e)
                {
                    continue;
                }
            }
        }
Exemplo n.º 5
0
        public static void ui_toggle_intercept(string stream_id, string true_or_false, string connection_string)
        {
            string proxy_management_parent = "";

            List <cTCPStream> tcp_streams = ui_tcp_streams_get();

            foreach (var tcp_stream in tcp_streams)
            {
                if (tcp_stream.stream_start == stream_id)
                {
                    proxy_management_parent = tcp_stream.source_process_name;
                    break;
                }
            }

            List <cUDPStream> udp_streams = ui_udp_streams_get();

            if (proxy_management_parent == "")
            {
                foreach (var udp_stream in udp_streams)
                {
                    if (udp_stream.stream_start == stream_id)
                    {
                        proxy_management_parent = udp_stream.source_process_name;
                        break;
                    }
                }
            }

            if (proxy_management_parent == "")
            {
                throw new Exception("Error: interception cannot be toggled because the connection is belongs too has closed");
            }

            List <cProxyProcess> proxy_processes = ui_proxy_process_get();

            foreach (var proxy_process in proxy_processes)
            {
                if (proxy_process.proxy_process_metadata == proxy_management_parent)
                {
                    byte[] bytes_stream_id         = Encoding.UTF8.GetBytes(stream_id);
                    byte[] true_bytes_id           = Encoding.UTF8.GetBytes(true_or_false);
                    byte[] bytes_connection_string = Encoding.UTF8.GetBytes(connection_string);

                    List <List <byte> > command_parameters = new List <List <byte> >();

                    command_parameters.Add(bytes_stream_id.ToList());
                    command_parameters.Add(true_bytes_id.ToList());
                    command_parameters.Add(bytes_connection_string.ToList());

                    cCommand intercept_stream_command = new cCommand
                    {
                        command    = "toggle_intercept",
                        parameters = command_parameters,
                    };

                    string json_command = JsonConvert.SerializeObject(intercept_stream_command);

                    lock (_proxy_process_mutex)
                    {
                        proxy_process.proxy_management_stream.Client.Send(Encoding.UTF8.GetBytes(json_command));
                    }

                    return;
                }
            }

            throw new Exception("Error: interception cannot be toggled because the connection is belongs too has closed");
        }