Created
September 4, 2014 05:33
-
-
Save imerr/0c04ab0013fd0efa9900 to your computer and use it in GitHub Desktop.
cloudflare browser check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import requests | |
| from types import * | |
| from urlparse import urlparse | |
| solverregex = re.compile('.*?setTimeout\(function\(\){.*?var t,r,a,f, ([^=]+)={"([^"]+)":([^}]+)};.+challenge-form\'\);.*?\n.*?;(.*?);a.value =.*?f\.submit\(\);.*?}, 5850\);.*', re.DOTALL) | |
| vcregex = re.compile('<input type="hidden" name="jschl_vc" value="([^"]+)"/>') | |
| def getNested(s, delim=("(", ")")): | |
| level = 0 | |
| pos = 0 | |
| for c in s: | |
| pos+=1 | |
| if c == delim[0]: | |
| level +=1 | |
| elif c == delim[1]: | |
| level -=1 | |
| if level == -1: | |
| return pos-1 | |
| print "Couldn't find matching - level ", level | |
| return s | |
| indent = -1 | |
| def solveEquation(q): | |
| global indent | |
| indent +=1 | |
| print '\t'*indent, "Parsing:", q | |
| pos = 0 | |
| res = 0 | |
| stringify = False | |
| if q[0] == "!": | |
| stringify = True | |
| while pos < len(q): | |
| if q[pos] == "(": | |
| nested = getNested(q[pos+1:len(q)]) | |
| nres = solveEquation(q[pos+1:pos+1+nested]) | |
| if type(nres) is StringType and type(res) is not StringType : | |
| res = str(res)+nres | |
| elif type(res) == StringType and type(nres) is IntType: | |
| res = res + str(nres) | |
| else: | |
| res +=nres | |
| pos+=nested+1 | |
| elif q[pos] == ")": | |
| pass | |
| pos+=1 | |
| elif q[pos:pos+4] == "!+[]": | |
| res+=1 | |
| pos+=4 | |
| elif q[pos:pos+5] == "+!![]": | |
| res+=1 | |
| pos+=5 | |
| elif q[pos:pos+3] == "+[]": | |
| pos+=3 | |
| elif q[pos:pos+2] == "+(": | |
| pos+=1 | |
| # we dont care about whitespaces | |
| elif q[pos] == " ": | |
| pos+=1 | |
| elif q[pos] == "\t": | |
| pos+=1 | |
| else: | |
| print '\t'*indent, "Unknown", q[pos:pos+6] | |
| break | |
| print '\t'*indent, "Res is ", res | |
| indent -=1 | |
| if stringify: | |
| return str(res) | |
| return res | |
| def solve(request, session): | |
| res = solverregex.findall(request.test) | |
| if len(res) == 0: | |
| print "Couldn't find answer script - No cloudflare check?" | |
| return False | |
| res=res[0] | |
| vc = vcregex.findall(request.test) | |
| if len(vc)==0: | |
| print "Couldn't find vc input - No cloudflare check?" | |
| return False | |
| vc = vc[0] | |
| print "VC is ", vc | |
| varname = (res[0], res[1]) | |
| solved = int(solveEquation(res[2].rstrip())) | |
| print "Initial value: ", res[2], "Solved:", solved | |
| for extra in res[3].split(";"): | |
| extra = extra.rstrip() | |
| if extra[:len('.'.join(varname))] != '.'.join(varname): | |
| print "Extra does not start with varname (", extra, ")" | |
| else: | |
| extra = extra[len('.'.join(varname)):] | |
| if extra[:2] == "+=": | |
| solved += int(solveEquation(extra[2:])) | |
| elif extra[:2] == "-=": | |
| solved -= int(solveEquation(extra[2:])) | |
| elif extra[:2] == "*=": | |
| solved *= int(solveEquation(extra[2:])) | |
| elif extra[:2] == "/=": | |
| solved /= int(solveEquation(extra[2:])) | |
| else: | |
| print "Unknown modifier", extra | |
| print "Solved value: ", solved | |
| up = urlparse(request.url) | |
| solved += len(up.netloc) | |
| print "With domain length", solved | |
| final = session.get(up.scheme+"//"+up.netloc+"/cdn-cgi/l/chk_jschl?jschl_vc={0}&jschl_answer={1}".format(vc, solved)) | |
| if final.status_code == 200: | |
| return final | |
| else: | |
| print "Status code not 200, but", final.status_code | |
| print "Might not have worked, returning request anyways" | |
| return final |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment