Guest User

myCode

a guest
Dec 2nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import requests
  3. import re
  4. import base64
  5. import os
  6.  
  7. # ENTER LOGIN BELOW
  8. username = "USERNAME"
  9. password = "PASSWORD"
  10.  
  11. ####################
  12.  
  13. sess=requests.Session()
  14.  
  15. #setting flag to verify base64 encoding in the last loop
  16. flag=1
  17.  
  18. login_url='https://ringzer0ctf.com/login'
  19. URL='http://ringzer0ctf.com/challenges/15'
  20.  
  21. def login(): #logs you in and prints status
  22. login_data=dict(username=username,password=password)
  23. r1=sess.post(login_url,data=login_data)
  24. print r1.status_code
  25.  
  26. def getMessage():#gets the message in this case the base64 you can just print msg.lstrip() to confirm its correct
  27. login()
  28. r2=sess.get(URL)
  29. msg = r2.text.splitlines()[71].strip('<br />')
  30. return msg.lstrip()
  31.  
  32.  
  33. def submit_answer(ansr): #submits the answer and then finds the flag
  34. r3=sess.get(URL+"/"+str(ansr))
  35. flag=re.findall(r'FLAG-\w+',r3.text)
  36. print flag
  37.  
  38. def decodedata(dat): #decodes the base64
  39. return base64.b64decode(dat)
  40.  
  41. def check(data): #verifies if the first 5 places in the given data is either alphabet or number if not then obviously binary data
  42. if (re.search(r'^[A-Za-z0-9+/]{5}', data)):
  43. flag=1
  44. else:
  45. flag=0
  46. return flag
  47.  
  48. #below function takes the binary data writes it in a binary file , makes it executable
  49. #then executes it stores the output in a string called stri and returns it
  50. def makeElf_and_execute(dta):
  51. f=open("elfFile","wb")
  52. f.write(dta[::-1])
  53. f.close()
  54. os.system('chmod +x elfFile')
  55. stri=os.popen('./elfFile').read()
  56. return stri
  57.  
  58.  
  59. dat=getMessage() #gets the base64 data
  60.  
  61. #the 3 line code below just takes the binary data and decodes it if its base64 then flag remains 1 when the check() function
  62. #detects that its not base64 it makes flag=0 and thus looping ends
  63. while(flag==1):
  64. dat=decodedata(dat)
  65. flag=check(dat)
  66.  
  67. #submit the answer
  68. answer=makeElf_and_execute(dat)
  69. print answer
Add Comment
Please, Sign In to add comment