public async Task ValidateAuthorityAsync( AuthorityInfo authorityInfo, RequestContext requestContext) { if (authorityInfo.ValidateAuthority) { string resource = string.Format(CultureInfo.InvariantCulture, "https://{0}", authorityInfo.Host); string webFingerUrl = Constants.FormatAdfsWebFingerUrl(authorityInfo.Host, resource); Http.HttpResponse httpResponse = await _serviceBundle.HttpManager.SendGetAsync( new Uri(webFingerUrl), null, requestContext.Logger, cancellationToken : requestContext.UserCancellationToken).ConfigureAwait(false); if (httpResponse.StatusCode != HttpStatusCode.OK) { throw MsalServiceExceptionFactory.FromHttpResponse( MsalError.InvalidAuthority, MsalErrorMessage.AuthorityValidationFailed, httpResponse); } AdfsWebFingerResponse wfr = OAuth2Client.CreateResponse <AdfsWebFingerResponse>(httpResponse, requestContext); if (wfr.Links.FirstOrDefault( a => a.Rel.Equals(Constants.DefaultRealm, StringComparison.OrdinalIgnoreCase) && a.Href.Equals(resource)) == null) { throw new MsalClientException( MsalError.InvalidAuthority, MsalErrorMessage.InvalidAuthorityOpenId); } } }
public static T WithData <T>(this T ex, Http.HttpResponse response, int maxSampleLength = 512) where T : Exception { if (response == null || response.Content == null) { return(ex); } var contentSample = response.Content.Substring(0, Math.Min(response.Content.Length, maxSampleLength)); if (response.Request != null) { ex.AddData("RequestUri", response.Request.Url.ToString()); if (response.Request.ContentSummary != null) { ex.AddData("RequestSummary", response.Request.ContentSummary); } } ex.AddData("StatusCode", response.StatusCode.ToString()); if (response.Headers != null) { ex.AddData("ContentType", response.Headers.ContentType ?? string.Empty); } ex.AddData("ContentLength", response.Content.Length.ToString()); ex.AddData("ContentSample", contentSample); return(ex); }
public async Task RecordSessionAsync(Http.HttpRequest request, Http.HttpResponse response, TimeSpan duration) { int sessionId = -1; lock (this) { sessionId = nextSessionNumber++; } // Write client request var requestPart = this.outputPackage.CreatePart(UriForPart(sessionId, 'c'), "text/plain"); using (var requestStream = requestPart.GetStream(System.IO.FileMode.Create)) { await request.WriteToStreamAsync(requestStream); } var responsePart = this.outputPackage.CreatePart(UriForPart(sessionId, 's'), "text/plain"); using (var responseStream = responsePart.GetStream(System.IO.FileMode.Create)) { await response.WriteToStreamAsync(responseStream); } var metadataPart = this.outputPackage.CreatePart(UriForPart(sessionId, 'm'), "application/xml"); var metadata = CreateMetadataForSession(sessionId, request.StartTime, duration); using (var metadataStream = metadataPart.GetStream(System.IO.FileMode.Create)) { await metadata.WriteToStreamAsync(metadataStream); } }
/// <summary> /// HTTP/1.1 요청이 들어오면 이곳에서 처리합니다. /// </summary> /// <param name="request">HTTP 요청 데이터</param> /// <returns>HTTP 리스폰스</returns> private Http.HttpResponse OnHttpRequest(Http.HttpRequest request) { Console.WriteLine("SimpleAdaptor::OnHttpRequest " + request.requestUri); var response = new Http.HttpResponse(); response.code = Http.ResponseCode.OK; response.reasonPhrase = "OK"; response.SetContent("Hello World! " + request.requestUri); throw new CloseSessionException(response); //return response; }
private String[] parseResponse(HttpWebResponse r) { String[] asdf = null; if (r != null) { Http.HttpResponse response = new Http.HttpResponse(); Http a = new Http(); response = a.GetResponse(r); // response = Http.GetResponse(r); ScanEventArgs args = new ScanEventArgs { Detections = new Dictionary <string, string>() }; args.BBCode = a.ParseBetween(response.Html, "<textarea style=\"width: 100%; height: 200px;\">[u]", "</textarea>", "<textarea style=\"width: 100%; height: 200px;\">".Length); args.Rate = a.ParseBetween(args.BBCode, "[u][b]Result:[/b][/u] ", "[u][b]", "[u][b]Result:[/b][/u] ".Length).Trim(); args.Link = a.ParseBetween(args.BBCode, "[url]", "[/url", "[url]".Length); string detections = a.ParseBetween(args.BBCode, "[/url]", "[i]", "[/url]".Length).Trim(); string[] lines = detections.Split('\n'); foreach (string t in lines) { /* * string[] x = t.Split(new string[] { "[/b] : [color=" }, StringSplitOptions.RemoveEmptyEntries); * * for (int s = 0; s < x.Length; s++) * { * x[s] = x[s].Replace("[b]", "").Replace("green]", "").Replace("red]", "").Replace("[/color]", ""); * } * args.Detections.Add(x[0].Trim(), x[1].Replace("File seems clean", "Clean").Trim()); */ args.Detections.Add(t, "0"); } //OnScanComplete(args); asdf = lines; } return(asdf); }
private Http.HttpResponse OnHttpRequest(Http.HttpRequest request) { Console.WriteLine("StaticFileAdaptor::OnHttpRequest " + request.requestUri); var response = new Http.HttpResponse(); var path = request.requestUri.Substring(1).Replace("/", "\\"); if (path.Contains("..\\")) { response.code = Http.ResponseCode.Forbidden; response.reasonPhrase = "Forbidden"; } else if (File.Exists(path) == false) { response.code = Http.ResponseCode.NotFound; response.reasonPhrase = "NotFound"; } else { response.code = Http.ResponseCode.OK; response.reasonPhrase = "OK"; response.headers["Content-Type"] = "application/octet-stream"; using (var fp = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { if (fp.Length > int.MaxValue) { throw new NotImplementedException("size over INT_MAX"); } response.content = new byte[fp.Length]; fp.Read(response.content, 0, Convert.ToInt32(fp.Length)); } } return(response); }
public void Login() { if (!LoginThreaded) { LoginThreaded = true; Thread thread = new Thread(Login) { IsBackground = true, Priority = ThreadPriority.BelowNormal }; thread.Start(); return; } LoginThreaded = false; Reset(); Http.TimeOut = 10000; Http.DebugMode = true; Http.AutoRedirect = true; StringBuilder postData = new StringBuilder(); postData.Append("username="******"&password="******"&send=Login&rememberme=on"); Http.ContentType = "application/x-www-form-urlencoded"; Http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; Http.Referer = "http://scan4you.net/remote.php"; Http.HttpResponse response = Http.GetResponse(Http.Verb.POST, "http://scan4you.net/remote.php", postData.ToString()); response = Http.GetResponse(Http.Verb.GET, "http://www.cyber-software.org/scan/index.php?cs=csscanner"); bool success = response.Html.Contains("Logout"); OnLogin(success); LoggedIn = success; }
private void ScanFile(object fileName) { if (!ScanThreaded) { ScanThreaded = true; Thread thread = new Thread(ScanFile) { Priority = ThreadPriority.BelowNormal, IsBackground = true }; thread.Start(fileName); return; } ScanThreaded = false; ScanEventArgs args = new ScanEventArgs { Detections = new Dictionary <string, string>() }; string path = (string)fileName; Http.TimeOut = 600000; Http.DebugMode = true; Http.AutoRedirect = true; FileInfo fileInfo = new FileInfo(path); Http.UploadData data = new Http.UploadData(File.ReadAllBytes(path), fileInfo.Name, "file"); Http.Referer = "http://www.cyber-software.org/scan/index.php?cs=csscanner"; NameValueCollection fields = new NameValueCollection { { "send", "Check File" }, { "url", "http://" }, { "domen", "http://" }, { "pack", "http://" } }; Http.HttpResponse response = Http.GetResponse(Http.Verb.POST, "http://www.cyber-software.org/scan/index.php?cs=csscanner", null, fields, data); args.BBCode = Http.ParseBetween(response.Html, "<textarea style=\"width: 100%; height: 200px;\">[u]", "</textarea>", "<textarea style=\"width: 100%; height: 200px;\">".Length); args.Rate = Http.ParseBetween(args.BBCode, "[u][b]Result:[/b][/u] ", "[u][b]", "[u][b]Result:[/b][/u] ".Length).Trim(); args.Link = Http.ParseBetween(args.BBCode, "[url]", "[/url", "[url]".Length); string detections = Http.ParseBetween(args.BBCode, "[/url]", "[i]", "[/url]".Length).Trim(); string[] lines = detections.Split('\n'); foreach (string t in lines) { string[] x = t.Split(new string[] { "[/b] : [color=" }, StringSplitOptions.RemoveEmptyEntries); for (int s = 0; s < x.Length; s++) { x[s] = x[s].Replace("[b]", "").Replace("green]", "").Replace("red]", "").Replace("[/color]", ""); } args.Detections.Add(x[0].Trim(), x[1].Replace("File seems clean", "Clean").Trim()); } OnScanComplete(args); }
private Http.HttpResponse ExecCgi(Http.HttpRequest request) { Process p = new Process(); var env = p.StartInfo.EnvironmentVariables; var tokens = request.requestUri.Split(new char[] { '?' }, 2); if (tokens.Length != 2) { env["QUERY_STRING"] = ""; } else { env["QUERY_STRING"] = tokens[1]; } env["REQUEST_URI"] = request.requestUri; env["DOCUMENT_URI"] = "/"; var scriptPath = request.path; if (scriptPath.EndsWith("/")) { scriptPath += "index.php"; } scriptPath = scriptPath.Substring(1); env["SCRIPT_FILENAME"] = scriptPath; env["SCRIPT_NAME"] = "IM JINWOO"; env["GATEWAY_INTERFACE"] = "CGI/1.1"; env["SERVER_SOFTWARE"] = "ASDF"; env["REDIRECT_STATUS"] = "CGI"; env["SERVER_ADDR"] = "127.0.0.1"; env["SERVER_NAME"] = "JIWNOOSERVER"; env["SERVER_PORT"] = "80"; env["SERVER_PROTOCOL"] = "HTTP/1.1"; env["SERVER_SIGNATURE"] = ""; env["SERVER_SOFTWARE"] = "HttpServ.cs"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.FileName = "C:\\Users\\hyun\\Downloads\\php-7.0.8-nts-Win32-VC14-x86\\php-cgi.exe"; p.StartInfo.WorkingDirectory = "C:\\Users\\hyun\\Downloads\\php-7.0.8-nts-Win32-VC14-x86\\"; p.Start(); if (p.WaitForExit(1000) == false) { throw new InvalidOperationException("CGI::TimeOut"); } Console.WriteLine("END PHP"); var buffer = p.StandardOutput.ReadToEnd(); var error = p.StandardError.ReadToEnd(); Console.WriteLine(error); Console.WriteLine("PHP DATA"); Console.WriteLine(buffer); var builder = new Http.HttpRequestBuilder(); builder.parser.ForceSkipRequestLine(); builder.parser.ForceAllowContentWithoutLength(); foreach (var w in builder.Write(Encoding.UTF8.GetBytes(buffer))) { ; } var cgiResult = builder.WriteEof(); foreach (var header in cgiResult.headers) { Console.WriteLine($"{header.Key} : {header.Value}"); } Console.WriteLine(Encoding.UTF8.GetString(cgiResult.content)); var response = new Http.HttpResponse(Http.ResponseCode.OK); foreach (var header in cgiResult.headers) { response.headers[header.Key] = header.Value; } response.SetContent(cgiResult.content); return(response); }