Beispiel #1
0
        public frmProfileManager(string torExecutableFilePath)
        {
            InitializeComponent();

            //init tor controller
            _torController = new TorController(torExecutableFilePath);
            _torController.Socks5EndPoint = new IPEndPoint(IPAddress.Loopback, 9950);
            _torController.ControlPort    = 9951;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new intance of the <see cref="PrivoxyProxy"/> service
        /// </summary>
        public TrouProxy(TorProxySettings torSettings, TorControllerSettings controllerSettings, PrivoxyProxySettings privoxySettings)
        {
            // -- Instance

            Tor        = new TorProxy(torSettings);
            Controller = new TorController(controllerSettings);

            Privoxy = new PrivoxyProxy(privoxySettings);
        }
Beispiel #3
0
        public frmProfileManager(string torExecutableFilePath)
        {
            InitializeComponent();

            //init profiles
            RefreshProfileList();

            //init mesh update
            _meshUpdate = new MeshUpdate(_isPortableApp ? Program.UPDATE_URI_WINDOWS_PORTABLE_APP : Program.UPDATE_URI_WINDOWS_SETUP_APP, Program.UPDATE_CHECK_INTERVAL);
            _meshUpdate.UpdateAvailable   += meshUpdate_UpdateAvailable;
            _meshUpdate.NoUpdateAvailable += meshUpdate_NoUpdateAvailable;
            _meshUpdate.UpdateCheckFailed += meshUpdate_UpdateCheckFailed;

            //init tor controller
            _torController = new TorController(torExecutableFilePath);
            _torController.Socks5EndPoint = new IPEndPoint(IPAddress.Loopback, 9950);
            _torController.ControlPort    = 9951;
        }
Beispiel #4
0
        public MeshNode(Stream s, string password, string profileFolder, TorController torController)
        {
            _password      = password;
            _profileFolder = profileFolder;

            switch (s.ReadByte()) //version
            {
            case 1:
                //read headers and init decryptor
                Aes decryptionAlgo = Aes.Create();
                decryptionAlgo.Key     = MeshNetwork.GetKdfValue32(Encoding.UTF8.GetBytes(password), s.ReadBytes(32), 1, 1 * 1024 * 1024); //salt
                decryptionAlgo.IV      = s.ReadBytes(16);                                                                                  //IV
                decryptionAlgo.Padding = PaddingMode.ISO10126;
                decryptionAlgo.Mode    = CipherMode.CBC;

                byte[] hmac = s.ReadBytes(32);     //hmac
                long   cipherTextStartPosition = s.Position;

                //authenticate data in Encrypt-then-MAC (EtM) mode
                using (HMAC aeHmac = new HMACSHA256(decryptionAlgo.Key))
                {
                    byte[] computedHmac = aeHmac.ComputeHash(s);

                    if (!BinaryNumber.Equals(hmac, computedHmac))
                    {
                        throw new CryptographicException("Invalid password or data tampered.");
                    }
                }

                //decrypt data and init node
                s.Position = cipherTextStartPosition;
                CryptoStream cS = new CryptoStream(s, decryptionAlgo.CreateDecryptor(), CryptoStreamMode.Read);

                InitMeshNode(new BinaryReader(cS), torController);
                break;

            case -1:
                throw new EndOfStreamException();

            default:
                throw new InvalidDataException("MeshNode format version not supported.");
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            TorController tc;
            uint port;
            string hostname, password, tmp;
            List<GetInfoReply> infos;
            List<GetConfReply> configs;

            Logger.ConsoleLogLevel = LogTypes.NONE;
            Logger.FileLogLevel = LogTypes.INFO;

            hostname = "127.0.0.1"; // NOTE: ipv6 is NOT supported.
            port = 9051;
            password = "******";

            try
            {

                /* testing
                Console.Write("Write the server host: ");
                hostname = Console.ReadLine();
                Console.Write("Insert your freaking control port: ");
                tmp = Console.ReadLine();
                if(!uint.TryParse(tmp, out port))
                {
                    Console.WriteLine("BAD BOY.");
                    return;
                }
                Console.Write("Enter your password: "******"Authenticated successfully!");

                    tc.SendCommand(new SetEvents(false, TorEvents.ORCONN));

                    #region Infos
                    if (tc.GetInfo(out infos,
                                   Informations.process_pid,
                                   Informations.version,
                                   Informations.traffic_read,
                                   Informations.traffic_written,
                                   Informations.circuit_status
                                   )
                        .Code == ReplyCodes.OK)
                    {
                        foreach (GetInfoReply info in infos)
                        {
                            Console.WriteLine("[INFORMATION] {0} -> {1}", info.Name, info.Value);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Something went wrong retrieving the informations..."); // should never happen.
                    }
                    #endregion

                    #region Configs
                    tc.GetConf(out configs,
                               Configs.NewCircuitPeriod,
                               Configs.ORPort,
                               Configs.NumEntryGuards,
                               Configs.CookieAuthentication,
                               Configs.ControlSocket);
                    foreach(GetConfReply conf in configs)
                    {
                        Console.WriteLine("[CONFIG] {0} -> {1}", conf.Name, conf.Value==null?"null":conf.Value);
                    }
                    #endregion

                    Console.WriteLine("[CURRENT CONFIG]:\r\n{0}\r\n\r\n",tc.GetCurrentConfig());
                }
                else
                {
                    Console.WriteLine("Wrong password.");
                }

                //Console.WriteLine("Press a key to close the connection.");
                Console.ReadKey();

                tc.Close();
            }
            catch (SocketException)
            {
                Console.WriteLine("Can't connect to the server at \"{0}:{1}\".", hostname, port);
            }

            Console.WriteLine("Press a key to close the program.");
            Console.ReadKey();
        }
Beispiel #6
0
        private void InitMeshNode(BinaryReader bR, TorController torController)
        {
            switch (bR.ReadByte()) //version
            {
            case 1:
                _type             = (MeshNodeType)bR.ReadByte();
                _privateKey       = bR.ReadBuffer();
                _supportedCiphers = (SecureChannelCipherSuite)bR.ReadByte();

                //
                _userId = new BinaryNumber(bR.BaseStream);

                //
                _localServicePort = bR.ReadUInt16();
                _downloadFolder   = bR.ReadShortString();

                //
                _profileDateModified  = bR.ReadDate();
                _profileDisplayName   = bR.ReadShortString();
                _profileStatus        = (MeshProfileStatus)bR.ReadByte();
                _profileStatusMessage = bR.ReadShortString();

                //
                _profileImageDateModified = bR.ReadDate();
                _profileDisplayImage      = bR.ReadBuffer();

                //
                _ipv4BootstrapDhtNodes = new EndPoint[bR.ReadInt32()];
                for (int i = 0; i < _ipv4BootstrapDhtNodes.Length; i++)
                {
                    _ipv4BootstrapDhtNodes[i] = EndPointExtension.Parse(bR);
                }

                _ipv6BootstrapDhtNodes = new EndPoint[bR.ReadInt32()];
                for (int i = 0; i < _ipv6BootstrapDhtNodes.Length; i++)
                {
                    _ipv6BootstrapDhtNodes[i] = EndPointExtension.Parse(bR);
                }

                _torBootstrapDhtNodes = new EndPoint[bR.ReadInt32()];
                for (int i = 0; i < _torBootstrapDhtNodes.Length; i++)
                {
                    _torBootstrapDhtNodes[i] = EndPointExtension.Parse(bR);
                }

                //
                _enableUPnP = bR.ReadBoolean();
                _allowInboundInvitations          = bR.ReadBoolean();
                _allowOnlyLocalInboundInvitations = bR.ReadBoolean();

                //
                if (bR.ReadBoolean())
                {
                    _proxy = new NetProxy((NetProxyType)bR.ReadByte(), bR.ReadShortString(), bR.ReadUInt16(), (bR.ReadBoolean() ? new NetworkCredential(bR.ReadShortString(), bR.ReadShortString()) : null));
                }

                //
                _appData = bR.ReadBuffer();

                //start connection manager
                _connectionManager = new ConnectionManager(this, torController);

                //
                int networkCount = bR.ReadInt32();

                for (int i = 0; i < networkCount; i++)
                {
                    MeshNetwork network = new MeshNetwork(_connectionManager, bR);
                    _networks.Add(network.NetworkId, network);
                }

                InitAnnounceTimer();
                break;

            default:
                throw new InvalidDataException("MeshNode format version not supported.");
            }
        }
Beispiel #7
0
        public MeshNode(MeshNodeType type, byte[] privateKey, SecureChannelCipherSuite supportedCiphers, ushort localServicePort, string profileDisplayName, string profileFolder, string downloadFolder, TorController torController)
        {
            _type                = type;
            _privateKey          = privateKey;
            _supportedCiphers    = supportedCiphers;
            _localServicePort    = localServicePort;
            _profileDateModified = DateTime.UtcNow;
            _profileDisplayName  = profileDisplayName;

            if (_type == MeshNodeType.Anonymous)
            {
                _enableUPnP = false;
                _allowInboundInvitations          = true;
                _allowOnlyLocalInboundInvitations = true;
            }
            else
            {
                _enableUPnP = true;
                _allowInboundInvitations          = true;
                _allowOnlyLocalInboundInvitations = false;
            }

            _profileFolder  = profileFolder;
            _downloadFolder = downloadFolder;

            GenerateNewUserId();

            //start connection manager
            _connectionManager = new ConnectionManager(this, torController);

            InitAnnounceTimer();
        }
Beispiel #8
0
        static async Task Main(string[] args)
        {
            var launcher = new TorLauncher();

            launcher.OnProgress += (s, e) =>
            {
                Console.SetCursorPosition(0, Console.CursorTop);
                var progress = Enumerable.Range(0, e).Where(x => x % 10 == 0).Select(x => $"{x}%");
                Console.Write($"Bootstrapping: {string.Join(" ", progress)}");
            };
            using var torProcess = await launcher.LaunchAsync();

            var controlFilePath = launcher.Arguments["--ControlPortWriteToFile"];

            using (var control = await TorController.UseControlPortFileAsync(controlFilePath))
            {
                await control.AuthenticateAsync("");

                Console.WriteLine("General info");
                Console.WriteLine("------------------------------------------------------------------------------------------------------");
                var protocolInfo = await control.GetProtocolInfoAsync();

                var version = await control.GetVersionAsync();

                var user = await control.GetUserAsync();

                var pid = await control.GetPidAsync();

                Console.WriteLine($"Tor version   : {version}");
                Console.WriteLine($"Tor user      : {user}");
                Console.WriteLine($"Tor Process Id: {pid}");
                Console.WriteLine();
                Console.WriteLine($"Protocol");
                Console.WriteLine($"  - Protocol Version: {protocolInfo.ProtocolVersion}");
                Console.WriteLine($"  - Tor Version     : {protocolInfo.TorVersion}");
                Console.WriteLine($"  - Auth methods    : {string.Join(", ", protocolInfo.AuthMethods)}");
                Console.WriteLine($"  - Cookie file path: {protocolInfo.CookieFile}");
                Console.WriteLine();
                Console.WriteLine("Resolve domains");

                var ip = await control.ResolveAsync("google.com");

                var domain = await control.ResolveAsync(ip, isReverse : true);

                Console.WriteLine($"  - google.com   : {ip}");
                Console.WriteLine($"  - {ip} : {domain}");
                Console.WriteLine();
            }

            using (var control = await TorController.UseControlPortFileAsync(controlFilePath))
            {
                await control.AuthenticateAsync("");

                Console.WriteLine("Circuits");
                Console.WriteLine("------------------------------------------------------------------------------------------------------");
                var circuits = await control.GetCircuitsAsync();

                foreach (var circ in circuits)
                {
                    var pathLength = Math.Min(100, circ.Path.Length);
                    Console.WriteLine($"{circ.Id} {circ.Status} {circ.TimeCreated} [{string.Join(", ", circ.BuildFlags)}] {circ.Path.Substring(0, pathLength)}...");
                }

                /*
                 * //Console.WriteLine(" Dropping Guard...");
                 * //await control.DropGuardsAsync();
                 * Console.WriteLine(" Renewing circuits...");
                 * await control.SignalAsync(Signal.NEWNYM);
                 * await Task.Delay(30_000);
                 * circuits = await control.GetCircuitsAsync();
                 * foreach(var circ in circuits)
                 * {
                 *      var pathLength = Math.Min(110, circ.Path.Length);
                 *      Console.WriteLine($"{circ.Id} {circ.Status} {circ.TimeCreated} [{string.Join(", ", circ.BuildFlags)}] {circ.Path.Substring(0, pathLength)}...");
                 * }
                 */
                Console.WriteLine();
            }
#if FALSE
            using (var control = await TorController.UseControlPortFileAsync(controlFilePath))
            {
                await control.AuthenticateAsync("pwd");

                Console.WriteLine("Bandwidth event (Read/Write)");
                Console.WriteLine("------------------------------------------------------------------------------------------------------");

                var handler = new EventHandler <AsyncReply>((sender, e) => {
                    var ev = (BandwidthEvent)e;
                    Console.WriteLine($"[EVENT] Bandwidth -> Read: {ev.BytesRead} bytes\t\t Written: {ev.BytesWritten} bytes");
                });
                await control.AddEventHandlerAsync(AsyncEvent.BW, handler);

                await control.SignalAsync(Signal.DORMANT);

                await control.SignalAsync(Signal.ACTIVE);

                await Task.Delay(4_000);

                await control.RemoveEventHandlerAsync(AsyncEvent.BW, handler);

                Console.WriteLine();
            }


            using (var control = await TorController.UseControlPortFileAsync(controlFilePath))
            {
                await control.AuthenticateAsync("pwd");

                Console.WriteLine("Ephemeral Hidden Services");
                Console.WriteLine("------------------------------------------------------------------------------------------------------");
                Console.Write("Creating....");
                void DisplayUpload(object sender, AsyncReply e)
                {
                    var ev = (HiddenServiceDescriptorEvent)e;

                    if (ev.Action == HsDescActions.UPLOADED || ev.Action == HsDescActions.UPLOAD || ev.Action == HsDescActions.CREATED)
                    {
                        Console.WriteLine($"{ev.Action} {ev.Address} -> {ev.HsDir}");
                    }
                }

                await control.AddEventHandlerAsync(AsyncEvent.HS_DESC, DisplayUpload);

                var hs1 = control.CreateEphemeralHiddenServiceAsync("8081", flags: OnionFlags.DiscardPK, waitForPublication: true);
                var hs2 = control.CreateEphemeralHiddenServiceAsync("8082", waitForPublication: true);
                var hs  = await Task.WhenAll(hs1, hs2);

                await control.RemoveEventHandlerAsync(AsyncEvent.HS_DESC, DisplayUpload);

                Console.WriteLine("Done");
                Console.WriteLine($"CREATED : {hs[0].ServiceId}");
                Console.WriteLine($"CREATED : {hs[1].ServiceId}");
                Console.WriteLine();

                Console.WriteLine("Listing...");
                var hsList = await control.ListEphemeralHiddenServicesAsync();

                for (var i = 0; i < hsList.Length; i++)
                {
                    Console.WriteLine($"{i}: {hsList[i]}");
                }
                Console.WriteLine();

                Console.WriteLine("Removing...");
                for (var i = 0; i < hsList.Length; i++)
                {
                    var hsItem = hsList[i];
                    await control.RemoveHiddenServiceAsync(hsItem);

                    Console.WriteLine($"{hsItem} REMOVED");
                }

                Console.WriteLine();
            }
#endif

            using (var control = await TorController.UseControlPortFileAsync(controlFilePath))
            {
                await control.AuthenticateAsync("");

                var handler = new EventHandler <AsyncReply>((sender, e) =>
                                                            Console.WriteLine($"[EVENT] {e.Event} -> {e.Line.Substring(0, Math.Min(110, e.Line.Length))} {e.RawString}"));

                var handler2 = new EventHandler <AsyncReply>((sender, e) => {
                    Console.WriteLine(e.Line);
                });

                Console.WriteLine("Events");
                Console.WriteLine("------------------------------------------------------------------------------------------------------");

                Console.WriteLine("Circuit events....");
                await control.AddEventHandlerAsync(AsyncEvent.CIRC, handler);

                await Task.Delay(4_000);

                await control.RemoveEventHandlerAsync(AsyncEvent.CIRC, handler);

                Console.WriteLine("Stream events....");
                await control.AddEventHandlerAsync(AsyncEvent.STREAM, handler2);

                await Task.Delay(16_000);

                await control.RemoveEventHandlerAsync(AsyncEvent.STREAM, handler2);

                Console.WriteLine("Debug events....");
                await control.AddEventHandlerAsync(AsyncEvent.DEBUG, handler);

                await Task.Delay(500);

                await control.RemoveEventHandlerAsync(AsyncEvent.DEBUG, handler);

                // await control.SignalAsync(Signal.SHUTDOWN);
            }

            Console.WriteLine("Goodbye. Enjoy it!");
        }