Nov 9, 2014 03:20 PM
(This post was last modified: Nov 9, 2014 07:02 PM by idb..)
A site that I was working with recently implemented CF so it was fucking with my automation over WebRequests code. Threw this together so that I could go through CloudFlare without having to use a WebBrowser method (similar to the one provided here: https://hackforums.net/showthread.php?tid=3762105 ). Interesting little piece of code though. Shows how to emulate some Javascript, which from what I've seen most people haven't really messed with outside of the Browser.
Before I get into it let me make mention that you need to add a reference to the Microsoft Script Control in order for it to work properly. Also keep in mind that I've only tested this code on a few sites. There could be errors when parsing the JS values. If it's fucking up for you, drop a line and let me know so I can update.
In order to use this you will need to pass the html that was returned from the CF page that appears when you're requesting whatever Url you're requesting.
Also make sure that you account for the __cfduid (returned when you request the page and CF is returned) & cf_clearance (returned when you perform your request to /cdn-cgi/l/chk_jschl in order to pass through the CF) cookies. Without these cookies you will just get the CF landing page over and over.
If I get some more free time today I'll try to throw together a little example to show how this is actually used. For now having the required values returned to you should be good enough.
Anyhow, hope this helps someone out there. If not, shrug atleast I was entertained for a brief period of time. lol.
Before I get into it let me make mention that you need to add a reference to the Microsoft Script Control in order for it to work properly. Also keep in mind that I've only tested this code on a few sites. There could be errors when parsing the JS values. If it's fucking up for you, drop a line and let me know so I can update.
Code
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Text.RegularExpressions
Friend Class CloudFlare
Public Shared Function Bypass(html As String, host As String) As DictionaryEntry
Dim js As New MSScriptControl.ScriptControl() With {.AllowUI = False, .Language = "JScript"}
Dim result As DictionaryEntry = Nothing
Try
Dim m As MatchCollection = Regex.Matches(html, "var t,r,a,f, (?<value>.*?|[\s\S]*?)a.value")
If m.Count.Equals(0) Then Throw New Exception("Could not parse script values.")
Dim value As String = m(0).Groups("value").Value
Dim key As String = String.Join(".", value.Split("="c)(0), value.Split(""""c)(1))
Dim lines As New List(Of String)
For Each line As String In From item In value.Split(";"c) Select item = item.Trim Where Not String.IsNullOrEmpty(item) Where item.StartsWith(key.Split("."c)(0))
If line.StartsWith(key.Split("."c)(0) & "=") Then
lines.Add("var " & line & ";")
Else
lines.Add(line & ";")
End If
Next
Dim code As New StringBuilder("function bypass(host)")
With code
.AppendLine("{")
For Each line As String In lines
.AppendLine(line)
Next
.AppendLine(String.Format(" var res = parseInt({0}, 10) + host.length;", key))
.AppendLine(" return res;")
.AppendLine("}")
js.AddCode(.ToString)
End With
Dim params As Object() = New Object() {host}
result = New DictionaryEntry(Regex.Match(html, """([a-fA-F\d]{32})""").Groups(1).Value, js.Run("bypass", params).ToString)
Catch ex As Exception
Finally
js.Reset()
Marshal.FinalReleaseComObject(js)
js = Nothing
End Try
Return result
End Function
End ClassIn order to use this you will need to pass the html that was returned from the CF page that appears when you're requesting whatever Url you're requesting.
Code
Dim cf As DictionaryEntry = CloudFlare.BypassCloudflare(html, "bombshare.altervista.org")
If cf.Key IsNot Nothing Then
Debug.Print("vc: " & cf.Key.ToString)
Debug.Print("answer: " & cf.Value.ToString)
End IfAlso make sure that you account for the __cfduid (returned when you request the page and CF is returned) & cf_clearance (returned when you perform your request to /cdn-cgi/l/chk_jschl in order to pass through the CF) cookies. Without these cookies you will just get the CF landing page over and over.
If I get some more free time today I'll try to throw together a little example to show how this is actually used. For now having the required values returned to you should be good enough.
Anyhow, hope this helps someone out there. If not, shrug atleast I was entertained for a brief period of time. lol.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)
STOP STEALING CODE.
FREE NATHAN
People who report posts are lamers.
STOP STEALING CODE.
FREE NATHAN
People who report posts are lamers.



