Browse Source

cleaned code & added Python gitignore

Marius Schwarz 4 years ago
parent
commit
b40543da0e
4 changed files with 160 additions and 11 deletions
  1. 138 0
      .gitignore
  2. 9 3
      code/padd0r.py
  3. 11 7
      code/poc_po1.py
  4. 2 1
      lab/cookie_handler.py

+ 138 - 0
.gitignore

@@ -0,0 +1,138 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+cover/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+.pybuilder/
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+#   For a library or package, you might want to ignore these files since the code is
+#   intended to run in multiple environments; otherwise, check them in:
+# .python-version
+
+# pipenv
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
+#   install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# Cython debug symbols
+cython_debug/

+ 9 - 3
code/padd0r.py

@@ -4,6 +4,7 @@ from copy import deepcopy
 import logging
 import random
 from functools import reduce
+import sys
 
 class Encoding:
     ''' Encoding Enum '''
@@ -168,12 +169,13 @@ class PaddingOracle(object):
 
                     if first_run:
                         real_padding = pt_block[byte_index]
-                        print('')
                         first_run = False
 
                     it_block[byte_index] = guess ^ padding
                     logging.debug("[~]  correct padding [{0}] with byte [{1}]\n\t-> it_byte = {0} ^ {1}    = {3}\n\t-> pt_byte = it_byte ^ {2} = {4}\n".format(hex(padding),\
                             hex(guess), hex(orig_pre_ct[byte_index]), hex(it_block[byte_index]),hex(pt_block[byte_index])))
+
+
                     logging.debug("[+] Plaintext Block: {}".format(pt_block))
                     break
 
@@ -287,6 +289,9 @@ class PaddingOracle(object):
                 }
         logging.basicConfig(format='%(message)s', level=levels.get(level, logging.INFO))
 
+    def decrypt_block_at_index(self, index):
+        logging.info("[+] Decrypting block at index %d" % index)
+        self.crack_block(index)
 
     '''
         crack all blocks of the ciphertext (except first one)
@@ -298,9 +303,10 @@ class PaddingOracle(object):
 
         num_blocks = len(self.blocks)
         pt_blocks = []
-        logging.info("[*] decrypting all %d blocks" % num_blocks)
+        logging.info("[+] Decrypting all %d blocks" % num_blocks)
+
         for idx in range(num_blocks, 1, -1):
-            logging.info("\n-----[ decrypting block %d ]-----\n" %(idx))
+            logging.info("[*] Decrypting block %d" %(idx))
             it_block, pt_block = self.crack_last_block(local_blocks[:idx])
             pt_blocks.append(pt_block)
             local_blocks = deepcopy(orig_blocks)

+ 11 - 7
code/poc_po1.py

@@ -15,17 +15,19 @@ def oracle(ct):
     url = "http://127.0.0.1:5000/po1"
 
     data = {
-        "auth":b64encode(ct)
+        "auth":b64encode(ct).decode("utf-8")
     }
 
     text = requests.get(url, cookies=data).text
 
     # distinguish between a padding error and a valid padding
-    # ....
-
+    # dont forget to return true on a valid padding and false on a wrong padding
+    if "PaddingError" in text:
+        return False
+    return True
 
 
-    # dont forget to return true on a valid padding and false on a wrong padding
+ac = "jAJBizDAZZLtRw4WEM2Q4DFZeRbeQX791w5fis8Pyx2nXI8NpxpUHffLw67fIHEH+mrGDs81tyASQGKII6jyIq4u3iFYUap73xd4Xt+E0Cw5aJHuEc/OKNeCSQRrY6+nFcCg//304sx9y2wJDqT9pYOdxbGdca0OgmHSAzodx9g="
 
 
 def decrypt(cookie):
@@ -33,11 +35,13 @@ def decrypt(cookie):
     #                           verbosity can be 1 or 2
     #                                       which encodings are realistic?
     #                                                               pass the oracle functions as parameter
-    po = PaddingOracle(cookie, verbosity=1, encoding=Encoding.b64, oracle=oracle)
+    po = PaddingOracle(cookie, BS=16, verbosity=2, encoding=Encoding.b64, oracle=oracle)
     po.set_output("hex")
 
     # decrypt the blocks
+    po.decrypt_all_blocks()
 
+    #po.decrypt_last_block()
+    #po.decrypt_block_at_index(7)
 
-
-decrypt(admin_cookie)
+decrypt(ac)

+ 2 - 1
lab/cookie_handler.py

@@ -73,7 +73,8 @@ def create_cookie_po1(user_obj):
     print('Debug: user_obj: %s' %user_obj)
     user_obj.flag = FLAGS['po1']
 
-    cookie = b64encode(encr(str(user_obj))) return cookie
+    cookie = b64encode(encr(str(user_obj)))
+    return cookie
 def create_cookie_po2(user_obj):
     print('Debug: user_obj: %s' %user_obj)
     user_obj.flag = "P{Its-not-that-easy!;)}"