public bool Bypass(HttpSession <Application> session, Request req, RequestResponse rr) { string url = req.Url; string baseUrl = url.EndsWith("/") ? StringFunc.Substring(url, 0, url.Length - 1) : url; string domainName = baseUrl.Split("/")[2]; string resolveUrl = ResolveUrl(rr.GetAsDoc(), domainName, baseUrl); if (string.IsNullOrEmpty(resolveUrl)) { return(false); } Misc.Sleep(5500); rr = session.DispatchRequest(new GetRequest(resolveUrl)); if (rr.Validate(200)) { return(true); } if (rr.Validate(403)) { //String captcha = new CaptchaService().recaptchaV2(c, "6LfBixYUAAAAABhdHynFUIMA_sa4s-XsJvnjtgB0", resolveUrl); //String url = "https://" + domainName + "/cdn-cgi/l/chk_captcha"; Console.WriteLine("CAPTCHA ON CLOUDFARE!"); return(false); } Console.WriteLine("Unexpected response (" + rr.ResponseCode + ")"); return(false); }
private void WriteFilePart(IHttpStreamable httpStream, bool prepare, string key, FileLink value) { FileInfo fileInfo = (FileInfo)value.GetInfo(); string fileName = fileInfo.Name; if (NoMediaExtension) { fileName = StringFunc.Substring(fileName, 0, fileName.IndexOf(fileInfo.Extension)); } httpStream.WriteLine("Content-Disposition: form-data; name=\"" + key + "\"; filename=\"" + fileName + "\""); httpStream.WriteLine("Content-Type: " + MimeType.GetByFile(value).Notation); if (!Chunked) { httpStream.WriteLine("Content-Transfer-Encoding: binary"); } httpStream.WriteLine(); httpStream.FlushUnderlying(); if (!prepare) { WriteFile(httpStream, value); } httpStream.WriteLine(); httpStream.FlushUnderlying(); }
private static string ResolveUrl(Document doc, string domainName, string baseUrl) { try { Element jschlEl = doc.Select("[name=jschl_vc]").First; if (jschlEl == null) { Console.WriteLine("Failed to extract jsch element"); return(null); } string jschl_vc = jschlEl.Attr("value"); string pass = doc.Select("[name=pass]").First.Attr("value"); Element scriptEl = doc.GetElementsByTag("script").First; if (scriptEl == null) { Console.WriteLine("Failed to extract script element"); return(null); } string scriptHtml = scriptEl.Html; string content = StringFunc.Substring(scriptHtml, scriptHtml.IndexOf("setTimeout(function(){") + 22, scriptHtml.Length).Trim(); string part1 = StringFunc.Substring(content, 31, content.IndexOf("};") + 2); //@INFO: The first equation initially added to the builder var string[] part1Split = part1.Split("="); string objName = part1Split[0]; string objKey = StringFunc.Substring(part1Split[1], 2, part1Split[1].IndexOf(":") - 1); string objVar = objName + "." + objKey; //@INFO: The var of the object to use (name.key) string equationBlock = StringFunc.Substring(content, content.IndexOf(";" + objVar), content.IndexOf("a.value")); //The equation block double equationResult = (double)Javascript.ExecuteFunction("function test() { " + part1 + "" + equationBlock + " var aval = +" + objVar + ".toFixed(10); return aval;}", "test"); //System.out.println(equationResult); double result = equationResult + domainName.Length; //System.out.println(result); string formatResult = string.Format("%.10f", result).Replace(",", "."); return(baseUrl + "/cdn-cgi/l/chk_jschl?jschl_vc=" + jschl_vc + "&pass="******"&jschl_answer=" + formatResult); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } return(null); }
public Stream Decode(Stream inputStream) { List <byte> lineBuffer = new List <byte>(); while (true) { byte b = (byte)inputStream.ReadByte(); if (b < 0) { Console.WriteLine("Malformed server response received, EOF reached unexpectedly"); return(null); } lineBuffer.Add(b); if (b != 10) //Keep collecting bytes if there's no linefeed (new line) \n indicated { continue; } byte[] lineBufferArray = new byte[lineBuffer.Count]; for (int i = 0; i < lineBufferArray.Length; i++) { lineBufferArray[i] = lineBuffer[i]; } string line = Encoding.ASCII.GetString(lineBufferArray).Trim(); //Build a string out of our collected bytes and trim off the line break lineBuffer.Clear(); //Clears the line buffer for the next read if (line == string.Empty) //When an empty line is found it means we parsed all headers { break; } if (line.Equals("0", StringComparison.Ordinal) || line.Equals(Delimiters.Linebreak, StringComparison.Ordinal)) { break; } if (line.StartsWith("HTTP", StringComparison.OrdinalIgnoreCase)) //The status line of the response { string[] msgParts = line.Split(" "); string httpProtocolVersion = msgParts[0]; string responseCode = msgParts[1]; StringBuilder responseMsgBuilder = new StringBuilder(); for (int i = 2; i < msgParts.Length; i++) { responseMsgBuilder.Append(msgParts[i] + " "); } int code = MathUtil.ParseInt(responseCode); HttpCode httpCode = HttpCode.GetForCode(code); string msg = responseMsgBuilder.ToString().Trim(); if (string.IsNullOrEmpty(msg)) { msg = httpCode.Message; } if (httpCode == HttpCode.Invalid) { msg = "[Unhandled code: " + code + "] - " + msg; } ResponseStatus = new ResponseStatus(HttpVersion.Parse(httpProtocolVersion), httpCode, msg); continue; } string key = StringFunc.Substring(line, 0, line.IndexOf(":")).Trim(); string value = StringFunc.Substring(line, line.IndexOf(":") + 1, line.Length).Trim(); if (!key.Equals(HeaderKeys.SetCookie, StringComparison.OrdinalIgnoreCase)) { Headers.Put(key, value); if (HttpConfig.DebugMode) { Console.WriteLine("RESPONSE-HEADER => " + key + ": " + value); } continue; } Cookie cookie = ExtractCookie(value); Cookies.Add(cookie); if (HttpConfig.DebugMode) { Console.WriteLine("RESPONSE-COOKIE => " + cookie.ToString()); } } return(inputStream); }
private static Cookie ExtractCookie(string headerValue) { string[] fields = headerValue.Split(";"); string key = StringFunc.Substring(fields[0], 0, fields[0].IndexOf("=")).Trim(); string value = StringFunc.Substring(fields[0], fields[0].IndexOf("=") + 1, fields[0].Length); string expires = null; string path = "/"; string domain = "/"; bool secure = false; bool httpOnly = false; long maxAge = 0L; string sameSite = "Lax"; for (int i = 1; i < fields.Length; i++) { string field = fields[i].Trim(); if (field.Equals(CookieKeys.Secure, StringComparison.OrdinalIgnoreCase)) { secure = true; continue; } if (field.Equals(CookieKeys.HttpOnly, StringComparison.OrdinalIgnoreCase)) { httpOnly = true; continue; } if (!field.Contains("=", StringComparison.Ordinal)) { Console.WriteLine("Malformed cookie field: " + fields[i]); continue; } string fieldKey = StringFunc.Substring(field, 0, field.IndexOf("=")).Trim(); string fieldValue = StringFunc.Substring(field, field.IndexOf("=") + 1, field.Length); if (fieldKey.Equals(CookieKeys.Expires, StringComparison.OrdinalIgnoreCase)) { expires = fieldValue; continue; } if (fieldKey.Equals(CookieKeys.Domain, StringComparison.OrdinalIgnoreCase)) { domain = fieldValue; continue; } if (fieldKey.Equals(CookieKeys.Path, StringComparison.OrdinalIgnoreCase)) { path = fieldValue; continue; } if (fieldKey.Equals(CookieKeys.MaxAge, StringComparison.OrdinalIgnoreCase)) { maxAge = MathUtil.ParseLong(fieldValue, true, 0L); continue; } if (fieldKey.Equals(CookieKeys.SameSite, StringComparison.OrdinalIgnoreCase)) { sameSite = fieldValue; continue; } Console.WriteLine("Unhandled cookie field: " + fields[i]); } Cookie cookie = new Cookie(key, value, domain); cookie.Expires = expires; cookie.Path = path; cookie.Secure = secure; cookie.MaxAge = maxAge; cookie.SameSite = sameSite; return(cookie); }