當前位置: 首頁>>代碼示例>>Python>>正文


Python srvs.hNetrSessionEnum方法代碼示例

本文整理匯總了Python中impacket.dcerpc.v5.srvs.hNetrSessionEnum方法的典型用法代碼示例。如果您正苦於以下問題:Python srvs.hNetrSessionEnum方法的具體用法?Python srvs.hNetrSessionEnum怎麽用?Python srvs.hNetrSessionEnum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在impacket.dcerpc.v5.srvs的用法示例。


在下文中一共展示了srvs.hNetrSessionEnum方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_hNetrSessionEnum

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def test_hNetrSessionEnum(self):
        dce, rpctransport = self.connect()
        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 0)
        resp.dump()

        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 1)
        resp.dump()

        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 2)
        resp.dump()

        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 10)
        resp.dump()

        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 502)
        resp.dump() 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:18,代碼來源:test_srvs.py

示例2: test_hNetrSessionDel

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def test_hNetrSessionDel(self):
        dce, rpctransport = self.connect()
        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 502)
        resp.dump()

        try:
            resp = srvs.hNetrSessionDel(dce, resp['InfoStruct']['SessionInfo']['Level502']['Buffer'][0]['sesi502_cname'], resp['InfoStruct']['SessionInfo']['Level502']['Buffer'][0]['sesi502_username'] )
            resp.dump()
        except Exception, e:
            if e.get_error_code() != 0x908:
                raise 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:13,代碼來源:test_srvs.py

示例3: get_netsession

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def get_netsession(self):

        try:
            resp = srvs.hNetrSessionEnum(self._rpc_connection, '\x00', NULL, 10)
        except DCERPCException:
            return list()

        results = list()
        for session in resp['InfoStruct']['SessionInfo']['Level10']['Buffer']:
            results.append(rpcobj.Session(session))

        return results 
開發者ID:the-useless-one,項目名稱:pywerview,代碼行數:14,代碼來源:net.py

示例4: do_who

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def do_who(self, line):
        if self.loggedIn is False:
            LOG.error("Not logged in")
            return
        rpctransport = transport.SMBTransport(self.smb.getRemoteHost(), filename = r'\srvsvc', smb_connection = self.smb)
        dce = rpctransport.get_dce_rpc()
        dce.connect()
        dce.bind(srvs.MSRPC_UUID_SRVS)
        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 10)

        for session in resp['InfoStruct']['SessionInfo']['Level10']['Buffer']:
            print("host: %15s, user: %5s, active: %5d, idle: %5d" % (
            session['sesi10_cname'][:-1], session['sesi10_username'][:-1], session['sesi10_time'],
            session['sesi10_idle_time'])) 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:16,代碼來源:smbclient.py

示例5: test_hNetrSessionDel

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def test_hNetrSessionDel(self):
        dce, rpctransport = self.connect()
        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 502)
        resp.dump()

        try:
            resp = srvs.hNetrSessionDel(dce, resp['InfoStruct']['SessionInfo']['Level502']['Buffer'][0]['sesi502_cname'], resp['InfoStruct']['SessionInfo']['Level502']['Buffer'][0]['sesi502_username'] )
            resp.dump()
        except Exception as e:
            if e.get_error_code() != 0x908:
                raise 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:13,代碼來源:test_srvs.py

示例6: get_netsessions

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def get_netsessions(self):
        self.sessions = {}
        self.create_rpc_con(r'\srvsvc')
        try:
            resp = srvs.hNetrSessionEnum(self.rpc_connection, '\x00', NULL, 10)
        except DCERPCException:
            return list()

        for session in resp['InfoStruct']['SessionInfo']['Level10']['Buffer']:
            self.sessions[session['sesi10_username'].strip('\x00')] = {'user' : session['sesi10_username'].strip('\x00'),
                                                      'host' : session['sesi10_cname'].strip('\x00'),
                                                      'time' : session['sesi10_time'],
                                                      'idle' : session['sesi10_idle_time']
                                                      }
        self.rpc_connection.disconnect() 
開發者ID:m8r0wn,項目名稱:ActiveReign,代碼行數:17,代碼來源:rpc.py

示例7: do_who

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def do_who(self, line):
        if self.loggedIn is False:
            logging.error("Not logged in")
            return
        rpctransport = transport.SMBTransport(self.smb.getRemoteHost(), filename = r'\srvsvc', smb_connection = self.smb)
        dce = rpctransport.get_dce_rpc()
        dce.connect()                     
        dce.bind(srvs.MSRPC_UUID_SRVS)
        resp = srvs.hNetrSessionEnum(dce, NULL, NULL, 10)

        for session in resp['InfoStruct']['SessionInfo']['Level10']['Buffer']:
            print "host: %15s, user: %5s, active: %5d, idle: %5d" % (
            session['sesi10_cname'][:-1], session['sesi10_username'][:-1], session['sesi10_time'],
            session['sesi10_idle_time']) 
開發者ID:tholum,項目名稱:PiBunny,代碼行數:16,代碼來源:smbclient.py

示例8: getSessions

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def getSessions(self, target):
        if self.__targets[target]['SRVS'] is None:
            stringSrvsBinding = r'ncacn_np:%s[\PIPE\srvsvc]' % target
            rpctransportSrvs = transport.DCERPCTransportFactory(stringSrvsBinding)
            if hasattr(rpctransportSrvs, 'set_credentials'):
            # This method exists only for selected protocol sequences.
                rpctransportSrvs.set_credentials(self.__username, self.__password, self.__domain, self.__lmhash,
                                                 self.__nthash, self.__aesKey)
                rpctransportSrvs.set_kerberos(self.__doKerberos, self.__kdcHost)

            dce = rpctransportSrvs.get_dce_rpc()
            dce.connect()
            dce.bind(srvs.MSRPC_UUID_SRVS)
            self.__maxConnections -= 1
        else:
            dce = self.__targets[target]['SRVS']

        try:
            resp = srvs.hNetrSessionEnum(dce, '\x00', NULL, 10)
        except Exception, e:
            if str(e).find('Broken pipe') >= 0:
                # The connection timed-out. Let's try to bring it back next round
                self.__targets[target]['SRVS'] = None
                self.__maxConnections += 1
                return
            else:
                raise 
開發者ID:tholum,項目名稱:PiBunny,代碼行數:29,代碼來源:netview.py

示例9: rpc_get_sessions

# 需要導入模塊: from impacket.dcerpc.v5 import srvs [as 別名]
# 或者: from impacket.dcerpc.v5.srvs import hNetrSessionEnum [as 別名]
def rpc_get_sessions(self):
        binding = r'ncacn_np:%s[\PIPE\srvsvc]' % self.addr

        dce = self.dce_rpc_connect(binding, srvs.MSRPC_UUID_SRVS)

        if dce is None:
            return

        try:
            resp = srvs.hNetrSessionEnum(dce, '\x00', NULL, 10)
        except DCERPCException as e:
            if 'rpc_s_access_denied' in str(e):
                logging.debug('Access denied while enumerating Sessions on %s, likely a patched OS', self.hostname)
                return []
            else:
                raise
        except Exception as e:
            if str(e).find('Broken pipe') >= 0:
                return
            else:
                raise

        sessions = []

        for session in resp['InfoStruct']['SessionInfo']['Level10']['Buffer']:
            userName = session['sesi10_username'][:-1]
            ip = session['sesi10_cname'][:-1]
            # Strip \\ from IPs
            if ip[:2] == '\\\\':
                ip = ip[2:]
            # Skip empty IPs
            if ip == '':
                continue
            # Skip our connection
            if userName == self.ad.auth.username:
                continue
            # Skip empty usernames
            if len(userName) == 0:
                continue
            # Skip machine accounts
            if userName[-1] == '$':
                continue
            # Skip local connections
            if ip in ['127.0.0.1', '[::1]']:
                continue
            # IPv6 address
            if ip[0] == '[' and ip[-1] == ']':
                ip = ip[1:-1]

            logging.info('User %s is logged in on %s from %s' % (userName, self.hostname, ip))

            sessions.append({'user': userName, 'source': ip, 'target': self.hostname})

        dce.disconnect()

        return sessions 
開發者ID:fox-it,項目名稱:BloodHound.py,代碼行數:58,代碼來源:computer.py


注:本文中的impacket.dcerpc.v5.srvs.hNetrSessionEnum方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。