title: Altering the Last Byte of a String
body: <p>I'm working on a Padding Oracle attack and which involves altering an IV and sending it back with a HTML post request. The simple version is that I'm trying to alter the last byte of a string....and I think I might be doing it wrong. First we start out with a Raw IV from the Oracle.</p>
  
  <pre><code>IV = 'NFhS0jOCAR0ymB2MM+3Pfg=='
  </code></pre>
  
  <p>We can't work with that so we do base-64 decoding on it.</p>
  
  <pre><code>IV = base64.b64decode(IV)
  </code></pre>
  
  <p>That turns it into garbage on our screen (4XR�3�2��3��~) but now it's in a form that we can work with. Now we want to find out the last byte of the IV so we say</p>
  
  <pre><code>LastByte = IV[len(IV)-1]
  </code></pre>
  
  <p>Which gives us "~" as the last byte. NOW things get crazy, we want to change the last byte of the IV by XOR'ing it with a number we will call X. </p>
  
  <pre><code>NewByte = ord(LastByte) ^ x
  newIV = IV[:len(IV)-1] + str(NewByte)
  </code></pre>
  
  <p>And then we base64 encode it and move on</p>
  
  <pre><code>newIV = base64.b64encode(newIV)
  </code></pre>
  
  <p>When I check the length of the newIV it's the same length as the original raw IV but I just feel like something isn't right here. Am I messing it up by doing str(NewByte)? I feel like I should be doing this with a bytearray somehow but I don't know enough about using them do it in one. Did I alter the last byte correctly?</p>