elcattivo / CloudFlareUtilities

A .NET Standard Library to bypass Cloudflare's Anti-DDoS measure (JavaScript challenge) using a DelegatingHandler.
MIT License
190 stars 47 forks source link

Input string was not in a correct format. #1

Closed properties closed 8 years ago

properties commented 8 years ago

Hi,

I tried this, but it doesnt work for some reason.

This is my code:


 using System;
 using System.Net.Http;
 using System.Text.RegularExpressions;

 namespace CloudFlareUtilities.CloudFlare_Test
 {
     class Program
     {
         static void Main(string[] args)
         {
             try
             {
                var handler = new ClearanceHandler();
                var client = new HttpClient(handler);

                var content = client.GetStringAsync("http://www.url.url/").Result;
                Console.WriteLine(content);
            }
            catch (AggregateException e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.ReadLine();
        }
    }
}

And I will get the error:

System.AggregateException: One or more errors occurred. ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at CloudFlareUtilities.ChallengeSolver.DeobfuscateNumber(String obfuscatedNumber) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 43
   at CloudFlareUtilities.ChallengeSolver.<>c.<DecodeSecretNumber>b__6_0(Match s) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 29
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
   at CloudFlareUtilities.ChallengeSolver.DecodeSecretNumber(String challengePageContent, String targetHost) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 30
   at CloudFlareUtilities.ChallengeSolver.Solve(String challengePageContent, String targetHost) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 17
   at CloudFlareUtilities.ClearanceHandler.<PassClearance>d__14.MoveNext() in ...\CloudFlareUtilities\CloudFlareUtilities\ClearanceHandler.cs:line 125
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at CloudFlareUtilities.ClearanceHandler.<SendAsync>d__10.MoveNext() in ...\CloudFlareUtilities\CloudFlareUtilities\ClearanceHandler.cs:line 73
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at CloudFlareUtilities.CloudFlare_Test.Program.Main(String[] args) in c:\users\matthew\documents\visual studio 2015\Projects\CloudFlare Test\CloudFlare Test\Program.cs:line 16
---> (Inner Exception #0) System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at CloudFlareUtilities.ChallengeSolver.DeobfuscateNumber(String obfuscatedNumber) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 43
   at CloudFlareUtilities.ChallengeSolver.<>c.<DecodeSecretNumber>b__6_0(Match s) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 29
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
   at CloudFlareUtilities.ChallengeSolver.DecodeSecretNumber(String challengePageContent, String targetHost) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 30
   at CloudFlareUtilities.ChallengeSolver.Solve(String challengePageContent, String targetHost) in ...\CloudFlareUtilities\CloudFlareUtilities\ChallengeSolver.cs:line 17
   at CloudFlareUtilities.ClearanceHandler.<PassClearance>d__14.MoveNext() in ...\CloudFlareUtilities\CloudFlareUtilities\ClearanceHandler.cs:line 125
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at CloudFlareUtilities.ClearanceHandler.<SendAsync>d__10.MoveNext() in ...\CloudFlareUtilities\CloudFlareUtilities\ClearanceHandler.cs:line 73<---

Line 16 is: var content = client.GetStringAsync("http://www.url.url/").Result;

Any suggestions? Thanksx.

elcattivo commented 8 years ago

Does the problem occur every time you try to open that specific URL or just sometimes?

Can you provide the JavaScript part of the clearance page? It should look like the following snippet:

<script type="text/javascript">
  //<![CDATA[
  (function(){
    var a = function() {try{return !!window.addEventListener} catch(e) {return !1} },
    b = function(b, c) {a() ? document.addEventListener("DOMContentLoaded", b, c) : document.attachEvent("onreadystatechange", b)};
    b(function(){
      var a = document.getElementById('cf-content');a.style.display = 'block';
      setTimeout(function(){
        var t,r,a,f, qNWWRKI={"FCGKXmfHH":+((+!![]+[])+(!+[]+!![]))};
        t = document.createElement('div');
        t.innerHTML="<a href='/'>x</a>";
        t = t.firstChild.href;r = t.match(/https?:\/\//)[0];
        t = t.substr(r.length); t = t.substr(0,t.length-1);
        a = document.getElementById('jschl-answer');
        f = document.getElementById('challenge-form');
        ;qNWWRKI.FCGKXmfHH*=+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]));qNWWRKI.FCGKXmfHH+=!+[]+!![];qNWWRKI.FCGKXmfHH-=+((!+[]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]));qNWWRKI.FCGKXmfHH*=+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]));qNWWRKI.FCGKXmfHH*=+((!+[]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]));qNWWRKI.FCGKXmfHH*=+((!+[]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]));qNWWRKI.FCGKXmfHH-=+((!+[]+!![]+[])+(+[]));qNWWRKI.FCGKXmfHH-=+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]+!![]+!![]+!![]));qNWWRKI.FCGKXmfHH-=+((+!![]+[])+(!+[]+!![]+!![]+!![]+!![]));a.value = parseInt(qNWWRKI.FCGKXmfHH, 10) + t.length;
        f.submit();
      }, 4000);
    }, false);
  })();
  //]]>
</script>
properties commented 8 years ago

I tried about 7 times, and it happend everytime.

Here is the javascript part:

<script type="text/javascript">
  //<![CDATA[
  (function(){
    var a = function() {try{return !!window.addEventListener} catch(e) {return !1} },
    b = function(b, c) {a() ? document.addEventListener("DOMContentLoaded", b, c) : document.attachEvent("onreadystatechange", b)};
    b(function(){
      var a = document.getElementById('cf-content');a.style.display = 'block';
      setTimeout(function(){
        var t,r,a,f, cevSPlu={"DcfQJnFXdLUO":+((!+[]+!![]+!![]+[])+(!+[]+!![]+!![]+!![]+!![]+!![]))};
        t = document.createElement('div');
        t.innerHTML="<a href='/'>x</a>";
        t = t.firstChild.href;r = t.match(/https?:\/\//)[0];
        t = t.substr(r.length); t = t.substr(0,t.length-1);
        a = document.getElementById('jschl-answer');
        f = document.getElementById('challenge-form');
        ;cevSPlu.DcfQJnFXdLUO*=+((!+[]+!![]+!![]+!![]+[])+(!+[]+!![]));a.value = parseInt(cevSPlu.DcfQJnFXdLUO, 10) + t.length;
        f.submit();
      }, 4000);
    }, false);
  })();
  //]]>
</script>
elcattivo commented 8 years ago

Well, that is strange. I can parse the script without any errors.

If you don't mind, can you tell me the actual URL? If you don't want to post it public, you can send me an email. You can find the address in my profile.

properties commented 8 years ago

Strange. I mailed you the URL.

elcattivo commented 8 years ago

The issue has been resolved in the latest release.

properties commented 8 years ago

It has been resolved indeed, thanks!

elcattivo commented 8 years ago

Thanks for finding the bug.