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

[Feature Request] Support Kerberos Authentication #22

Closed
qichaozhao opened this issue Feb 7, 2018 · 12 comments
Closed

[Feature Request] Support Kerberos Authentication #22

qichaozhao opened this issue Feb 7, 2018 · 12 comments

Comments

@qichaozhao
Copy link
Contributor

Hi genotrance,

Firstly thanks for building this awesome tool.

At my corp offices it seems by default Kerberos authentication is used and NTLM does not work for authenticating through the corporate proxy, is there any possibility you could work at adding authentication via using a Kerberos ticket cache?

I am happy to contribute if you can give me some guidance as to what needs to be done - I am familiar with Python but have no idea how these authentication mechanisms work.

@genotrance
Copy link
Owner

Hello @qichaozhao, Px uses winkerberos behind the scenes which should support your scenario. However, I have no way to try it out since I don't have such a setup.

For starters, it would help to know if Px works as is for you. If it doesn't, please share the logs so that I can tell where exactly it is failing. You can run it with the --debug flag which will generate the logs.

@qichaozhao
Copy link
Contributor Author

hey @genotrance, I have been messing about with this and looking at logs and it appears that winkerberos doesn't seem to support the microsoft implementation of kerberos (or at least, I couldn't get it working). Despite having valid kerberos tickets and passing GSSAPI auth method I still kept getting 407's.

I hacked something together which works for my purposes using Go instead so please feel free to close this issue out.

@genotrance
Copy link
Owner

Thanks for the feedback.

@behackett if you had any ideas here, will be appreciated. If you have a test script for winkerberos that can be tested outside the proxy scenario, will be great.

@qichaozhao
Copy link
Contributor Author

If it helps, here is my hacked auth generator class:

class NtlmMessageGenerator:
    def __init__(self):
        # if "winkerberos" in sys.modules:
        status, self.ctx = winkerberos.authGSSClientInit("my.proxy.com")
        self.get_response = self.get_response_wkb

    def get_response_wkb(self, challenge=""):
        dprint("winkerberos SSPI")
        status = winkerberos.authGSSClientStep(self.ctx, '')
        auth_req = winkerberos.authGSSClientResponse(self.ctx)
        print(auth_req)

        return auth_req

and my hacked do_transaction code:

    def do_transaction(self):
        dprint("Entering")

        ipport = self.get_destination()
        if ipport != None:
            dprint("Skipping NTLM proxying")
            resp, headers, body = self.do_socket(destination=ipport)
        else:
            # Check for NTLM auth
            ntlm = NtlmMessageGenerator()
            ntlm_resp = ntlm.get_response()
            # if ntlm_resp == None:
            #     dprint("Bad NTLM response")
            #     return 503, None, None
            resp, headers, body = self.do_socket({
                "Proxy-Authorization": "Negotiate %s" % ntlm_resp
            })
            if resp == 407:
                dprint("Auth required")
                ntlm_challenge = ""
                for header in headers:
                    if header[0] == "Proxy-Authenticate" and "Negotiate" in header[1]:
                        print(header)
                        # ntlm_challenge = header[1].split()[1]
                        ntlm_challenge = True
                        break

                if ntlm_challenge:
                    dprint("Challenged")
                    ntlm_resp = ntlm.get_response(ntlm_challenge)
                    # if ntlm_resp == None:
                    #     dprint("Bad NTLM response")
                    #     return 503, None, None
                    resp, headers, body = self.do_socket({
                        "Proxy-Authorization": "Negotiate %s" % ntlm_resp
                    })

                    return resp, headers, body
                else:
                    dprint("Didn't get challenge, not NTLM proxy")
            elif resp > 400:
                return resp, None, None
            else:
                dprint("No auth required")

        return resp, headers, body

Debug logs are as follows:

Serving at 127.0.0.1:3129 proc MainProcess
Serving at 127.0.0.1:3129 proc Process-1
MainProcess: MainThread: 1519266579: verify_request: Client address: 127.0.0.1
MainProcess: Thread_0: 1519266579: do_GET: Entering
MainProcess: Thread_0: 1519266579: do_transaction: Entering
MainProcess: Thread_0: 1519266579: get_response_wkb: winkerberos SSPI
YIIKLgYJKoZIhvcSAQICAQBuggodMIIKGaADAgEFoQMCAQ6iBwMFACAAAACjgggnYYIIIzCCCB+gAwIBBaESGxBBUEFDLkNPUlBESVIuTkVUojQwMqADAgECoSswKRsESFRUUBshU0NEQ0EwMDAwMzAxLmNuLnN2Yy5jb3JwaW50cmEubmV0o4IHzDCCB8igAwIBEqEDAgEDooIHugSCB7ZjunJqI7P5WiF9VNH9+nbyPheeYckXqjswyZ6aFdQc/sZiM/kzHtF5M4tU+V5rhv/lDJbqs5yl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qJieOXxkxy5ayS1s3NsWMqgcKwL5Y7XIzXkopZf0PLtGfWUFaumwWchLm9I3ZBzpWOfiAP/bDvdIOWVyHIRmDPZAuVFIxOLRUf3PuD/0o2q414zNXL2+uOUB/LBNQwc4D0X0YJOknTL+kMhsJvubaRALGhapzQK6zndSak3IqsR8zt0EJvbDIwhHcn1Nr3Hn3Fy0hSJKTJ7oLimF3G81IPfT+cH7ZTh0x8G1f8CGXw6+YtymrF2HsA4BF/DOgZ9L+59qk793Q/93Up0aOonUoHjGUltvU0YQgI8VpK3iOus+VZr5q2/2DMoz5JtxaZcFceoNHrVY1DRVeIQ3+S6lAW2E50JtP9DFsucHW2h72HdEyq9l9rBTQBe52RGloMoakggHXMIIB06ADAgESooIBygSCAcY8ySBby5/7CGolbTe//1+84sdQfMBSENrRQXmU0KE5SSrTNnbVIGyPELxU16qOeUsNbCgIq7AqYVssQMit5fWrbkFxBg/wtcA4tgcNuUwr39iTYKm2+2zo+vJJMf0pgWcOA0Amo32XUpqazPSZGmf3TVu4PEX8HXIftgi3OHSDMh9OZvOGEks5wBru7zo2nnRIaHykX4RbnDvLS5H1TjHWrJtqXylJhSnEUm++Zz/3CCAqOqjBQgTof3Zm08hZtpwX3rEnlgEBrjT7SRgibUrmNj4hRSyKOPZBJIK2AbXliln0WpZ6ScdEfpqkk4Dz50HuSk0TRJfnGICzB4/f2aXhe66CkbLRCb2FPFcCpqjrY1a5Lvlr0mHkdFWklLfNQyL2V/k5ggXEQ8lZZoc2DNF+FkL5iGZ+OUlxn1ee5SvnmlbHrdds8tYwHWyOgadjSlXFoios07zpbIU4fe2Q6LWhjBvcyuYz1e2H+VJT5mX9F2rQ6vRhQKXA2YCCmnJ0w9EhaccFmCl68FNvaW3w+4PbHR2gP+fyCekrVVSQyGh9hJ/bdO0jaRJIPLdCUafd8e/IuBSC9uus07nLfCSepXinOql9lOFM
MainProcess: Thread_0: 1519266579: do_socket: Entering
MainProcess: Thread_0: 1519266579: do_socket: New connection
MainProcess: Thread_0: 1519266579: do_socket: b'GET http://www.baidu.com/ HTTP/1.1\r\n'
MainProcess: Thread_0: 1519266579: do_socket: Sending b'Host: www.baidu.com\r\n'
MainProcess: Thread_0: 1519266579: do_socket: Sending b'User-Agent: curl/7.56.1\r\n'
MainProcess: Thread_0: 1519266579: do_socket: Sending b'Accept: */*\r\n'
MainProcess: Thread_0: 1519266579: do_socket: Sending b'Proxy-Connection: Keep-Alive\r\n'
MainProcess: Thread_0: 1519266579: do_socket: Sending extra b'Proxy-Authorization: Negotiate YIIKLgYJKoZIhvcSAQICAQBuggodMIIKGaADAgEFoQMCAQ6iBwMFACAAAACjgggnYYIIIzCCCB+gAwIBBaESGxBBUEFDLkNPUlBESVIuTkVUojQwMqADAgECoSswKRsESFRUUBshU0NEQ0EwMDAwMzAxLmNuLnN2Yy5jb3JwaW50cmEubmV0o4IHzDCCB8igAwIBEqEDAgEDooIHugSCB7ZjunJqI7P5WiF9VNH9+nbyPheeYckXqjswyZ6aFdQc/sZiM/kzHtF5M4tU+V5rhv/lDJbqs5ylGbtWej7MyFep+XqWgZWI251/3VfIkthxr1Rz7IAkrz4aZwxwHQZf+khDn9kHszYSYvKeEwSN0uSKGKmDTFEWnYxGooMKBxzV7TngqO9mnelX+9bM6SZ2IJtCNACjAMaD4g8kCLpCM8hnJxiIcUAelnGE0TkyQxU4qt7zCm7POkgRitCjPjPucviJCe5ggswkN0nU/joorrLBesze6SHQLrbbw0vCm7j1nG/lUIpD2DnguGb2yBCFGUc2+8aVi5upmkqPi9I3NyYJidM6mR8OxyHZIS1a4swC1pumdGe0U85tWqGjTfz7JTELBPu36w5p3D4cXEEuuy8SUnN/f98eyhk6KgMfGEyWnKhr6ZeqRmPX/bv4SwN1oTTEWIo2ONm7sMRCt3JXS1PlIDeotUh9OWTQFpmAI5aiY15ZwW314TbyZbKBeXeSYLnnqi8Rf4wnc05HahER2qgSa2miQBQNJXg28hxiULnxYwZIj+F0ecd1mzdXc3ayPExPqiEr0p9Xl0nk5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wr39iTYKm2+2zo+vJJMf0pgWcOA0Amo32XUpqazPSZGmf3TVu4PEX8HXIftgi3OHSDMh9OZvOGEks5wBru7zo2nnRIaHykX4RbnDvLS5H1TjHWrJtqXylJhSnEUm++Zz/3CCAqOqjBQgTof3Zm08hZtpwX3rEnlgEBrjT7SRgibUrmNj4hRSyKOPZBJIK2AbXliln0WpZ6ScdEfpqkk4Dz50HuSk0TRJfnGICzB4/f2aXhe66CkbLRCb2FPFcCpqjrY1a5Lvlr0mHkdFWklLfNQyL2V/k5ggXEQ8lZZoc2DNF+FkL5iGZ+OUlxn1ee5SvnmlbHrdds8tYwHWyOgadjSlXFoios07zpbIU4fe2Q6LWhjBvcyuYz1e2H+VJT5mX9F2rQ6vRhQKXA2YCCmnJ0w9EhaccFmCl68FNvaW3w+4PbHR2gP+fyCekrVVSQyGh9hJ/bdO0jaRJIPLdCUafd8e/IuBSC9uus07nLfCSepXinOql9lOFM\r\n'
MainProcess: Thread_0: 1519266579: do_socket: Reading response code
MainProcess: Thread_0: 1519266579: do_socket: Response code: 407 False
MainProcess: Thread_0: 1519266579: do_socket: Reading response headers
MainProcess: Thread_0: 1519266579: do_socket: Received header Mime-Version = 1.0
MainProcess: Thread_0: 1519266579: do_socket: Received header Date = Thu, 22 Feb 2018 10:29:39 CST
MainProcess: Thread_0: 1519266579: do_socket: Received header Content-Type = text/html
MainProcess: Thread_0: 1519266579: do_socket: Received header Proxy-Authenticate = Negotiate
MainProcess: Thread_0: 1519266579: do_socket: Received header Connection = close
MainProcess: Thread_0: 1519266579: do_socket: Received header Proxy-Connection = close
MainProcess: Thread_0: 1519266579: do_socket: Received header Content-Length = 2073
MainProcess: Thread_0: 1519266579: do_socket: Reading response data
MainProcess: Thread_0: 1519266579: do_socket: Content length 2073
MainProcess: Thread_0: 1519266579: do_transaction: Auth required
('Proxy-Authenticate', 'Negotiate')
MainProcess: Thread_0: 1519266579: do_transaction: Challenged
MainProcess: Thread_0: 1519266579: get_response_wkb: winkerberos SSPI
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 63744)
Traceback (most recent call last):
  File "C:\anaconda3\lib\socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\anaconda3\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\anaconda3\lib\socketserver.py", line 696, in __init__
    self.handle()
  File "C:\anaconda3\lib\http\server.py", line 418, in handle
    self.handle_one_request()
  File "px.py", line 160, in handle_one_request
    httpserver.SimpleHTTPRequestHandler.handle_one_request(self)
  File "C:\anaconda3\lib\http\server.py", line 406, in handle_one_request
    method()
  File "px.py", line 388, in do_GET
    resp, headers, body = self.do_transaction()
  File "px.py", line 360, in do_transaction
    ntlm_resp = ntlm.get_response(ntlm_challenge)
  File "px.py", line 148, in get_response_wkb
    status = winkerberos.authGSSClientStep(self.ctx, '')
winkerberos.GSSError: SSPI: InitializeSecurityContext: The token supplied to the function is invalid

----------------------------------------

It's weird because it picks up the Kerberos ticket that I have active from my Windows Active Directory sign in but doesn't seem to generate the correct auth token that allows it to negotiate successfully with the proxy.

Also as mentioned before since I have another working solution (https://github.com/qichaozhao/win-auth-proxy for anyone who stumbles upon this), this bugfix/enhancement is not a priority and more of a curiosity for me as to why it's not working as expected. :)

@behackett
Copy link

I wrote WinKerberos specifically for Kerberos. I don't have an NTLM environment to test it any other way, and it's not clear to me how NTLM is supposed to work. One thing to try is passing mech_oid=winkerberos.GSS_MECH_OID_SPNEGO to authGSSClientInit. The default is winkerberos.GSS_MECH_OID_KRB5.

@behackett
Copy link

I think the error is SEC_E_INVALID_TOKEN, which is documented here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa375507(v=vs.85).aspx

The error is due to a malformed input token, such as a token corrupted in transit, a token of incorrect size, or a token passed into the wrong security package. Passing a token to the wrong package can happen if the client and server did not negotiate the proper security package.

My previous recommendation stands, use GSS_MECH_OID_SPNEGO.

@genotrance
Copy link
Owner

@qichaozhao, I think you have mostly this figured out - Px is hard-coded to talk only NTLM so changing NTLM in the Proxy-Authorization and Proxy-Authenticate as you have to Negotiate will make it generic. I just tried this with my NTLM proxy and it worked.

Can you try the same with mech_oid=winkerberos.GSS_MECH_OID_SPNEGO which you have removed in your code?

@qichaozhao
Copy link
Contributor Author

qichaozhao commented Feb 22, 2018

@behackett, @genotrance, thank you! It turns out that that the GSS_MECH_OID_SPNEGO flag was what was needed.

Are you accepting PRs? I would be happy to tidy up my code and submit one to enable Negotiate style authentication for this proxy tool, perhaps through the use of an extra config line in the .ini file?

@genotrance
Copy link
Owner

Thanks for all the work @qichaozhao. I've posted an updated version of Px which should work for you. Please verify that it works for you now. I've set the auth method to Negotiate throughout and it works for NTLM as well. I didn't have to add any extra config params either so hopefully it works across the board for everyone.

I did have to remove support for pywin32 sspi since it wasn't working for Kerberos mode with my proxy. As such, there's no real value supporting both mechanisms and considering winkerberos works for both scenarios and for Python 3.4+, it makes more sense anyway.

@qichaozhao
Copy link
Contributor Author

qichaozhao commented Feb 26, 2018

@genotrance , unfortunately this doesn't quite work - this is because of the authGSSClientInit step.

For Kerberos authentication the target URL needs to be: HTTP@<server>, but I don't know if hardcoding this will allow it to continue working for NTLM. Perhaps you can test?

The below change allows this to work for me.

status, self.ctx = winkerberos.authGSSClientInit('HTTP@' + State.proxy_server[0][0], gssflags=0, mech_oid=winkerberos.GSS_MECH_OID_SPNEGO)

@genotrance
Copy link
Owner

It works with HTTP@ so I'll check this in shortly. Thanks for verifying.

@qichaozhao
Copy link
Contributor Author

cool, cheers @genotrance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants