当前位置: 首页>>代码示例>>Python>>正文


Python smbconnection.SMBConnection方法代码示例

本文整理汇总了Python中impacket.smbconnection.SMBConnection方法的典型用法代码示例。如果您正苦于以下问题:Python smbconnection.SMBConnection方法的具体用法?Python smbconnection.SMBConnection怎么用?Python smbconnection.SMBConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在impacket.smbconnection的用法示例。


在下文中一共展示了smbconnection.SMBConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getMachineName

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def getMachineName(self):
        if self.__kdcHost is not None and self.__targetDomain == self.__domain:
            s = SMBConnection(self.__kdcHost, self.__kdcHost)
        else:
            s = SMBConnection(self.__targetDomain, self.__targetDomain)
        try:
            s.login('', '')
        except Exception:
            if s.getServerName() == '':
                raise 'Error while anonymous logging into %s'
        else:
            try:
                s.logoff()
            except Exception:
                # We don't care about exceptions here as we already have the required
                # information. This also works around the current SMB3 bug
                pass
        return "%s.%s" % (s.getServerName(), s.getServerDNSDomainName()) 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:20,代码来源:GetUserSPNs.py

示例2: connectPipe

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def connectPipe(self):
        try:
            lock.acquire()
            global dialect
            self.server = SMBConnection('*SMBSERVER', self.transport.get_smb_connection().getRemoteHost(),
                                        sess_port=self.port, preferredDialect=dialect)
            user, passwd, domain, lm, nt, aesKey, TGT, TGS = self.credentials
            self.server.login(user, passwd, domain, lm, nt)
            lock.release()
            self.tid = self.server.connectTree('IPC$') 

            self.server.waitNamedPipe(self.tid, self.pipe)
            self.fid = self.server.openFile(self.tid,self.pipe,self.permissions, creationOption = 0x40, fileAttributes = 0x80)
            self.server.setTimeout(1000000)
        except Exception:
            logging.critical("Something wen't wrong connecting the pipes(%s), try again" % self.__class__) 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:18,代码来源:raiseChild.py

示例3: connectPipe

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def connectPipe(self):
        try:
            lock.acquire()
            global dialect
            #self.server = SMBConnection('*SMBSERVER', self.transport.get_smb_connection().getRemoteHost(), sess_port = self.port, preferredDialect = SMB_DIALECT)
            self.server = SMBConnection(self.transport.get_smb_connection().getRemoteName(), self.transport.get_smb_connection().getRemoteHost(),
                                        sess_port=self.port, preferredDialect=dialect)
            user, passwd, domain, lm, nt, aesKey, TGT, TGS = self.credentials
            if self.transport.get_kerberos() is True:
                self.server.kerberosLogin(user, passwd, domain, lm, nt, aesKey, kdcHost=self.transport.get_kdcHost(), TGT=TGT, TGS=TGS)
            else:
                self.server.login(user, passwd, domain, lm, nt)
            lock.release()
            self.tid = self.server.connectTree('IPC$') 

            self.server.waitNamedPipe(self.tid, self.pipe)
            self.fid = self.server.openFile(self.tid,self.pipe,self.permissions, creationOption = 0x40, fileAttributes = 0x80)
            self.server.setTimeout(1000000)
        except:
            if logging.getLogger().level == logging.DEBUG:
                import traceback
                traceback.print_exc()
            logging.error("Something wen't wrong connecting the pipes(%s), try again" % self.__class__) 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:25,代码来源:psexec.py

示例4: connectPipe

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def connectPipe(self):
        try:
            lock.acquire()
            global dialect
            self.server = SMBConnection('*SMBSERVER', self.transport.get_smb_connection().getRemoteHost(),
                                        sess_port=self.port, preferredDialect=dialect)
            user, passwd, domain, lm, nt, aesKey, TGT, TGS = self.credentials
            self.server.login(user, passwd, domain, lm, nt)
            lock.release()
            self.tid = self.server.connectTree('IPC$') 

            self.server.waitNamedPipe(self.tid, self.pipe)
            self.fid = self.server.openFile(self.tid,self.pipe,self.permissions, creationOption = 0x40, fileAttributes = 0x80)
            self.server.setTimeout(1000000)
        except:
            logging.critical("Something wen't wrong connecting the pipes(%s), try again" % self.__class__) 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:18,代码来源:goldenPac.py

示例5: check

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def check(self, remote_host):
        # Validate credentials first
        if not self.creds_validated:
            self.validate_creds(remote_host)
            self.creds_validated = True

        # Now start scanner
        try:
            smbClient = SMBConnection(remote_host, remote_host, sess_port=int(self.__port)) #, preferredDialect=SMB2_DIALECT_21
        except:
            return
        ntlm.computeResponseNTLMv2 = mod_computeResponseNTLMv2
        try:
            smbClient.login(self.__username, self.__password, self.__domain, self.__lmhash, self.__nthash)
            logging.info('Target %s is VULNERABLE to CVE-2019-1040 (authentication was accepted)', remote_host)
        except SessionError as exc:
            if 'STATUS_INVALID_PARAMETER' in str(exc):
                logging.info('Target %s is not vulnerable to CVE-2019-1040 (authentication was rejected)', remote_host)
            else:
                logging.warning('Unexpected Exception while authenticating to %s: %s', remote_host, exc)

        smbClient.close()

# Process command-line arguments. 
开发者ID:fox-it,项目名称:cve-2019-1040-scanner,代码行数:26,代码来源:scan.py

示例6: connectPipe

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def connectPipe(self):
        try:
            lock.acquire()
            global dialect
            self.server = SMBConnection('*SMBSERVER', self.transport.get_smb_connection().getRemoteHost(),
                                        sess_port=self.port, preferredDialect=dialect)
            user, passwd, domain, lm, nt, aesKey, TGT, TGS = self.credentials
            self.server.login(user, passwd, domain, lm, nt)
            lock.release()
            self.tid = self.server.connectTree('IPC$') 

            self.server.waitNamedPipe(self.tid, self.pipe)
            self.fid = self.server.openFile(self.tid,self.pipe,self.permissions, creationOption = 0x40, fileAttributes = 0x80)
            self.server.setTimeout(1000000)
        except Exception, e:
            logging.critical("Something wen't wrong connecting the pipes(%s), try again" % self.__class__) 
开发者ID:tholum,项目名称:PiBunny,代码行数:18,代码来源:raiseChild.py

示例7: connectPipe

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def connectPipe(self):
        try:
            lock.acquire()
            global dialect
            #self.server = SMBConnection('*SMBSERVER', self.transport.get_smb_connection().getRemoteHost(), sess_port = self.port, preferredDialect = SMB_DIALECT)
            self.server = SMBConnection(self.transport.get_smb_connection().getRemoteName(), self.transport.get_smb_connection().getRemoteHost(),
                                        sess_port=self.port, preferredDialect=dialect)
            user, passwd, domain, lm, nt, aesKey, TGT, TGS = self.credentials
            if self.transport.get_kerberos() is True:
                self.server.kerberosLogin(user, passwd, domain, lm, nt, aesKey, kdcHost=self.transport.get_kdcHost(), TGT=TGT, TGS=TGS)
            else:
                self.server.login(user, passwd, domain, lm, nt)
            lock.release()
            self.tid = self.server.connectTree('IPC$') 

            self.server.waitNamedPipe(self.tid, self.pipe)
            self.fid = self.server.openFile(self.tid,self.pipe,self.permissions, creationOption = 0x40, fileAttributes = 0x80)
            self.server.setTimeout(1000000)
        except:
            import traceback
            traceback.print_exc()
            logging.error("Something wen't wrong connecting the pipes(%s), try again" % self.__class__) 
开发者ID:tholum,项目名称:PiBunny,代码行数:24,代码来源:psexec.py

示例8: __init__

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def __init__(self, config, SMBClient, username):
        Thread.__init__(self)
        self.daemon = True
        if isinstance(SMBClient, smb.SMB) or isinstance(SMBClient, smb3.SMB3):
            self.__SMBConnection = SMBConnection(existingConnection = SMBClient)
        else:
            self.__SMBConnection = SMBClient
        self.config = config
        self.__answerTMP = ''
        if self.config.interactive:
            #Launch locally listening interactive shell
            self.tcpshell = TcpShell()
        else:
            self.tcpshell = None
            if self.config.exeFile is not None:
                self.installService = serviceinstall.ServiceInstall(SMBClient, self.config.exeFile) 
开发者ID:tholum,项目名称:PiBunny,代码行数:18,代码来源:ntlmrelayx.py

示例9: __init__

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def __init__(self, SMBObject, exeFile):
        self._rpctransport = 0
        self.__service_name = ''.join([random.choice(string.letters) for i in range(4)])
        self.__binary_service_name = ''.join([random.choice(string.letters) for i in range(8)]) + '.exe'
        self.__exeFile = exeFile

        # We might receive two different types of objects, always end up
        # with a SMBConnection one
        if isinstance(SMBObject, smb.SMB) or isinstance(SMBObject, smb3.SMB3):
            self.connection = SMBConnection(existingConnection = SMBObject)
        else:
            self.connection = SMBObject

        self.share = '' 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:16,代码来源:serviceinstall.py

示例10: create_connection

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def create_connection(self):
        if self.dialects == smb.SMB_DIALECT:
            # Only for SMB1 let's do manualNego
            s = SMBConnection('*SMBSERVER', self.machine, preferredDialect = self.dialects, manualNegotiate=True)
            s.negotiateSession(self.dialects, flags2=self.flags2)
        else:
            s = SMBConnection('*SMBSERVER', self.machine, preferredDialect = self.dialects)
        return s 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:10,代码来源:test_smb.py

示例11: setup_smb_connection

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def setup_smb_connection(self):
        if not self.__smb_connection:
            self.__smb_connection = SMBConnection(self.getRemoteName(), self.getRemoteHost(), sess_port=self.get_dport(),
                                                  preferredDialect=self.__prefDialect) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:6,代码来源:transport.py

示例12: do_login

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def do_login(self):
    try:
      self.smb = SMBConnection(remoteName='*SMBSERVER', remoteHost=self.sambaTarget, sess_port=int(self.sambaPort))
      self.smb.login(user=self.username, password=self.password)
      if self.smb.isGuestSession():
        log("Using a GUEST session")
      return True
    except:
      log("Error logging into the Samba server: %s" % str(sys.exc_info()[1]))
      return False 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:12,代码来源:cve_2017_7494.py

示例13: login

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def login(self):
        try:
            ip = list({addr[-1][0] for addr in getaddrinfo(self.hostname, 0, 0, 0, 0)})[0]
            if ip != self.hostname:
                self._log.debug("Host {} resolved to {}".format(self.hostname, ip))
        except gaierror as e:
            return RetCode(ERROR_DNS_ERROR, e)

        try:
            self._conn = SMBConnection(self.hostname, ip, timeout=self.timeout)
        except Exception as e:
            return RetCode(ERROR_CONNECTION_ERROR, e)

        username = ''
        if not self.kerberos:
            username = self.username.split("@")[0]
            self._log.debug("Authenticating against {}".format(ip))
        else:
            self._log.debug("Authenticating against {}".format(self.hostname))

        try:
            if not self.kerberos:
                self._conn.login(username, self.password, domain=self.domain_name, lmhash=self.lmhash,
                                 nthash=self.nthash, ntlmFallback=True)
            else:
                self._conn.kerberosLogin(username, self.password, domain=self.domain_name, lmhash=self.lmhash,
                                         nthash=self.nthash, aesKey=self.aesKey, kdcHost=self.dc_ip)

        except SessionError as e:
            self._log.debug("Provided credentials : {}\\{}:{}".format(self.domain_name, username, self.password))
            return RetCode(ERROR_LOGIN_FAILURE, e)
        except KerberosException as e:
            self._log.debug("Kerberos error")
            return RetCode(ERROR_LOGIN_FAILURE, e)
        except Exception as e:
            return RetCode(ERROR_UNDEFINED, e)
        return RetCode(ERROR_SUCCESS) 
开发者ID:Hackndo,项目名称:lsassy,代码行数:39,代码来源:impacketconnection.py

示例14: get_gpttmpl

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def get_gpttmpl(self, gpttmpl_path):
        content_io = StringIO()

        gpttmpl_path_split = gpttmpl_path.split('\\')
        target = self._domain_controller
        share = gpttmpl_path_split[3]
        file_name = '\\'.join(gpttmpl_path_split[4:])

        smb_connection = SMBConnection(remoteName=target, remoteHost=target)
        # TODO: kerberos login
        smb_connection.login(self._user, self._password, self._domain,
                             self._lmhash, self._nthash)

        smb_connection.connectTree(share)
        smb_connection.getFile(share, file_name, content_io.write)

        try:
            content = codecs.decode(content_io.getvalue(), 'utf_16_le')[1:].replace('\r', '')
        except UnicodeDecodeError:
            content = content_io.getvalue().replace('\r', '')

        gpttmpl_final = GptTmpl(list())
        for l in content.split('\n'):
            if l.startswith('['):
                section_name = l.strip('[]').replace(' ', '').lower()
                setattr(gpttmpl_final, section_name, Policy(list()))
            elif '=' in l:
                property_name, property_values = [x.strip() for x in l.split('=')]
                if ',' in property_values:
                    property_values = property_values.split(',')
                try:
                    setattr(getattr(gpttmpl_final, section_name), property_name, property_values)
                except UnicodeEncodeError:
                    property_name = property_name.encode('utf-8')
                    setattr(getattr(gpttmpl_final, section_name), property_name, property_values)

        return gpttmpl_final 
开发者ID:the-useless-one,项目名称:pywerview,代码行数:39,代码来源:gpo.py

示例15: _get_netfqdn

# 需要导入模块: from impacket import smbconnection [as 别名]
# 或者: from impacket.smbconnection import SMBConnection [as 别名]
def _get_netfqdn(self):
        try:
            smb = SMBConnection(self._domain_controller, self._domain_controller)
        except socket.error:
            return str()

        smb.login(self._user, self._password, domain=self._domain,
                lmhash=self._lmhash, nthash=self._nthash)
        fqdn = smb.getServerDNSDomainName()
        smb.logoff()

        return fqdn 
开发者ID:the-useless-one,项目名称:pywerview,代码行数:14,代码来源:requester.py


注:本文中的impacket.smbconnection.SMBConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。