This repository has been archived by the owner on Jan 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support skipping vpc id assignment Documentation: http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.ServiceResource.create_security_group bump version * Support password
- Loading branch information
Showing
5 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# https://github.com/tomrittervg/decrypt-windows-ec2-passwd/blob/master/decrypt-windows-ec2-passwd.py | ||
|
||
import base64 | ||
import binascii | ||
|
||
|
||
def pkcs1_unpad(text): | ||
# From http://kfalck.net/2011/03/07/decoding-pkcs1-padding-in-python | ||
if len(text) > 0 and text[0] == '\x02': | ||
# Find end of padding marked by nul | ||
pos = text.find('\x00') | ||
if pos > 0: | ||
return text[pos + 1:] | ||
return None | ||
|
||
|
||
def long_to_bytes(val, endianness='big'): | ||
# From http://stackoverflow.com/questions/8730927/ | ||
# convert-python-long-int-to-fixed-size-byte-array | ||
|
||
# one (1) hex digit per four (4) bits | ||
try: | ||
# Python < 2.7 doesn't have bit_length =( | ||
width = val.bit_length() | ||
except Exception: | ||
width = len(val.__hex__()[2:-1]) * 4 | ||
|
||
# unhexlify wants an even multiple of eight (8) bits, but we don't | ||
# want more digits than we need (hence the ternary-ish 'or') | ||
width += 8 - ((width % 8) or 8) | ||
|
||
# format width specifier: four (4) bits per hex digit | ||
fmt = '%%0%dx' % (width // 4) | ||
|
||
# prepend zero (0) to the width, to zero-pad the output | ||
s = binascii.unhexlify(fmt % val) | ||
|
||
if endianness == 'little': | ||
# see http://stackoverflow.com/a/931095/309233 | ||
s = s[::-1] | ||
|
||
return s | ||
|
||
|
||
def decrypt_password(rsa_key, password): | ||
# Undo the whatever-they-do to the ciphertext to get the integer | ||
encryptedData = base64.b64decode(password) | ||
ciphertext = int(binascii.hexlify(encryptedData), 16) | ||
|
||
# Decrypt it | ||
plaintext = rsa_key.decrypt(ciphertext) | ||
|
||
# This is the annoying part. long -> byte array | ||
decryptedData = long_to_bytes(plaintext) | ||
# Now Unpad it | ||
unpaddedData = pkcs1_unpad(decryptedData) | ||
|
||
# Done | ||
return unpaddedData |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters