Mid-level wrapper over SMB_Client.smblink that provides some basic SMB client functions, such as tree connect, directory query, etc.
| 665 | |
| 666 | |
| 667 | class SMB_SOCKET(SuperSocket): |
| 668 | """ |
| 669 | Mid-level wrapper over SMB_Client.smblink that provides some basic SMB |
| 670 | client functions, such as tree connect, directory query, etc. |
| 671 | """ |
| 672 | |
| 673 | def __init__(self, smbsock, use_ioctl=True, timeout=3): |
| 674 | self.ins = smbsock |
| 675 | self.timeout = timeout |
| 676 | if not self.ins.atmt.smb_sock_ready.wait(timeout=timeout): |
| 677 | # If we have a SSP, tell it we failed. |
| 678 | if self.ins.atmt.session.sspcontext: |
| 679 | self.ins.atmt.session.sspcontext.clifailure() |
| 680 | raise TimeoutError( |
| 681 | "The SMB handshake timed out ! (enable debug=1 for logs)" |
| 682 | ) |
| 683 | if self.ins.atmt.ErrorStatus: |
| 684 | raise Scapy_Exception( |
| 685 | "SMB Session Setup failed: %s" % self.ins.atmt.ErrorStatus |
| 686 | ) |
| 687 | |
| 688 | @classmethod |
| 689 | def from_tcpsock(cls, sock, **kwargs): |
| 690 | """ |
| 691 | Wraps the tcp socket in a SMB_Client.smblink first, then into the |
| 692 | SMB_SOCKET/SMB_RPC_SOCKET |
| 693 | """ |
| 694 | return cls( |
| 695 | use_ioctl=kwargs.pop("use_ioctl", True), |
| 696 | timeout=kwargs.pop("timeout", 3), |
| 697 | smbsock=SMB_Client.from_tcpsock(sock, **kwargs), |
| 698 | ) |
| 699 | |
| 700 | @property |
| 701 | def session(self): |
| 702 | return self.ins.atmt.session |
| 703 | |
| 704 | def set_TID(self, TID): |
| 705 | """ |
| 706 | Set the TID (Tree ID). |
| 707 | This can be called before sending a packet |
| 708 | """ |
| 709 | self.ins.atmt.smb_header.TID = TID |
| 710 | |
| 711 | def get_TID(self): |
| 712 | """ |
| 713 | Get the current TID from the underlying socket |
| 714 | """ |
| 715 | return self.ins.atmt.smb_header.TID |
| 716 | |
| 717 | def tree_connect(self, name): |
| 718 | """ |
| 719 | Send a TreeConnect request |
| 720 | """ |
| 721 | resp = self.ins.sr1( |
| 722 | SMB2_Tree_Connect_Request( |
| 723 | Buffer=[ |
| 724 | ( |
no outgoing calls
no test coverage detected
searching dependent graphs…