Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.ControlBox = false;

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("You have to enter both username and password.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            APIKeyGrabber.Username = textBox1.Text;
            APIKeyGrabber.Password = textBox2.Text;

            button1.Text    = "Logging in...";
            button1.Enabled = false;

            Task task = APIKeyGrabber.Run(new Action(() => {
                if (APIKeyGrabber.APIKey.Contains("Error:"))
                {
                    MessageBox.Show(APIKeyGrabber.APIKey, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    this.Invoke(new Action(() => { button1.Enabled = true; button1.Text = "Log in"; this.ControlBox = true; }));
                }
                else
                {
                    MessageBox.Show("Successfully got the API Key.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (System.Windows.Forms.MessageBox.Show("Do you want to save your API key on this computer? It could be used by bad guys for malicious activities.", "Question", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        if (!System.IO.Directory.Exists($"{AppData}\\ORB\\Private\\"))
                        {
                            System.IO.Directory.CreateDirectory($"{AppData}\\ORB\\Private\\");
                        }

                        System.IO.File.WriteAllText($"{AppData}\\ORB\\Private\\Key", APIKeyGrabber.APIKey);
                    }
                    Engine.ApiKey = APIKeyGrabber.APIKey;
                    this.Invoke(new Action(() => { this.Close(); }));
                }
            }));
        }
Beispiel #2
0
        public static async Task Run(Action callback)
        {
            try
            {
                HttpClientHandler handler = new HttpClientHandler()
                {
                    AllowAutoRedirect = false,
                    UseCookies        = true,
                    CookieContainer   = new CookieContainer()
                };
                int        retries = 10;
                HttpClient client  = new HttpClient((HttpMessageHandler)handler);
                client.DefaultRequestHeaders.Add("user-agent", "ORB (4.2.6S)");
                client.DefaultRequestHeaders.Add("referer", " https://osu.ppy.sh/forum/ucp.php?mode=login");
                HttpResponseMessage async = await client.GetAsync("https://osu.ppy.sh/forum/ucp.php?mode=login");

                StringContent content = new StringContent(("username="******"&password="******"&redirect=index.php&sid=&login=Login").Replace(' ', '+'));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                content.Headers.Add("origin", "https://osu.ppy.sh");
                content.Headers.Add("sec-fetch-mode", "navigate");
                content.Headers.Add("sec-fetch-site", "same-origin");
                content.Headers.Add("sec-fetch-user", "?1");
                content.Headers.Add("upgrade-insecure-requests", "1");
                using (HttpResponseMessage loginResp = await client.PostAsync("https://osu.ppy.sh/forum/ucp.php?mode=login", (HttpContent)content))
                {
                    string loginTextResp = await loginResp.Content.ReadAsStringAsync();

                    if (loginTextResp.Contains("You have specified an incorrect password.") || loginTextResp.Contains("You have specified an incorrect username."))
                    {
                        APIKeyGrabber.APIKey = "Error: Wrong username or password.";
                        callback();
                        return;
                    }
                    loginTextResp = (string)null;
                }
                while (retries > 0)
                {
                    using (HttpResponseMessage apiPageResp = await client.GetAsync("https://osu.ppy.sh/p/api"))
                    {
                        string apiPageTextResp = await apiPageResp.Content.ReadAsStringAsync();

                        if (apiPageTextResp.Contains("The title of your app which is requiring access to the API.") && apiPageTextResp.Contains("The URL of your app/site."))
                        {
                            string        localUserCheck = APIKeyGrabber.GetLocalUserCheck(apiPageTextResp);
                            StringContent creationParams = new StringContent("app_name=Osu!+Random+Beatmap&app_url=https%3A%2F%2Fgithub.com%2FAlexS4v%2FORB4&localUserCheck=" + localUserCheck);
                            creationParams.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                            using (HttpResponseMessage apiRegisterResp = await client.PostAsync("https://osu.ppy.sh/p/api", (HttpContent)creationParams))
                            {
                                string apiRegisterTextResp = await apiRegisterResp.Content.ReadAsStringAsync();

                                if (apiPageTextResp != "ok")
                                {
                                    --retries;
                                }
                                apiRegisterTextResp = (string)null;
                            }
                        }
                        else if (apiPageTextResp.Contains("DO NOT GIVE THIS OUT TO OTHERS.") && apiPageTextResp.Contains("IT'S EQUIVALENT TO GIVING OUT YOUR PASSWORD.") && apiPageTextResp.Contains("YOUR ACCOUNT MAY BE COMPROMISED."))
                        {
                            string apiKey = APIKeyGrabber.GetAPIKey(apiPageTextResp);
                            if (apiKey.Length != 40)
                            {
                                --retries;
                            }
                            else
                            {
                                APIKeyGrabber.APIKey = apiKey;
                                callback();
                                return;
                            }
                        }
                        else
                        {
                            --retries;
                        }
                    }
                }
                APIKeyGrabber.APIKey = "Error: Too many retries.";
                callback();
            }
            catch (Exception ex)
            {
                Exception e = ex;
                APIKeyGrabber.APIKey = "Error: Could not get the API Key due an unknown error";
                callback();
            }
        }