示例#1
0
    def test_delete_simple(self):
        username = "******"
        password = "******"
        comment = "Created by MiniPyWin32Cred test suite"

        target = "{0}@{1}".format(username, password)

        r_credentials = {
            "Type": CRED_TYPE_GENERIC,
            "TargetName": target,
            "UserName": username,
            "CredentialBlob": password,
            "Comment": comment,
            "Persist": CRED_PERSIST_ENTERPRISE}
        CredWrite(r_credentials, 0)

        credentials = win32cred.CredRead(target, CRED_TYPE_GENERIC)
        self.assertTrue(credentials is not None)

        CredDelete(target, CRED_TYPE_GENERIC)

        with self.assertRaises(error) as ctx:
            CredRead(target, CRED_TYPE_GENERIC)
        self.assertEqual(ctx.exception.winerror, ERROR_NOT_FOUND)
        self.assertEqual(ctx.exception.funcname, "CredRead")
示例#2
0
    def test_write_simple(self):
        username = u"john"
        password = u"doefsajfsakfj"
        comment = u"Created by MiniPyWin32Cred test suite"

        target = "{0}@{1}".format(username, password)

        credentials = {"Type": CRED_TYPE_GENERIC,
                       "TargetName": target,
                       "UserName": username,
                       "CredentialBlob": password,
                       "Comment": comment,
                       "Persist": CRED_PERSIST_ENTERPRISE}

        CredWrite(credentials)

        res = win32cred.CredRead(
            TargetName=target, Type=CRED_TYPE_GENERIC)

        self.assertEqual(res["Type"], CRED_TYPE_GENERIC)
        self.assertEqual(res["UserName"], username)
        self.assertEqual(res["TargetName"], target)
        self.assertEqual(res["Comment"], comment)
        self.assertEqual(
            res["CredentialBlob"].decode('utf-16'), password)
示例#3
0
 def _vault_retrieve(service, ident):
     target = '%(ident)s@%(service)s' % vars()
     try:
         res = win32cred.CredRead(Type=win32cred.CRED_TYPE_GENERIC,
                                  TargetName=target)
     except pywintypes.error as e:
         if e.winerror == 1168 and e.funcname == 'CredRead':
             return None
         raise
     return res['CredentialBlob'].decode('utf-16')
示例#4
0
 def _get_password(self, target):
     try:
         res = win32cred.CredRead(
             Type=win32cred.CRED_TYPE_GENERIC,
             TargetName=target,
         )
     except pywintypes.error as e:
         e = OldPywinError.wrap(e)
         if e.winerror == 1168 and e.funcname == 'CredRead': # not found
             return None
         raise
     return res
示例#5
0
文件: Windows.py 项目: LLNL/GRAPE
 def _get_password(self, target):
     try:
         res = win32cred.CredRead(
             Type=win32cred.CRED_TYPE_GENERIC,
             TargetName=target,
         )
     except pywintypes.error:
         e = sys.exc_info()[1]
         if e.winerror == 1168 and e.funcname == 'CredRead': # not found
             return None
         raise
     return res
示例#6
0
def csv_download():

    # retrieves the user domain, username and password from windows credential manager
    username = "******".format(os.environ.get('USERDOMAIN'),
                               os.environ.get('USERNAME'))
    credential = win32cred.CredRead('TERMSRV/PDCPTMSDB',
                                    win32cred.CRED_TYPE_GENERIC, 0)
    password = credential.get('CredentialBlob').decode('utf-16')
    # using repr(object) we can see there is a null character ('\x00') at the end of password. use str.replace to remove
    password = password.replace('\x00', '')

    # option below to add parameters to report URL if required, make sure to update the 'response' variable if doing so
    # url = base_url + '?/Report&Date=' + current_date + '&rs:Format=csv'

    # open a session using Ntlm authorisation and save to specified path
    session = Session()
    session.auth = HttpNtlmAuth(username=username, password=password)
    response = session.get(base_url, verify=False)
    with open('{}\\KeyImport-{}.csv'.format(report_path, current_date),
              'wb') as fout:
        fout.write(response.content)
    session.close()
示例#7
0
    'Value': 'character data'
}]
cred = {
    'Comment': 'Created by win32cred_demo.py',
    'UserName': target,
    'TargetAlias': None,
    'TargetName': target,
    'CredentialBlob': pwd,
    'Flags': win32cred.CRED_FLAGS_USERNAME_TARGET,
    'Persist': win32cred.CRED_PERSIST_ENTERPRISE,
    'Type': win32cred.CRED_TYPE_DOMAIN_PASSWORD,
    'Attributes': attrs
}
win32cred.CredWrite(cred)
pwd = None
print win32cred.CredRead(target, win32cred.CRED_TYPE_DOMAIN_PASSWORD)

## Marshal saved credential and use it to log on
mc = win32cred.CredMarshalCredential(win32cred.UsernameTargetCredential,
                                     target)
th = win32security.LogonUser(mc, None, '', win32con.LOGON32_LOGON_INTERACTIVE,
                             win32con.LOGON32_PROVIDER_DEFAULT)
win32security.ImpersonateLoggedOnUser(th)
print 'GetUserName:'******'s profile.  (first check if user has a roaming profile)
username, domain = win32cred.CredUIParseUserName(target)
user_info_4 = win32net.NetUserGetInfo(None, username, 4)
profilepath = user_info_4['profile']
## LoadUserProfile apparently doesn't like an empty string