def do_import(self, line): if not line: return if line == 'empire': headers = {'Content-Type': 'application/json'} # Pull the username and password from the config file payload = { 'username': self.config.get('Empire', 'username'), 'password': self.config.get('Empire', 'password') } # Pull the host and port from the config file base_url = 'https://{}:{}'.format( self.config.get('Empire', 'api_host'), self.config.get('Empire', 'api_port')) try: r = requests.post(base_url + '/api/admin/login', json=payload, headers=headers, verify=False) if r.status_code == 200: token = r.json()['token'] url_params = {'token': token} r = requests.get(base_url + '/api/creds', headers=headers, params=url_params, verify=False) creds = r.json() for cred in creds['creds']: if cred['credtype'] == 'token' or cred[ 'credtype'] == 'krbtgt' or cred[ 'username'].endswith('$'): continue self.db.add_credential(cred['credtype'], cred['domain'], cred['username'], cred['password']) print "[+] Empire credential import successful" else: print "[-] Error authenticating to Empire's RESTful API server!" except ConnectionError as e: print "[-] Unable to connect to Empire's RESTful API server: {}".format( e) elif line == 'metasploit': msf = Msfrpc({ 'host': self.config.get('Metasploit', 'rpc_host'), 'port': self.config.get('Metasploit', 'rpc_port') }) try: msf.login('msf', self.config.get('Metasploit', 'password')) except MsfAuthError: print "[-] Error authenticating to Metasploit's MSGRPC server!" return console_id = str(msf.call('console.create')['id']) msf.call('console.write', [console_id, 'creds\n']) sleep(2) creds = msf.call('console.read', [console_id]) for entry in creds['data'].split('\n'): cred = entry.split() try: # host = cred[0] # port = cred[2] proto = cred[3] username = cred[4] password = cred[5] cred_type = cred[6] if proto == '({})'.format( self.proto) and cred_type == 'Password': self.db.add_credential('plaintext', '', username, password) except IndexError: continue msf.call('console.destroy', [console_id]) print "[+] Metasploit credential import successful"
def do_import(self, line): if not line: return if line == 'empire': headers = {'Content-Type': 'application/json'} #Pull the username and password from the config file payload = {'username': self.config.get('Empire', 'username'), 'password': self.config.get('Empire', 'password')} #Pull the host and port from the config file base_url = 'https://{}:{}'.format(self.config.get('Empire', 'api_host'), self.config.get('Empire', 'api_port')) try: r = requests.post(base_url + '/api/admin/login', json=payload, headers=headers, verify=False) if r.status_code == 200: token = r.json()['token'] url_params = {'token': token} r = requests.get(base_url + '/api/creds', headers=headers, params=url_params, verify=False) creds = r.json() for cred in creds['creds']: if cred['credtype'] == 'token' or cred['credtype'] == 'krbtgt' or cred['username'].endswith('$'): continue self.db.add_credential(cred['credtype'], cred['domain'], cred['username'], cred['password']) print "[+] Empire credential import successful" else: print "[-] Error authenticating to Empire's RESTful API server!" except ConnectionError as e: print "[-] Unable to connect to Empire's RESTful API server: {}".format(e) elif line == 'metasploit': msf = Msfrpc({'host': self.config.get('Metasploit', 'rpc_host'), 'port': self.config.get('Metasploit', 'rpc_port')}) try: msf.login('msf', self.config.get('Metasploit', 'password')) except MsfAuthError: print "[-] Error authenticating to Metasploit's MSGRPC server!" return console_id = str(msf.call('console.create')['id']) msf.call('console.write', [console_id, 'creds\n']) sleep(2) creds = msf.call('console.read', [console_id]) for entry in creds['data'].split('\n'): cred = entry.split() try: host = cred[0] port = cred[2] proto = cred[3] username = cred[4] password = cred[5] cred_type = cred[6] if proto == '(smb)' and cred_type == 'Password': self.db.add_credential('plaintext', '', username, password) except IndexError: continue msf.call('console.destroy', [console_id]) print "[+] Metasploit credential import successful"