MCPcopy Create free account
hub / github.com/secdev/scapy / connect

Method connect

scapy/layers/msrpce/rpcclient.py:153–252  ·  view source on GitHub ↗

Initiate a connection. :param host: the host to connect to :param endpoint: (optional) the port/smb pipe to connect to :param interface: (optional) if endpoint isn't provided, uses the endpoint mapper to find the appropriate endpoint for that interface.

(
        self,
        host,
        endpoint: Union[int, str] = None,
        port: Optional[int] = None,
        interface=None,
        timeout=5,
        smb_kwargs={},
    )

Source from the content-addressed store, hash-verified

151 return self.sock.session
152
153 def connect(
154 self,
155 host,
156 endpoint: Union[int, str] = None,
157 port: Optional[int] = None,
158 interface=None,
159 timeout=5,
160 smb_kwargs={},
161 ):
162 """
163 Initiate a connection.
164
165 :param host: the host to connect to
166 :param endpoint: (optional) the port/smb pipe to connect to
167 :param interface: (optional) if endpoint isn't provided, uses the endpoint
168 mapper to find the appropriate endpoint for that interface.
169 :param timeout: (optional) the connection timeout (default 5)
170 :param port: (optional) the port to connect to. (useful for SMB)
171 """
172 if endpoint is None and interface is not None:
173 # Figure out the endpoint using the endpoint mapper
174
175 if self.transport == DCERPC_Transport.NCACN_IP_TCP and port is None:
176 # IP/TCP
177 # ask the endpoint mapper (port 135) for the IP:PORT
178 endpoints = get_endpoint(
179 host,
180 interface,
181 ndrendian=self.ndrendian,
182 verb=self.verb,
183 )
184 if endpoints:
185 _, endpoint = endpoints[0]
186 else:
187 raise ValueError(
188 "Could not find an available endpoint for that interface !"
189 )
190 elif self.transport == DCERPC_Transport.NCACN_NP:
191 # SMB
192 # ask the endpoint mapper (over SMB) for the namedpipe
193 endpoints = get_endpoint(
194 host,
195 interface,
196 transport=self.transport,
197 ndrendian=self.ndrendian,
198 verb=self.verb,
199 smb_kwargs=smb_kwargs,
200 )
201 if endpoints:
202 endpoint = endpoints[0].lstrip("\\pipe\\")
203 else:
204 return
205
206 # Assign the default port if no port is provided
207 if port is None:
208 if self.transport == DCERPC_Transport.NCACN_IP_TCP: # IP/TCP
209 port = endpoint or 135
210 elif self.transport == DCERPC_Transport.NCACN_NP: # SMB

Callers 3

connect_and_bindMethod · 0.95
get_endpointFunction · 0.95
ServerAlive2Function · 0.95

Calls 4

open_smbpipeMethod · 0.95
DceRpcSocketClass · 0.90
get_endpointFunction · 0.85
from_tcpsockMethod · 0.45

Tested by

no test coverage detected