Skip to content

Commit b62c203

Browse files
committed
Detect DDoS-Guard and Custom Cloudflare challenges
1 parent f576a1c commit b62c203

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

src/FlareSolverrSharp/ChallengeDetector.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,22 @@ public static class ChallengeDetector
2323
/// <returns>True if the site is protected</returns>
2424
private static bool IsCloudflareProtected(HttpResponseMessage response)
2525
{
26-
// check status code
26+
// check response headers
27+
if (!response.Headers.Server.Any(i =>
28+
i.Product != null && CloudflareServerNames.Contains(i.Product.Name.ToLower())))
29+
return false;
30+
31+
// detect CloudFlare and DDoS-GUARD
2732
if (response.StatusCode.Equals(HttpStatusCode.ServiceUnavailable) ||
2833
response.StatusCode.Equals(HttpStatusCode.Forbidden))
29-
{
30-
// check response headers
31-
return response.Headers.Server.Any(i =>
32-
i.Product != null && CloudflareServerNames.Contains(i.Product.Name.ToLower()));
33-
}
34+
return true; // Defected CloudFlare and DDoS-GUARD
35+
36+
// detect Custom CloudFlare for EbookParadijs, Film-Paleis, MuziekFabriek and Puur-Hollands
37+
if (response.Headers.Vary.ToString() == "Accept-Encoding,User-Agent" &&
38+
response.Content.Headers.ContentEncoding.ToString() == "" &&
39+
response.Content.ReadAsStringAsync().Result.ToLower().Contains("ddos"))
40+
return true;
41+
3442
return false;
3543
}
3644

test/FlareSolverrSharp.Tests/ClearanceHandlerTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,35 @@ public async Task SolveOkProxy()
9595
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
9696
}
9797

98+
[TestMethod]
99+
public async Task SolveOkCloudflareDDoSGuardGet()
100+
{
101+
var handler = new ClearanceHandler(Settings.FlareSolverrApiUrl)
102+
{
103+
MaxTimeout = 60000
104+
};
105+
106+
var client = new HttpClient(handler);
107+
var response = await client.GetAsync(Settings.ProtectedDdgUri);
108+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
109+
Assert.IsTrue(!response.Content.ReadAsStringAsync().Result.ToLower().Contains("ddos"));
110+
}
111+
112+
[TestMethod]
113+
public async Task SolveOkCloudflareCustomGet()
114+
{
115+
// Custom CloudFlare for EbookParadijs, Film-Paleis, MuziekFabriek and Puur-Hollands
116+
var handler = new ClearanceHandler(Settings.FlareSolverrApiUrl)
117+
{
118+
MaxTimeout = 60000
119+
};
120+
121+
var client = new HttpClient(handler);
122+
var response = await client.GetAsync(Settings.ProtectedCcfUri);
123+
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
124+
Assert.IsTrue(!response.Content.ReadAsStringAsync().Result.ToLower().Contains("ddos"));
125+
}
126+
98127
[TestMethod]
99128
public async Task SolveErrorUrl()
100129
{

test/FlareSolverrSharp.Tests/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ internal static class Settings
77
internal const string FlareSolverrApiUrl = "http://localhost:8191/";
88
internal const string ProxyUrl = "http://127.0.0.1:8888/";
99
internal static readonly Uri ProtectedUri = new Uri("https://pirateiro.com/torrents/?search=harry");
10+
internal static readonly Uri ProtectedDdgUri = new Uri("https://www.erai-raws.info/feed/?type=magnet");
11+
internal static readonly Uri ProtectedCcfUri = new Uri("https://www.muziekfabriek.org");
1012

1113
/*
1214
To configure TinyProxy in local:

0 commit comments

Comments
 (0)