Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import requests
- import re
- import base64
- import os
- # ENTER LOGIN BELOW
- username = "USERNAME"
- password = "PASSWORD"
- ####################
- sess=requests.Session()
- #setting flag to verify base64 encoding in the last loop
- flag=1
- login_url='https://ringzer0ctf.com/login'
- URL='http://ringzer0ctf.com/challenges/15'
- def login(): #logs you in and prints status
- login_data=dict(username=username,password=password)
- r1=sess.post(login_url,data=login_data)
- print r1.status_code
- def getMessage():#gets the message in this case the base64 you can just print msg.lstrip() to confirm its correct
- login()
- r2=sess.get(URL)
- msg = r2.text.splitlines()[71].strip('<br />')
- return msg.lstrip()
- def submit_answer(ansr): #submits the answer and then finds the flag
- r3=sess.get(URL+"/"+str(ansr))
- flag=re.findall(r'FLAG-\w+',r3.text)
- print flag
- def decodedata(dat): #decodes the base64
- return base64.b64decode(dat)
- def check(data): #verifies if the first 5 places in the given data is either alphabet or number if not then obviously binary data
- if (re.search(r'^[A-Za-z0-9+/]{5}', data)):
- flag=1
- else:
- flag=0
- return flag
- #below function takes the binary data writes it in a binary file , makes it executable
- #then executes it stores the output in a string called stri and returns it
- def makeElf_and_execute(dta):
- f=open("elfFile","wb")
- f.write(dta[::-1])
- f.close()
- os.system('chmod +x elfFile')
- stri=os.popen('./elfFile').read()
- return stri
- dat=getMessage() #gets the base64 data
- #the 3 line code below just takes the binary data and decodes it if its base64 then flag remains 1 when the check() function
- #detects that its not base64 it makes flag=0 and thus looping ends
- while(flag==1):
- dat=decodedata(dat)
- flag=check(dat)
- #submit the answer
- answer=makeElf_and_execute(dat)
- print answer
Add Comment
Please, Sign In to add comment