-
Notifications
You must be signed in to change notification settings - Fork 21
Encrypted Strings
Joshua Roskos edited this page Apr 12, 2018
·
5 revisions
Check out this quick video demo of how to generate EncryptedStrings in Python...
Python - GenerateEncryptedStrings Function
# Use GenerateEncryptedString() locally - DO NOT include in the script!
# The 'Encrypted String' will become a parameter for the script in the JSS
# The unique 'Salt' and 'Passphrase' values will be present in your script
import subprocess
def GenerateEncryptedString(inputString):
'''Usage >>> GenerateEncryptedString("String")'''
salt = subprocess.check_output(['/usr/bin/openssl', 'rand', '-hex', '8']).rstrip()
passphrase = subprocess.check_output(['/usr/bin/openssl', 'rand', '-hex', '12']).rstrip()
p = subprocess.Popen(['/usr/bin/openssl', 'enc', '-aes256', '-a', '-A', '-S', salt, '-k', passphrase], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
encrypted = p.communicate(inputString)[0]
print("Encrypted String: %s" % encrypted)
print("Salt: %s | Passphrase: %s" % (salt, passphrase))
Python - DecryptEncryptedStrings Function (for testing)
# Include DecryptString() with your script to decrypt the password sent by the JSS
# The 'Salt' and 'Passphrase' values would be present in the script
import subprocess
def DecryptString(inputString, salt, passphrase):
'''Usage: >>> DecryptString("Encrypted String", "Salt", "Passphrase")'''
p = subprocess.Popen(['/usr/bin/openssl', 'enc', '-aes256', '-d', '-a', '-A', '-S', salt, '-k', passphrase], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
return p.communicate(inputString)[0]
- Launch Terminal
- Run
python - Copy the Python - GenerateEncryptedStrings Function code block above and paste into the Python repel and press Return twice
- Run
GenerateEncryptedString('yourPasswordHere') - This will return an output similar to:
>>> GenerateEncryptedString('j@mf1234')
Encrypted String: U2FsdGVkX1+T4I++G9edk/JPfsvaf7X94fi1+I44bZQ=
Salt: 93e08fbe1bd79d93 | Passphrase: 789e6b9f2a1901cb49765b03
- Copy the Encrypted String value to your MakeMeAdmin - Remove Admin Rights policy and paste the value in Parameter 4 of your scripts payload
- Copy the Salt value and use to replace the contents of the salt variable in the removeTempAdmin.py script
- Copy the Passphrase value and use to replace the contents of the passphrase variable in the removeTempAdmin.py script
- Launch Terminal
- Run
python - Copy the Python - DecryptEncryptedStrings Function (for testing) code block above and paste into the Python repel and press Return twice
- Run
DecryptString('yourEncryptedString', 'yourSalt', 'yourPassphrase') - This will return an output similar to:
>>> DecryptString('U2FsdGVkX1+T4I++G9edk/JPfsvaf7X94fi1+I44bZQ=', '93e08fbe1bd79d93', '789e6b9f2a1901cb49765b03')
'j@mf1234'
- The output should match your expected password and yes the single-quotes around it are normal and will not effect the script.
Enjoy!