Skip to content

Commit 7be7a7d

Browse files
authored
Fix SMB tests (#5158)
AI-Assisted: no
1 parent 4122c5d commit 7be7a7d

1 file changed

Lines changed: 0 additions & 77 deletions

File tree

test/scapy/layers/smbclientserver.uts

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -237,35 +237,6 @@ assert (LOCALPATH / "fileScapy").exists()
237237
assert (LOCALPATH / "sub").exists()
238238
assert (LOCALPATH / "sub" / "secret").exists()
239239

240-
= Parent traversal and absolute names are rejected
241-
242-
from scapy.layers.smb2 import FILE_ID_BOTH_DIR_INFORMATION
243-
from scapy.layers.smbclient import smbclient
244-
245-
root = pathlib.Path(get_temp_dir())
246-
download = root / "download"
247-
outside = root / "traversal.txt"
248-
absolute = root / "absolute.txt"
249-
inside = download / "ordinary.txt"
250-
attributes = FILE_ID_BOTH_DIR_INFORMATION(
251-
FileAttributes="FILE_ATTRIBUTE_ARCHIVE"
252-
).FileAttributes
253-
254-
client = object.__new__(smbclient)
255-
client.current_tree = 1
256-
client.ls = lambda parent=None: [
257-
("../traversal.txt", attributes, 1, 0),
258-
(str(absolute), attributes, 1, 0),
259-
("ordinary.txt", attributes, 1, 0),
260-
]
261-
client._get_file = lambda _remote, fd: fd.write(b"X")
262-
263-
client._getr(pathlib.PureWindowsPath("pub"), download, _verb=False)
264-
265-
assert not outside.exists()
266-
assert not absolute.exists()
267-
assert inside.read_bytes() == b"X"
268-
269240
+ SMB2 Server tests
270241
~ linux smbserver samba
271242

@@ -510,54 +481,6 @@ with run_smbserver(readonly=False, encryptshare=True):
510481
finally:
511482
cli.close()
512483

513-
= smbclient: reject guest session when transport protection is required
514-
515-
import socket
516-
517-
from scapy.error import Scapy_Exception
518-
from scapy.layers.smbclient import smbclient
519-
from scapy.layers.smbserver import SMB_Server
520-
521-
socket.TCP_KEEPIDLE = getattr(socket, "TCP_KEEPIDLE", socket.TCP_KEEPALIVE)
522-
socket.TCP_KEEPINTVL = getattr(socket, "TCP_KEEPINTVL", 0x101)
523-
524-
def run_guest_session(**requirement):
525-
with socket.socket() as sock:
526-
sock.bind(("127.0.0.1", 0))
527-
port = sock.getsockname()[1]
528-
server = SMB_Server.spawn(
529-
port=port,
530-
iface=conf.loopback_name,
531-
bg=True,
532-
verb=False,
533-
MAX_DIALECT=0x0302,
534-
)
535-
client = None
536-
try:
537-
client = smbclient(
538-
"127.0.0.1",
539-
guest=True,
540-
port=port,
541-
cli=False,
542-
timeout=3,
543-
MAX_DIALECT=0x0302,
544-
**requirement,
545-
)
546-
return None
547-
except Exception as ex:
548-
return ex
549-
finally:
550-
if client is not None:
551-
client.close()
552-
server.close()
553-
554-
assert run_guest_session() is None
555-
for requirement in ({"REQUIRE_SIGNATURE": True}, {"REQUIRE_ENCRYPTION": True}):
556-
error = run_guest_session(**requirement)
557-
assert isinstance(error, Scapy_Exception)
558-
assert "guest session" in str(error).lower()
559-
560-
561484
+ Windows-only SMB tests
562485
~ windows
563486

0 commit comments

Comments
 (0)