|
| 1 | +# Some code for learning Padding Oracle Attack |
| 2 | +There is a exploitable backend and an exploit script |
| 3 | + |
| 4 | +# Setup |
| 5 | +```bash |
| 6 | +git clone https://gitlab.com/kmille/padding-oracle.git |
| 7 | +python -m virtualenv -p python2 venv |
| 8 | +source venv/bin/activate |
| 9 | +cd padding-oracle |
| 10 | +pip install -r requirements.txt |
| 11 | + |
| 12 | +# Run the backend |
| 13 | +source venv/bin/activate |
| 14 | +gunicorn --bind 127.0.0.1:5000 backend:app |
| 15 | + |
| 16 | +# Run the backend script in a new tab |
| 17 | +source venv/bin/activate |
| 18 | +cd padding-oracle |
| 19 | +python exploit_backend.py # for more debug output disable some comments in oracle.Oracle.solve_oracle |
| 20 | +``` |
| 21 | + |
| 22 | +# Example Output |
| 23 | +<pre> |
| 24 | +Get the encrypted message |
| 25 | +IV: 7468697373686f756c646265726e646d |
| 26 | +Cipher: 4eff7c78220e0a1d63439eb7707c2583d1acf7be521e2cdb7dcdd77e22676481 |
| 27 | +Let the backend decrypt the message for testing |
| 28 | +Die ist ein beta Test |
| 29 | +Ciphertext in hex(64): 4eff7c78220e0a1d63439eb7707c2583d1acf7be521e2cdb7dcdd77e22676481 |
| 30 | +Ciphertext Blocks in hex: [u'4eff7c78220e0a1d63439eb7707c2583', u'd1acf7be521e2cdb7dcdd77e22676481'] |
| 31 | +Block counter: 1 |
| 32 | +Processing block #1: d1acf7be521e2cdb7dcdd77e22676481 |
| 33 | +Round counter: 0 |
| 34 | +Got no Padding Error for guess 0x89 |
| 35 | +Got intermediate byte #16: 88 |
| 36 | +All intermediates for this block: 88 |
| 37 | +Round counter: 1 |
| 38 | +Got no Padding Error for guess 0x2c |
| 39 | +Got intermediate byte #15: 2e |
| 40 | +All intermediates for this block: 882e |
| 41 | +Round counter: 2 |
| 42 | +Got no Padding Error for guess 0x74 |
| 43 | +Got intermediate byte #14: 77 |
| 44 | +All intermediates for this block: 882e77 |
| 45 | +Round counter: 3 |
| 46 | +Got no Padding Error for guess 0x7f |
| 47 | +Got intermediate byte #13: 7b |
| 48 | +All intermediates for this block: 882e777b |
| 49 | +Round counter: 4 |
| 50 | +Got no Padding Error for guess 0xb9 |
| 51 | +Got intermediate byte #12: bc |
| 52 | +All intermediates for this block: 882e777bbc |
| 53 | +Round counter: 5 |
| 54 | +Got no Padding Error for guess 0x93 |
| 55 | +Got intermediate byte #11: 95 |
| 56 | +All intermediates for this block: 882e777bbc95 |
| 57 | +Round counter: 6 |
| 58 | +Got no Padding Error for guess 0x4f |
| 59 | +Got intermediate byte #10: 48 |
| 60 | +All intermediates for this block: 882e777bbc9548 |
| 61 | +Round counter: 7 |
| 62 | +Got no Padding Error for guess 0x60 |
| 63 | +Got intermediate byte #9: 68 |
| 64 | +All intermediates for this block: 882e777bbc954868 |
| 65 | +Round counter: 8 |
| 66 | +Got no Padding Error for guess 0x1f |
| 67 | +Got intermediate byte #8: 16 |
| 68 | +All intermediates for this block: 882e777bbc95486816 |
| 69 | +Round counter: 9 |
| 70 | +Got no Padding Error for guess 0xb |
| 71 | +Got intermediate byte #7: 01 |
| 72 | +All intermediates for this block: 882e777bbc9548681601 |
| 73 | +Round counter: 10 |
| 74 | +Got no Padding Error for guess 0xe |
| 75 | +Got intermediate byte #6: 05 |
| 76 | +All intermediates for this block: 882e777bbc954868160105 |
| 77 | +Round counter: 11 |
| 78 | +Got no Padding Error for guess 0x5a |
| 79 | +Got intermediate byte #5: 56 |
| 80 | +All intermediates for this block: 882e777bbc95486816010556 |
| 81 | +Round counter: 12 |
| 82 | +Got no Padding Error for guess 0x6 |
| 83 | +Got intermediate byte #4: 0b |
| 84 | +All intermediates for this block: 882e777bbc954868160105560b |
| 85 | +Round counter: 13 |
| 86 | +Got no Padding Error for guess 0x17 |
| 87 | +Got intermediate byte #3: 19 |
| 88 | +All intermediates for this block: 882e777bbc954868160105560b19 |
| 89 | +Round counter: 14 |
| 90 | +Got no Padding Error for guess 0xa4 |
| 91 | +Got intermediate byte #2: ab |
| 92 | +All intermediates for this block: 882e777bbc954868160105560b19ab |
| 93 | +Round counter: 15 |
| 94 | +Got no Padding Error for guess 0x7e |
| 95 | +Got intermediate byte #1: 6e |
| 96 | +All intermediates for this block: 882e777bbc954868160105560b19ab6e |
| 97 | +Done with this round. Now XORING the intermediate bytes with the Cipher text of the previous ciphertext |
| 98 | +Cipher before in hex : 4eff7c78220e0a1d63439eb7707c2583 |
| 99 | +Recovered plain text: [' ', 'T', 'e', 's', 't', '\x0b', '\x0b', '\x0b', '\x0b', '\x0b', '\x0b', '\x0b', '\x0b', '\x0b', '\x0b', '\x0b'] |
| 100 | +Block counter: 0 |
| 101 | +Processing block #0: 4eff7c78220e0a1d63439eb7707c2583 |
| 102 | +Round counter: 0 |
| 103 | +Got no Padding Error for guess 0xd |
| 104 | +Got intermediate byte #16: 0c |
| 105 | +All intermediates for this block: 0c |
| 106 | +Round counter: 1 |
| 107 | +Got no Padding Error for guess 0x12 |
| 108 | +Got intermediate byte #15: 10 |
| 109 | +All intermediates for this block: 0c10 |
| 110 | +Round counter: 2 |
| 111 | +Got no Padding Error for guess 0x8 |
| 112 | +Got intermediate byte #14: 0b |
| 113 | +All intermediates for this block: 0c100b |
| 114 | +Round counter: 3 |
| 115 | +Got no Padding Error for guess 0x14 |
| 116 | +Got intermediate byte #13: 10 |
| 117 | +All intermediates for this block: 0c100b10 |
| 118 | +Round counter: 4 |
| 119 | +Got no Padding Error for guess 0x40 |
| 120 | +Got intermediate byte #12: 45 |
| 121 | +All intermediates for this block: 0c100b1045 |
| 122 | +Round counter: 5 |
| 123 | +Got no Padding Error for guess 0xa |
| 124 | +Got intermediate byte #11: 0c |
| 125 | +All intermediates for this block: 0c100b10450c |
| 126 | +Round counter: 6 |
| 127 | +Got no Padding Error for guess 0xa |
| 128 | +Got intermediate byte #10: 0d |
| 129 | +All intermediates for this block: 0c100b10450c0d |
| 130 | +Round counter: 7 |
| 131 | +Got no Padding Error for guess 0x1 |
| 132 | +Got intermediate byte #9: 09 |
| 133 | +All intermediates for this block: 0c100b10450c0d09 |
| 134 | +Round counter: 8 |
| 135 | +Got no Padding Error for guess 0x5c |
| 136 | +Got intermediate byte #8: 55 |
| 137 | +All intermediates for this block: 0c100b10450c0d0955 |
| 138 | +Round counter: 9 |
| 139 | +Got no Padding Error for guess 0x11 |
| 140 | +Got intermediate byte #7: 1b |
| 141 | +All intermediates for this block: 0c100b10450c0d09551b |
| 142 | +Round counter: 10 |
| 143 | +Got no Padding Error for guess 0x10 |
| 144 | +Got intermediate byte #6: 1b |
| 145 | +All intermediates for this block: 0c100b10450c0d09551b1b |
| 146 | +Round counter: 11 |
| 147 | +Got no Padding Error for guess 0x16 |
| 148 | +Got intermediate byte #5: 1a |
| 149 | +All intermediates for this block: 0c100b10450c0d09551b1b1a |
| 150 | +Round counter: 12 |
| 151 | +Got no Padding Error for guess 0x5e |
| 152 | +Got intermediate byte #4: 53 |
| 153 | +All intermediates for this block: 0c100b10450c0d09551b1b1a53 |
| 154 | +Round counter: 13 |
| 155 | +Got no Padding Error for guess 0x2 |
| 156 | +Got intermediate byte #3: 0c |
| 157 | +All intermediates for this block: 0c100b10450c0d09551b1b1a530c |
| 158 | +Round counter: 14 |
| 159 | +Got no Padding Error for guess 0xe |
| 160 | +Got intermediate byte #2: 01 |
| 161 | +All intermediates for this block: 0c100b10450c0d09551b1b1a530c01 |
| 162 | +Round counter: 15 |
| 163 | +Got no Padding Error for guess 0x20 |
| 164 | +Got intermediate byte #1: 30 |
| 165 | +All intermediates for this block: 0c100b10450c0d09551b1b1a530c0130 |
| 166 | +Done with this round. Now XORING the intermediate bytes with the Cipher text of the previous ciphertext |
| 167 | +Cipher before in hex : 7468697373686f756c646265726e646d |
| 168 | +Recovered plain text: ['D', 'i', 'e', ' ', 'i', 's', 't', ' ', 'e', 'i', 'n', ' ', 'b', 'e', 't', 'a'] |
| 169 | +Done |
| 170 | +Decrypted message: Die ist ein beta Test |
| 171 | +</pre> |
| 172 | + |
| 173 | +# Resources |
| 174 | + - https://en.wikipedia.org/wiki/Padding_oracle_attack |
| 175 | + |
0 commit comments