Python impacket.smb.SessionError() Examples
The following are 30
code examples of impacket.smb.SessionError().
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
impacket.smb
, or try the search function
.
Example #1
Source File: smbconnection.py From PiBunny with MIT License | 6 votes |
def login(self, user, password, domain = '', lmhash = '', nthash = '', ntlmFallback = True): """ logins into the target system :param string user: username :param string password: password for the user :param string domain: domain where the account is valid for :param string lmhash: LMHASH used to authenticate using hashes (password is not used) :param string nthash: NTHASH used to authenticate using hashes (password is not used) :param bool ntlmFallback: If True it will try NTLMv1 authentication if NTLMv2 fails. Only available for SMBv1 :return: None, raises a Session Error if error. """ self._ntlmFallback = ntlmFallback try: if self.getDialect() == smb.SMB_DIALECT: return self._SMBConnection.login(user, password, domain, lmhash, nthash, ntlmFallback) else: return self._SMBConnection.login(user, password, domain, lmhash, nthash) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #2
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def getFile(self, shareName, pathName, callback, shareAccessMode = None): """ downloads a file :param string shareName: name for the share where the file is to be retrieved :param string pathName: the path name to retrieve :param callback callback: :return: None, raises a SessionError exception if error. """ try: if shareAccessMode is None: # if share access mode is none, let's the underlying API deals with it return self._SMBConnection.retr_file(shareName, pathName, callback) else: return self._SMBConnection.retr_file(shareName, pathName, callback, shareAccessMode=shareAccessMode) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #3
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def queryInfo(self, treeId, fileId): """ queries basic information about an opened file/directory :param HANDLE treeId: a valid handle for the share where the file is to be opened :param HANDLE fileId: a valid handle for the file/directory to be closed :return: a smb.SMBQueryFileBasicInfo structure. raises a SessionError exception if error. """ try: if self.getDialect() == smb.SMB_DIALECT: res = self._SMBConnection.query_file_info(treeId, fileId) else: res = self._SMBConnection.queryInfo(treeId, fileId) return smb.SMBQueryFileStandardInfo(res) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #4
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def readNamedPipe(self,treeId, fileId, bytesToRead = None ): """ read from a named pipe :param HANDLE treeId: a valid handle for the share where the pipe resides :param HANDLE fileId: a valid handle for the pipe :param integer bytesToRead: amount of data to read :return: None, raises a SessionError exception if error. """ try: return self.readFile(treeId, fileId, bytesToRead = bytesToRead, singleCall = True) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #5
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def transactNamedPipe(self, treeId, fileId, data, waitAnswer = True): """ writes to a named pipe using a transaction command :param HANDLE treeId: a valid handle for the share where the pipe is :param HANDLE fileId: a valid handle for the pipe :param string data: buffer with the data to write :param boolean waitAnswer: whether or not to wait for an answer :return: None, raises a SessionError exception if error. """ try: return self._SMBConnection.TransactNamedPipe(treeId, fileId, data, waitAnswer = waitAnswer) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #6
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def writeNamedPipe(self, treeId, fileId, data, waitAnswer = True): """ writes to a named pipe :param HANDLE treeId: a valid handle for the share where the pipe is :param HANDLE fileId: a valid handle for the pipe :param string data: buffer with the data to write :param boolean waitAnswer: whether or not to wait for an answer :return: None, raises a SessionError exception if error. """ try: if self.getDialect() == smb.SMB_DIALECT: return self._SMBConnection.write_andx(treeId, fileId, data, wait_answer = waitAnswer, write_pipe_mode = True) else: return self.writeFile(treeId, fileId, data, 0) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #7
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def putFile(self, shareName, pathName, callback, shareAccessMode = None): """ uploads a file :param string shareName: name for the share where the file is to be uploaded :param string pathName: the path name to upload :param callback callback: :return: None, raises a SessionError exception if error. """ try: if shareAccessMode is None: # if share access mode is none, let's the underlying API deals with it return self._SMBConnection.stor_file(shareName, pathName, callback) else: return self._SMBConnection.stor_file(shareName, pathName, callback, shareAccessMode) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #8
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def rename(self, shareName, oldPath, newPath): """ renames a file/directory :param string shareName: name for the share where the files/directories are :param string oldPath: the old path name or the directory/file to rename :param string newPath: the new path name or the directory/file to rename :return: True, raises a SessionError exception if error. """ try: return self._SMBConnection.rename(shareName, oldPath, newPath) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #9
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def login(self, user, password, domain = '', lmhash = '', nthash = '', ntlmFallback = True): """ logins into the target system :param string user: username :param string password: password for the user :param string domain: domain where the account is valid for :param string lmhash: LMHASH used to authenticate using hashes (password is not used) :param string nthash: NTHASH used to authenticate using hashes (password is not used) :param bool ntlmFallback: If True it will try NTLMv1 authentication if NTLMv2 fails. Only available for SMBv1 :return: None, raises a Session Error if error. """ self._ntlmFallback = ntlmFallback try: if self.getDialect() == smb.SMB_DIALECT: return self._SMBConnection.login(user, password, domain, lmhash, nthash, ntlmFallback) else: return self._SMBConnection.login(user, password, domain, lmhash, nthash) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #10
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def queryInfo(self, treeId, fileId): """ queries basic information about an opened file/directory :param HANDLE treeId: a valid handle for the share where the file is to be opened :param HANDLE fileId: a valid handle for the file/directory to be closed :return: a smb.SMBQueryFileBasicInfo structure. raises a SessionError exception if error. """ try: if self.getDialect() == smb.SMB_DIALECT: res = self._SMBConnection.query_file_info(treeId, fileId) else: res = self._SMBConnection.queryInfo(treeId, fileId) return smb.SMBQueryFileStandardInfo(res) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #11
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def transactNamedPipe(self, treeId, fileId, data, waitAnswer = True): """ writes to a named pipe using a transaction command :param HANDLE treeId: a valid handle for the share where the pipe is :param HANDLE fileId: a valid handle for the pipe :param string data: buffer with the data to write :param boolean waitAnswer: whether or not to wait for an answer :return: None, raises a SessionError exception if error. """ try: return self._SMBConnection.TransactNamedPipe(treeId, fileId, data, waitAnswer = waitAnswer) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #12
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def writeNamedPipe(self, treeId, fileId, data, waitAnswer = True): """ writes to a named pipe :param HANDLE treeId: a valid handle for the share where the pipe is :param HANDLE fileId: a valid handle for the pipe :param string data: buffer with the data to write :param boolean waitAnswer: whether or not to wait for an answer :return: None, raises a SessionError exception if error. """ try: if self.getDialect() == smb.SMB_DIALECT: return self._SMBConnection.write_andx(treeId, fileId, data, wait_answer = waitAnswer, write_pipe_mode = True) else: return self.writeFile(treeId, fileId, data, 0) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #13
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def readNamedPipe(self,treeId, fileId, bytesToRead = None ): """ read from a named pipe :param HANDLE treeId: a valid handle for the share where the pipe resides :param HANDLE fileId: a valid handle for the pipe :param integer bytesToRead: amount of data to read :return: None, raises a SessionError exception if error. """ try: return self.readFile(treeId, fileId, bytesToRead = bytesToRead, singleCall = True) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #14
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def putFile(self, shareName, pathName, callback, shareAccessMode = None): """ uploads a file :param string shareName: name for the share where the file is to be uploaded :param string pathName: the path name to upload :param callback callback: :return: None, raises a SessionError exception if error. """ try: if shareAccessMode is None: # if share access mode is none, let's the underlying API deals with it return self._SMBConnection.stor_file(shareName, pathName, callback) else: return self._SMBConnection.stor_file(shareName, pathName, callback, shareAccessMode) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #15
Source File: smbconnection.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def login(self, user, password, domain = '', lmhash = '', nthash = '', ntlmFallback = True): """ logins into the target system :param string user: username :param string password: password for the user :param string domain: domain where the account is valid for :param string lmhash: LMHASH used to authenticate using hashes (password is not used) :param string nthash: NTHASH used to authenticate using hashes (password is not used) :param bool ntlmFallback: If True it will try NTLMv1 authentication if NTLMv2 fails. Only available for SMBv1 :return: None, raises a Session Error if error. """ self._ntlmFallback = ntlmFallback try: if self.getDialect() == smb.SMB_DIALECT: return self._SMBConnection.login(user, password, domain, lmhash, nthash, ntlmFallback) else: return self._SMBConnection.login(user, password, domain, lmhash, nthash) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code())
Example #16
Source File: K8Cscan.py From K8CScan with MIT License | 6 votes |
def smbcheck(target): if checkPort(target,'445'): conn = MYSMB(target) try: conn.login(USERNAME, PASSWORD) except smb.SessionError as e: #print('Login failed: ' + nt_errors.ERROR_MESSAGES[e.error_code][0]) sys.exit() finally: #print('OS: ' + conn.get_server_os()) TragetOS = '(' + conn.get_server_os()+')' tid = conn.tree_connect_andx('\\\\'+target+'\\'+'IPC$') conn.set_default_tid(tid) # test if target is vulnerable TRANS_PEEK_NMPIPE = 0x23 recvPkt = conn.send_trans(pack('<H', TRANS_PEEK_NMPIPE), maxParameterCount=0xffff, maxDataCount=0x800) status = recvPkt.getNTStatus() if status == 0xC0000205: # STATUS_INSUFF_SERVER_RESOURCES #print('The target is not patched') CheckResult = 'MS17-010\t'+TragetOS return CheckResult
Example #17
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 6 votes |
def reconnect(self): """ reconnects the SMB object based on the original options and credentials used. Only exception is that manualNegotiate will not be honored. Not only the connection will be created but also a login attempt using the original credentials and method (Kerberos, PtH, etc) :return: True, raises a SessionError exception if error """ userName, password, domain, lmhash, nthash, aesKey, TGT, TGS = self.getCredentials() self.negotiateSession(self._preferredDialect) if self._doKerberos is True: self.kerberosLogin(userName, password, domain, lmhash, nthash, aesKey, self._kdcHost, TGT, TGS, self._useCache) else: self.login(userName, password, domain, lmhash, nthash, self._ntlmFallback) return True
Example #18
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 6 votes |
def putFile(self, shareName, pathName, callback, shareAccessMode = None): """ uploads a file :param string shareName: name for the share where the file is to be uploaded :param string pathName: the path name to upload :param callback callback: function called to read the contents to be written. :param int shareAccessMode: :return: None, raises a SessionError exception if error. """ try: if shareAccessMode is None: # if share access mode is none, let's the underlying API deals with it return self._SMBConnection.stor_file(shareName, pathName, callback) else: return self._SMBConnection.stor_file(shareName, pathName, callback, shareAccessMode) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #19
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 6 votes |
def getFile(self, shareName, pathName, callback, shareAccessMode = None): """ downloads a file :param string shareName: name for the share where the file is to be retrieved :param string pathName: the path name to retrieve :param callback callback: function called to write the contents read. :param int shareAccessMode: :return: None, raises a SessionError exception if error. """ try: if shareAccessMode is None: # if share access mode is none, let's the underlying API deals with it return self._SMBConnection.retr_file(shareName, pathName, callback) else: return self._SMBConnection.retr_file(shareName, pathName, callback, shareAccessMode=shareAccessMode) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #20
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 6 votes |
def readNamedPipe(self,treeId, fileId, bytesToRead = None ): """ read from a named pipe :param HANDLE treeId: a valid handle for the share where the pipe resides :param HANDLE fileId: a valid handle for the pipe :param integer bytesToRead: amount of data to read :return: None, raises a SessionError exception if error. """ try: return self.readFile(treeId, fileId, bytesToRead = bytesToRead, singleCall = True) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #21
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 6 votes |
def transactNamedPipe(self, treeId, fileId, data, waitAnswer = True): """ writes to a named pipe using a transaction command :param HANDLE treeId: a valid handle for the share where the pipe is :param HANDLE fileId: a valid handle for the pipe :param string data: buffer with the data to write :param boolean waitAnswer: whether or not to wait for an answer :return: None, raises a SessionError exception if error. """ try: return self._SMBConnection.TransactNamedPipe(treeId, fileId, data, waitAnswer = waitAnswer) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #22
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 6 votes |
def login(self, user, password, domain = '', lmhash = '', nthash = '', ntlmFallback = True): """ logins into the target system :param string user: username :param string password: password for the user :param string domain: domain where the account is valid for :param string lmhash: LMHASH used to authenticate using hashes (password is not used) :param string nthash: NTHASH used to authenticate using hashes (password is not used) :param bool ntlmFallback: If True it will try NTLMv1 authentication if NTLMv2 fails. Only available for SMBv1 :return: None, raises a Session Error if error. """ self._ntlmFallback = ntlmFallback try: if self.getDialect() == smb.SMB_DIALECT: return self._SMBConnection.login(user, password, domain, lmhash, nthash, ntlmFallback) else: return self._SMBConnection.login(user, password, domain, lmhash, nthash) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #23
Source File: zzz_exploit.py From MS17-010-Python with MIT License | 6 votes |
def find_named_pipe(conn): pipes = [ 'browser', 'spoolss', 'netlogon', 'lsarpc', 'samr' ] tid = conn.tree_connect_andx('\\\\'+conn.get_remote_host()+'\\'+'IPC$') found_pipe = None if args.pipe: return args.pipe for pipe in pipes: logger.blue('Trying pipe: %s' % logger.BLUE(pipe)) try: fid = conn.nt_create_andx(tid, pipe) conn.close(tid, fid) logger.green('Found pipe: %s' % logger.GREEN(pipe)) found_pipe = pipe except smb.SessionError as e: logger.red('Got error whilst connecting to %s: %s' % (pipe,logger.RED(e))) finally: conn.disconnect_tree(tid) return found_pipe
Example #24
Source File: mysmb.py From AutoBlue-MS17-010 with MIT License | 6 votes |
def find_named_pipe(self, firstOnly=True): pipes_file = '/usr/share/metasploit-framework/data/wordlists/named_pipes.txt' try: with open(pipes_file) as f: pipes = [ x.strip() for x in f.readlines()] except IOError as e: print("[-] Could not open {}, trying hardcoded values".format(pipes_file)) pipes = [ 'netlogon', 'lsarpc', 'samr', 'browser', 'spoolss', 'atsvc', 'DAV RPC SERVICE', 'epmapper', 'eventlog', 'InitShutdown', 'keysvc', 'lsass', 'LSM_API_service', 'ntsvcs', 'plugplay', 'protected_storage', 'router', 'SapiServerPipeS-1-5-5-0-70123', 'scerpc', 'srvsvc', 'tapsrv', 'trkwks', 'W32TIME_ALT', 'wkssvc','PIPE_EVENTROOT\CIMV2SCM EVENT PROVIDER', 'db2remotecmd' ] tid = self.tree_connect_andx('\\\\'+self.get_remote_host()+'\\'+'IPC$') found_pipes = [] for pipe in pipes: try: fid = self.nt_create_andx(tid, pipe) self.close(tid, fid) found_pipes.append(pipe) print("[+] Found pipe '{}'".format(pipe)) if firstOnly: break except smb.SessionError as e: pass self.disconnect_tree(tid) if len(found_pipes) > 0: return found_pipes[0] else: return None
Example #25
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def rename(self, shareName, oldPath, newPath): """ renames a file/directory :param string shareName: name for the share where the files/directories are :param string oldPath: the old path name or the directory/file to rename :param string newPath: the new path name or the directory/file to rename :return: True, raises a SessionError exception if error. """ try: return self._SMBConnection.rename(shareName, oldPath, newPath) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #26
Source File: smbconnection.py From cracke-dit with MIT License | 6 votes |
def getFile(self, shareName, pathName, callback, shareAccessMode = None): """ downloads a file :param string shareName: name for the share where the file is to be retrieved :param string pathName: the path name to retrieve :param callback callback: :return: None, raises a SessionError exception if error. """ try: if shareAccessMode is None: # if share access mode is none, let's the underlying API deals with it return self._SMBConnection.retr_file(shareName, pathName, callback) else: return self._SMBConnection.retr_file(shareName, pathName, callback, shareAccessMode=shareAccessMode) except (smb.SessionError, smb3.SessionError), e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #27
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 5 votes |
def waitNamedPipe(self, treeId, pipeName, timeout = 5): """ waits for a named pipe :param HANDLE treeId: a valid handle for the share where the pipe is :param string pipeName: the pipe name to check :param integer timeout: time to wait for an answer :return: None, raises a SessionError exception if error. """ try: return self._SMBConnection.waitNamedPipe(treeId, pipeName, timeout = timeout) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #28
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 5 votes |
def deleteDirectory(self, shareName, pathName): """ deletes a directory :param string shareName: a valid name for the share where directory is to be deleted :param string pathName: the path name or the directory to delete :return: None, raises a SessionError exception if error. """ try: return self._SMBConnection.rmdir(shareName, pathName) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #29
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 5 votes |
def transactNamedPipeRecv(self): """ reads from a named pipe using a transaction command :return: data read, raises a SessionError exception if error. """ try: return self._SMBConnection.TransactNamedPipeRecv() except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())
Example #30
Source File: smbconnection.py From Slackor with GNU General Public License v3.0 | 5 votes |
def connectTree(self,share): if self.getDialect() == smb.SMB_DIALECT: # If we already have a UNC we do nothing. if ntpath.ismount(share) is False: # Else we build it share = ntpath.basename(share) share = '\\\\' + self.getRemoteHost() + '\\' + share try: return self._SMBConnection.connect_tree(share) except (smb.SessionError, smb3.SessionError) as e: raise SessionError(e.get_error_code(), e.get_error_packet())