本文整理汇总了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()
示例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
示例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
示例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']))
示例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
示例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()
示例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'])
示例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
示例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