Exemplo n.º 1
0
        public async Task <HttpClientProxyResponse> SendAsync(HttpClientProxyRequest proxyRequest)
        {
            var httpRequest = new HttpRequestMessage(proxyRequest.HttpMethod, proxyRequest.Url);

            if (proxyRequest.Values != null)
            {
                httpRequest.Content = new FormUrlEncodedContent(proxyRequest.Values);
            }

            if (proxyRequest.Cookies != null)
            {
                // TODO
                // Do I need to add this cookie back in or does it remeber for the current session?
                //_cookies.Add(proxyRequest.Cookies);
            }

            var httpResponse = await _client.SendAsync(httpRequest);

            var proxyResponse = new HttpClientProxyResponse
            {
                StatusCode = httpResponse.StatusCode,
                Contents   = httpResponse.Content == null ? "" : await httpResponse.Content.ReadAsStringAsync(),
                Cookies    = _cookies.GetCookies(new Uri(_client.BaseAddress, proxyRequest.Url))
            };

            //var responseCookies = _cookies.GetCookies().Cast<Cookie>();

            return(proxyResponse);
        }
        public void Create(string key, string value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var antiForgeryToken = _antiForgeryAction.GetToken(_relativePath);

            var values = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Key", key),
                new KeyValuePair <string, string>("Value", value)
            };

            if (!string.IsNullOrEmpty(antiForgeryToken))
            {
                values.Add(new KeyValuePair <string, string>("__RequestVerificationToken", antiForgeryToken));
            }

            // Login as hacker - get session cookie
            var newSecretRequest = new HttpClientProxyRequest
            {
                Url        = _relativePath,
                HttpMethod = HttpMethod.Post,
                Values     = values
                             //Cookies = antiForgeryResponse.Cookies
            };

            var newSecretResponse = _client.SendAsync(newSecretRequest).Result;
        }
        public string GetTargetSecret(string secretKey)
        {
            // Get the contents of the Secrets
            var secretsRequest = new HttpClientProxyRequest
            {
                Url        = _relativePath,
                HttpMethod = HttpMethod.Get
            };

            var secretsResponse = _client.SendAsync(secretsRequest).Result;

            return(GetSecret(secretsResponse.Contents, secretKey));
        }
Exemplo n.º 4
0
        public string GetToken(string relativePath)
        {
            if (relativePath == null)
            {
                throw new ArgumentNullException("relativePath");
            }

            // Get the anti-forgery token for login
            var antiForgeryRequest = new HttpClientProxyRequest
            {
                Url        = relativePath,
                HttpMethod = HttpMethod.Get
            };
            var antiForgeryResponse = _client.SendAsync(antiForgeryRequest).Result;

            return(GetTokenFromContent(antiForgeryResponse.Contents));
        }
Exemplo n.º 5
0
        public async Task LoginAsync(string user, string password)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            var antiForgeryToken = _antiForgeryAction.GetToken(_relativePath);

            var values = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Username", user),
                new KeyValuePair <string, string>("Password", password)
            };

            if (!string.IsNullOrEmpty(antiForgeryToken))
            {
                values.Add(new KeyValuePair <string, string>("__RequestVerificationToken", antiForgeryToken));
            }

            // Login as hacker - get session cookie
            var loginRequest = new HttpClientProxyRequest
            {
                Url        = _relativePath,
                HttpMethod = HttpMethod.Post,
                Values     = values
                             //Cookies = antiForgeryResponse.Cookies
            };

            var loginResponse = await _client.SendAsync(loginRequest);

            if (loginResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                if (!loginResponse.Contents.Contains("Invalid login attempt."))
                {
                    _successful = true;
                }
            }
        }