MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _listShares_SMB2

Method _listShares_SMB2

pager_lib/smb/base.py:418–603  ·  view source on GitHub ↗
(self, callback, errback, timeout = 30)

Source from the content-addressed store, hash-verified

416
417
418 def _listShares_SMB2(self, callback, errback, timeout = 30):
419 if not self.has_authenticated:
420 raise NotReadyError('SMB connection not authenticated')
421
422 expiry_time = time.time() + timeout
423 path = 'IPC$'
424 messages_history = [ ]
425
426 def connectSrvSvc(tid):
427 m = SMB2Message(SMB2CreateRequest('srvsvc',
428 file_attributes = 0,
429 access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_READ_EA | FILE_WRITE_EA | READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
430 share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
431 oplock = SMB2_OPLOCK_LEVEL_NONE,
432 impersonation = SEC_IMPERSONATE,
433 create_options = FILE_NON_DIRECTORY_FILE | FILE_OPEN_NO_RECALL,
434 create_disp = FILE_OPEN))
435
436 m.tid = tid
437 self._sendSMBMessage(m)
438 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectSrvSvcCB, errback, tid = tid)
439 self._pushToArray(messages_history, m)
440
441 def connectSrvSvcCB(create_message, **kwargs):
442 self._pushToArray(messages_history, create_message)
443 if create_message.status == 0:
444 call_id = self._getNextRPCCallID()
445 # The data_bytes are binding call to Server Service RPC using DCE v1.1 RPC over SMB. See [MS-SRVS] and [C706]
446 # If you wish to understand the meanings of the byte stream, I would suggest you use a recent version of WireShark to packet capture the stream
447 data_bytes = \
448 binascii.unhexlify(b"""05 00 0b 03 10 00 00 00 74 00 00 00""".replace(b' ', b'')) + \
449 struct.pack('<I', call_id) + \
450 binascii.unhexlify(b"""
451b8 10 b8 10 00 00 00 00 02 00 00 00 00 00 01 00
452c8 4f 32 4b 70 16 d3 01 12 78 5a 47 bf 6e e1 88
45303 00 00 00 04 5d 88 8a eb 1c c9 11 9f e8 08 00
4542b 10 48 60 02 00 00 00 01 00 01 00 c8 4f 32 4b
45570 16 d3 01 12 78 5a 47 bf 6e e1 88 03 00 00 00
4562c 1c b7 6c 12 98 40 45 03 00 00 00 00 00 00 00
45701 00 00 00
458""".replace(b' ', b'').replace(b'\n', b''))
459 m = SMB2Message(SMB2WriteRequest(create_message.payload.fid, data_bytes, 0))
460 m.tid = kwargs['tid']
461 self._sendSMBMessage(m)
462 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcBindCB, errback, tid = kwargs['tid'], fid = create_message.payload.fid)
463 self._pushToArray(messages_history, m)
464 else:
465 errback(OperationFailure('Failed to list shares: Unable to locate Server Service RPC endpoint', messages_history))
466
467 def rpcBindCB(trans_message, **kwargs):
468 self._pushToArray(messages_history, trans_message)
469 if trans_message.status == 0:
470 m = SMB2Message(SMB2ReadRequest(kwargs['fid'], read_len = 1024, read_offset = 0))
471 m.tid = kwargs['tid']
472 self._sendSMBMessage(m)
473 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, rpcReadCB, errback, tid = kwargs['tid'], fid = kwargs['fid'])
474 self._pushToArray(messages_history, m)
475 else:

Callers

nothing calls this directly

Calls 5

_pushToArrayMethod · 0.95
NotReadyErrorClass · 0.85
SMB2MessageClass · 0.85
_PendingRequestClass · 0.85

Tested by

no test coverage detected