Last active
September 22, 2024 20:54
-
-
Save le4ker/2eceadbd3f64bf62d252f720bbb226d3 to your computer and use it in GitHub Desktop.
Revisions
-
le4ker revised this gist
Oct 22, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,4 +44,4 @@ def decrypt(ciphertext) new_plaintext = unauthenticatedEncryption.decrypt(intercepted_ciphertext) puts new_plaintext # admin=1 -
le4ker revised this gist
Oct 22, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # Demonstration of CBC Bit Flipping Attack # # Author: Panos Sakkos <[email protected]> # # Date: October 2017 # # License: MIT # # # # # # # # # # # # # # # # # # # # # # # # # # # -
le4ker created this gist
Oct 22, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ # # # # # # # # # # # # # # # # # # # # # # # # # # # Demonstration of CBC Bit Flipping Attack # # Author: Panos Sakkos <[email protected]> # # Date: May 2017 # # License: MIT # # # # # # # # # # # # # # # # # # # # # # # # # # # require 'openssl' class UnauthenticatedEncryption def encrypt(plaintext) cipher = OpenSSL::Cipher::AES.new(256, :CBC) cipher.encrypt @key = cipher.random_key iv = cipher.random_iv ciphertext = cipher.update(plaintext) + cipher.final return iv + ciphertext end def decrypt(ciphertext) decipher = OpenSSL::Cipher::AES.new(256, :CBC) decipher.decrypt decipher.key = @key decipher.iv = ciphertext[0..15] plaintext = decipher.update(ciphertext[16..(ciphertext.length - 1)]) + decipher.final return plaintext end end plaintext = 'admin=0' unauthenticatedEncryption = UnauthenticatedEncryption.new() intercepted_ciphertext = unauthenticatedEncryption.encrypt(plaintext) intercepted_ciphertext[6] = (intercepted_ciphertext.bytes[6] ^ 0x01).chr new_plaintext = unauthenticatedEncryption.decrypt(intercepted_ciphertext) puts new_plaintext # admin=0