Example #1
0
        private void ProxyConnectCallback(IAsyncResult ar)
        {
            if (_closed)
            {
                return;
            }
            try
            {
                var        session      = (AsyncSession <ProxyTimer>)ar.AsyncState;
                ProxyTimer timer        = session.State;
                var        destEndPoint = timer.DestEndPoint;
                var        server       = timer.Server;
                timer.Elapsed -= ProxyConnectTimer_Elapsed;
                timer.Enabled  = false;
                timer.Dispose();

                var remote = session.Remote;

                // Complete the connection.
                remote.EndConnectProxy(ar);

                _proxyConnected = true;

                if (!(remote is DirectConnect))
                {
                    Logger.Debug($"Socket connected to proxy {remote.ProxyEndPoint}");
                }

                _startConnectTime = DateTime.Now;
                ServerTimer connectTimer = new ServerTimer(_serverTimeout)
                {
                    AutoReset = false
                };
                connectTimer.Elapsed += DestConnectTimer_Elapsed;
                connectTimer.Enabled  = true;
                connectTimer.Session  = session;
                connectTimer.Server   = server;

                _destConnected = false;

                NetworkCredential auth = null;
                if (_config.proxy.useAuth)
                {
                    auth = new NetworkCredential(_config.proxy.authUser, _config.proxy.authPwd);
                }

                // Connect to the remote endpoint.
                remote.BeginConnectDest(destEndPoint, ConnectCallback,
                                        new AsyncSession <ServerTimer>(session, connectTimer), auth);
            }
            catch (ArgumentException)
            {
            }
            catch (Exception e)
            {
                Logger.LogUsefulException(e);
                Close();
            }
        }
Example #2
0
        protected void StartConnect(EndPoint target)
        {
            try
            {
                _destEndPoint = target;

                CreateRemote();

                // Setting up proxy
                IForwardProxy remote;
                EndPoint      proxyEP;
                if (Config.proxy.useProxy)
                {
                    switch (Config.proxy.proxyType)
                    {
                    case ProxyConfig.PROXY_SOCKS5:
                        remote = new Socks5Proxy();
                        break;

                    case ProxyConfig.PROXY_HTTP:
                        remote = new HttpProxy();
                        break;

                    default:
                        throw new NotSupportedException("Unknown forward proxy.");
                    }
                    proxyEP = SocketUtil.GetEndPoint(Config.proxy.proxyServer, Config.proxy.proxyPort);
                }
                else
                {
                    remote  = new DirectConnect();
                    proxyEP = null;
                }

                var session = new AsyncSession(remote);
                _currentRemoteSession = session;

                ProxyTimer proxyTimer = new ProxyTimer(_proxyTimeout);
                proxyTimer.AutoReset = false;
                proxyTimer.Elapsed  += proxyConnectTimer_Elapsed;
                proxyTimer.Enabled   = true;

                proxyTimer.Session      = session;
                proxyTimer.DestEndPoint = SocketUtil.GetEndPoint(_server.server, _server.server_port);
                proxyTimer.Server       = _server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, ProxyConnectCallback, new AsyncSession <ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
        private void ProxyConnectCallback(IAsyncResult ar)
        {
            Server server = null;

            if (_closed)
            {
                return;
            }
            try
            {
                var        session      = (AsyncSession <ProxyTimer>)ar.AsyncState;
                ProxyTimer timer        = session.State;
                var        destEndPoint = timer.DestEndPoint;
                server         = timer.Server;
                timer.Elapsed -= proxyConnectTimer_Elapsed;
                timer.Enabled  = false;
                timer.Dispose();

                var remote = session.Remote;

                // Complete the connection.
                remote.EndConnectProxy(ar);

                _proxyConnected = true;

                if (_config.isVerboseLogging)
                {
                    if (!(remote is DirectConnect))
                    {
                        Logging.Info($"Socket connected to proxy {remote.ProxyEndPoint}");
                    }
                }

                _startConnectTime = DateTime.Now;
                ServerTimer connectTimer = new ServerTimer(_serverTimeout);
                connectTimer.AutoReset = false;
                connectTimer.Elapsed  += destConnectTimer_Elapsed;
                connectTimer.Enabled   = true;
                connectTimer.Session   = session;
                connectTimer.Server    = server;

                _destConnected = false;
                // Connect to the remote endpoint.
                remote.BeginConnectDest(destEndPoint, new AsyncCallback(ConnectCallback),
                                        new AsyncSession <ServerTimer>(session, connectTimer));
            }
            catch (ArgumentException)
            {
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
Example #4
0
        private void StartConnect()
        {
            try
            {
                CreateRemote();

                // TODO async resolving
                IPAddress ipAddress;
                bool      parsed = IPAddress.TryParse(server.server, out ipAddress);
                if (!parsed)
                {
                    IPHostEntry ipHostInfo = Dns.GetHostEntry(server.server);
                    ipAddress = ipHostInfo.AddressList[0];
                }
                IPEndPoint destEP = new IPEndPoint(ipAddress, server.server_port);

                // Setting up proxy
                IPEndPoint proxyEP;
                if (_config.useProxy)
                {
                    parsed = IPAddress.TryParse(_config.proxyServer, out ipAddress);
                    if (!parsed)
                    {
                        IPHostEntry ipHostInfo = Dns.GetHostEntry(_config.proxyServer);
                        ipAddress = ipHostInfo.AddressList[0];
                    }

                    remote  = new Socks5Proxy();
                    proxyEP = new IPEndPoint(ipAddress, _config.proxyPort);
                }
                else
                {
                    remote  = new DirectConnect();
                    proxyEP = destEP;
                }


                ProxyTimer proxyTimer = new ProxyTimer(3000);
                proxyTimer.AutoReset    = false;
                proxyTimer.Elapsed     += proxyConnectTimer_Elapsed;
                proxyTimer.Enabled      = true;
                proxyTimer.DestEndPoint = destEP;
                proxyTimer.Server       = server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, new AsyncCallback(ProxyConnectCallback), proxyTimer);
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
Example #5
0
        private void StartConnect()
        {
            try
            {
                CreateRemote();

                // Setting up proxy
                IProxy   remote;
                EndPoint proxyEP;
                if (_config.useProxy)
                {
                    remote  = new Socks5Proxy();
                    proxyEP = SocketUtil.GetEndPoint(_config.proxyServer, _config.proxyPort);
                }
                else
                {
                    remote  = new DirectConnect();
                    proxyEP = null;
                }

                var session = new AsyncSession(remote);
                _currentRemoteSession = session;

                ProxyTimer proxyTimer = new ProxyTimer(3000);
                proxyTimer.AutoReset = false;
                proxyTimer.Elapsed  += proxyConnectTimer_Elapsed;
                proxyTimer.Enabled   = true;

                proxyTimer.Session      = session;
                proxyTimer.DestEndPoint = SocketUtil.GetEndPoint(server.server, server.server_port);
                proxyTimer.Server       = server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, new AsyncCallback(ProxyConnectCallback), new AsyncSession <ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
Example #6
0
        private void ProxyConnectTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            ProxyTimer timer = (ProxyTimer)sender;

            timer.Elapsed -= ProxyConnectTimer_Elapsed;
            timer.Enabled  = false;
            timer.Dispose();


            if (_proxyConnected || _destConnected || _closed)
            {
                return;
            }
            IProxy proxy = timer.Session.Remote;

            Logger.Info($"Proxy {proxy.ProxyEndPoint} timed out");
            proxy.Close();
            Close();
        }
Example #7
0
        private void StartConnect()
        {
            try
            {
                CreateRemote();

                // Setting up proxy
                IProxy   remote;
                EndPoint proxyEP  = null;
                EndPoint serverEP = SocketUtil.GetEndPoint(_server.server, _server.server_port);
                EndPoint pluginEP = _controller.GetPluginLocalEndPointIfConfigured(_server);

                if (pluginEP != null)
                {
                    serverEP = pluginEP;
                    remote   = new DirectConnect();
                }
                else if (_config.proxy.useProxy)
                {
                    switch (_config.proxy.proxyType)
                    {
                    case ProxyConfig.PROXY_SOCKS5:
                        remote = new Socks5Proxy();
                        break;

                    case ProxyConfig.PROXY_HTTP:
                        remote = new HttpProxy();
                        break;

                    default:
                        throw new NotSupportedException("Unknown forward proxy.");
                    }
                    proxyEP = SocketUtil.GetEndPoint(_config.proxy.proxyServer, _config.proxy.proxyPort);
                }
                else
                {
                    remote = new DirectConnect();
                }

                var session = new AsyncSession(remote);
                lock (_closeConnLock)
                {
                    if (_closed)
                    {
                        remote.Close();
                        return;
                    }

                    _currentRemoteSession = session;
                }

                ProxyTimer proxyTimer = new ProxyTimer(_proxyTimeout)
                {
                    AutoReset = false
                };
                proxyTimer.Elapsed += ProxyConnectTimer_Elapsed;
                proxyTimer.Enabled  = true;

                proxyTimer.Session      = session;
                proxyTimer.DestEndPoint = serverEP;
                proxyTimer.Server       = _server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, ProxyConnectCallback,
                                         new AsyncSession <ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logger.LogUsefulException(e);
                Close();
            }
        }
        private void StartConnect()
        {
            try
            {
                CreateRemote();

                // Setting up proxy
                IProxy remote;
                EndPoint proxyEP;
                if (_config.proxy.useProxy)
                {
                    switch (_config.proxy.proxyType)
                    {
                        case ProxyConfig.PROXY_SOCKS5:
                            remote = new Socks5Proxy();
                            break;
                        case ProxyConfig.PROXY_HTTP:
                            remote = new HttpProxy();
                            break;
                        default:
                            throw new NotSupportedException("Unknown forward proxy.");
                    }
                    proxyEP = SocketUtil.GetEndPoint(_config.proxy.proxyServer, _config.proxy.proxyPort);
                }
                else
                {
                    remote = new DirectConnect();
                    proxyEP = null;
                }

                var session = new AsyncSession(remote);
                _currentRemoteSession = session;

                ProxyTimer proxyTimer = new ProxyTimer(_proxyTimeout);
                proxyTimer.AutoReset = false;
                proxyTimer.Elapsed += proxyConnectTimer_Elapsed;
                proxyTimer.Enabled = true;

                proxyTimer.Session = session;
                proxyTimer.DestEndPoint = SocketUtil.GetEndPoint(_server.server, _server.server_port);
                proxyTimer.Server = _server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, new AsyncCallback(ProxyConnectCallback), new AsyncSession<ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
        private void StartConnect()
        {
            try
            {
                CreateRemote();

                // Setting up proxy
                IProxy remote;
                EndPoint proxyEP;
                if (_config.useProxy)
                {
                    remote = new Socks5Proxy();
                    proxyEP = SocketUtil.GetEndPoint(_config.proxyServer, _config.proxyPort);
                }
                else
                {
                    remote = new DirectConnect();
                    proxyEP = null;
                }

                var session = new AsyncSession(remote);
                _currentRemoteSession = session;

                ProxyTimer proxyTimer = new ProxyTimer(3000);
                proxyTimer.AutoReset = false;
                proxyTimer.Elapsed += proxyConnectTimer_Elapsed;
                proxyTimer.Enabled = true;

                proxyTimer.Session = session;
                proxyTimer.DestEndPoint = SocketUtil.GetEndPoint(server.server, server.server_port);
                proxyTimer.Server = server;

                _proxyConnected = false;

                // Connect to the proxy server.
                remote.BeginConnectProxy(proxyEP, new AsyncCallback(ProxyConnectCallback), new AsyncSession<ProxyTimer>(remote, proxyTimer));
            }
            catch (Exception e)
            {
                Logging.LogUsefulException(e);
                Close();
            }
        }
Example #10
0
        public bool TryPasswordVariant(string password)
        {
            //Cookies = new CookieContainer();

            RestRequest request = new RestRequest("/accounts/login/ajax/", Method.POST);

            request.AddParameter("password", password, ParameterType.GetOrPost);
            ProxyTimer.Restart();
            var response = _client.Execute(request);

            ProxyTimer.Stop();
            if (!response.IsSuccessful || response.ContentLength == 127)
            {
                if (++ProxyIndex >= Proxies.Length)
                {
                    ProxyIndex = 0;
                    SaveProxyTimes();
                }

                var lastProxy = _client.Proxy;
                _client.Proxy = Proxies[ProxyIndex];
                ProxyTimer.Restart();
                response = _client.Execute(request);
                ProxyTimer.Stop();

                if (!response.IsSuccessful || response.ContentLength == 127)
                {
                    _client.Proxy = lastProxy;
                    --ProxyIndex;

                    if (CurrentUserIteration > Proxies.Length / 2 ||)
                    {
                        var now = DateTime.Now;
                        UsernameRefreshTimes[UsernameIndex] = now.AddMinutes(12);
                        if (++UsernameIndex == Usernames.Length)
                        {
                            UsernameIndex = 0;
                        }
                        var nextRefresh = UsernameRefreshTimes[UsernameIndex];
                        if (nextRefresh > now)
                        {
                            Console.WriteLine("Sleeping until {0}", nextRefresh);
                            Thread.Sleep((int)(nextRefresh - now).TotalMilliseconds);
                        }

                        Console.WriteLine("{0} variants tested\t-\tswitching to account {1}", VariantsTried, Usernames[UsernameIndex]);
                        _client.DefaultParameters.First(p => p.Name == "username").Value = Usernames[UsernameIndex];
                        ProxyTimer.Restart();
                        response = _client.Execute(request);
                        ProxyTimer.Stop();
                    }
                    else
                    {
                        int lastIndex = ProxyIndex;
                        do
                        {
                            _client.Proxy = Proxies[ProxyIndex];
                            ProxyTimer.Restart();
                            response = _client.Execute(request);
                            ProxyTimer.Stop();
                        } while ((!response.IsSuccessful || response.ContentLength == 127) && ++ProxyIndex < Proxies.Length);

                        if (!response.IsSuccessful)
                        {
                            ProxyIndex = 0;
                            do
                            {
                                _client.Proxy = Proxies[ProxyIndex];
                                ProxyTimer.Restart();
                                response = _client.Execute(request);
                                ProxyTimer.Stop();
                            } while ((!response.IsSuccessful || response.ContentLength == 127) && ++ProxyIndex < lastIndex);
                        }
                    }

                    if (!response.IsSuccessful || response.ContentLength == 127)
                    {
                        SaveProxyTimes();
                        Console.WriteLine("Total failure, last password was {0}; {1} total variants tried", password, VariantsTried);
                        Console.ReadLine();
                    }
                }
            }

            if (!DontLogTimes.Contains(ProxyIndex))
            {
                if (ProxyTimes.ContainsKey(ProxyIndex))
                {
                    ProxyTimes[ProxyIndex].Add(ProxyTimer.ElapsedMilliseconds);
                }
                else
                {
                    ProxyTimes.Add(ProxyIndex, new List <long>()
                    {
                        ProxyTimer.ElapsedMilliseconds
                    });
                }
            }

            ++VariantsTried;
            ++CurrentUserIteration;
            ++CurrentProxyIteration;
            return(response.ContentLength > 60);
        }