Python win32security.LogonUser() Examples

The following are 13 code examples of win32security.LogonUser(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32security , or try the search function .
Example #1
Source File: authorizers.py    From oss-ftp with MIT License 8 votes vote down vote up
def impersonate_user(self, username, password):
            """Impersonate the security context of another user."""
            handler = win32security.LogonUser(
                username, None, password,
                win32con.LOGON32_LOGON_INTERACTIVE,
                win32con.LOGON32_PROVIDER_DEFAULT)
            win32security.ImpersonateLoggedOnUser(handler)
            handler.Close() 
Example #2
Source File: _windows.py    From django-ftpserver with MIT License 8 votes vote down vote up
def impersonate_user(self, username, password):
            """impersonate user when operating file system
            """
            handler = win32security.LogonUser(
                username, None, password,
                win32con.LOGON32_LOGON_INTERACTIVE,
                win32con.LOGON32_PROVIDER_DEFAULT)
            win32security.ImpersonateLoggedOnUser(handler)
            handler.Close() 
Example #3
Source File: authorizers.py    From script-languages with MIT License 8 votes vote down vote up
def validate_authentication(self, username, password, handler):
            if username == "anonymous":
                if self.anonymous_user is None:
                    raise AuthenticationFailed(self.msg_anon_not_allowed)
                return
            try:
                win32security.LogonUser(username, None, password,
                                        win32con.LOGON32_LOGON_INTERACTIVE,
                                        win32con.LOGON32_PROVIDER_DEFAULT)
            except pywintypes.error:
                raise AuthenticationFailed(self.msg_wrong_password) 
Example #4
Source File: authorizers.py    From script-languages with MIT License 8 votes vote down vote up
def impersonate_user(self, username, password):
            """Impersonate the security context of another user."""
            handler = win32security.LogonUser(
                username, None, password,
                win32con.LOGON32_LOGON_INTERACTIVE,
                win32con.LOGON32_PROVIDER_DEFAULT)
            win32security.ImpersonateLoggedOnUser(handler)
            handler.Close() 
Example #5
Source File: authorizers.py    From pyftpdlib with MIT License 5 votes vote down vote up
def validate_authentication(self, username, password, handler):
            if username == "anonymous":
                if self.anonymous_user is None:
                    raise AuthenticationFailed(self.msg_anon_not_allowed)
                return
            try:
                win32security.LogonUser(username, None, password,
                                        win32con.LOGON32_LOGON_INTERACTIVE,
                                        win32con.LOGON32_PROVIDER_DEFAULT)
            except pywintypes.error:
                raise AuthenticationFailed(self.msg_wrong_password) 
Example #6
Source File: authorizers.py    From pyftpdlib with MIT License 5 votes vote down vote up
def impersonate_user(self, username, password):
            """Impersonate the security context of another user."""
            handler = win32security.LogonUser(
                username, None, password,
                win32con.LOGON32_LOGON_INTERACTIVE,
                win32con.LOGON32_PROVIDER_DEFAULT)
            win32security.ImpersonateLoggedOnUser(handler)
            handler.Close() 
Example #7
Source File: login_functions.py    From flicket with MIT License 5 votes vote down vote up
def nt_log_on(domain, username, password):
    """

    This feature is experimental for windows hosts that want to authenticate on the
    local machines domain running this application.

    # todo: This will eventually be changed to use ldap but I don't currently have a means to test this.
    :param domain:
    :param username:
    :param password:
    :return:
    """

    valid_os = False
    authenticated = False

    if os.name == 'nt':
        try:
            import pywintypes
            import win32security
            valid_os = True
        except ModuleNotFoundError:
            raise ModuleNotFoundError('Is pywin32 installed?')

    if valid_os:

        try:
            token = win32security.LogonUser(
                username,
                domain,
                password,
                win32security.LOGON32_LOGON_NETWORK,
                win32security.LOGON32_PROVIDER_DEFAULT)
            authenticated = bool(token)
        except pywintypes.error:
            pass

    return authenticated 
Example #8
Source File: winprocess.py    From ironpython2 with Apache License 2.0 4 votes vote down vote up
def logonUser(loginString):
    """
    Login as specified user and return handle.
    loginString:  'Domain\nUser\nPassword'; for local
        login use . or empty string as domain
        e.g. '.\nadministrator\nsecret_password'
    """
    domain, user, passwd = loginString.split('\n')
    return win32security.LogonUser(
        user,
        domain,
        passwd,
        win32con.LOGON32_LOGON_INTERACTIVE,
        win32con.LOGON32_PROVIDER_DEFAULT
        ) 
Example #9
Source File: authorizers.py    From oss-ftp with MIT License 2 votes vote down vote up
def validate_authentication(self, username, password, handler):
            if username == "anonymous":
                if self.anonymous_user is None:
                    raise AuthenticationFailed(self.msg_anon_not_allowed)
                return
            try:
                win32security.LogonUser(username, None, password,
                                        win32con.LOGON32_LOGON_INTERACTIVE,
                                        win32con.LOGON32_PROVIDER_DEFAULT)
            except pywintypes.error:
                raise AuthenticationFailed(self.msg_wrong_password) 
Example #10
Source File: authorizers.py    From oss-ftp with MIT License 2 votes vote down vote up
def impersonate_user(self, username, password):
            """Impersonate the security context of another user."""
            handler = win32security.LogonUser(
                username, None, password,
                win32con.LOGON32_LOGON_INTERACTIVE,
                win32con.LOGON32_PROVIDER_DEFAULT)
            win32security.ImpersonateLoggedOnUser(handler)
            handler.Close() 
Example #11
Source File: authorizers.py    From oss-ftp with MIT License 2 votes vote down vote up
def validate_authentication(self, username, password, handler):
            if username == "anonymous":
                if self.anonymous_user is None:
                    raise AuthenticationFailed(self.msg_anon_not_allowed)
                return
            try:
                win32security.LogonUser(username, None, password,
                                        win32con.LOGON32_LOGON_INTERACTIVE,
                                        win32con.LOGON32_PROVIDER_DEFAULT)
            except pywintypes.error:
                raise AuthenticationFailed(self.msg_wrong_password) 
Example #12
Source File: windows-privesc-check.py    From WHP with Do What The F*ck You Want To Public License 2 votes vote down vote up
def impersonate(username, password, domain):
	if username:
		print "Using alternative credentials:"
		print "Username: " + str(username)
		print "Password: " + str(password)
		print "Domain:   " + str(domain)
		handle = win32security.LogonUser( username, domain, password, win32security.LOGON32_LOGON_NEW_CREDENTIALS, win32security.LOGON32_PROVIDER_WINNT50 )
		win32security.ImpersonateLoggedOnUser( handle )
	else:
		print "Running as current user.  No logon creds supplied (-u, -d, -p)."
	print 
Example #13
Source File: windowsprivcheck.py    From LHF with GNU General Public License v3.0 2 votes vote down vote up
def impersonate(username, password, domain):
	if username:
		print "Using alternative credentials:"
		print "Username: " + str(username)
		print "Password: " + str(password)
		print "Domain:   " + str(domain)
		handle = win32security.LogonUser( username, domain, password, win32security.LOGON32_LOGON_NEW_CREDENTIALS, win32security.LOGON32_PROVIDER_WINNT50 )
		win32security.ImpersonateLoggedOnUser( handle )
	else:
		print "Running as current user.  No logon creds supplied (-u, -d, -p)."
	print