| 1 |
|
| 2 |
import socket |
| 3 |
|
| 4 |
from rsyncfns import SCRATCHDIR, claim_ports, require_tcp, start_rsyncd, test_fail |
| 5 |
|
| 6 |
PORT = 12934 |
| 7 |
require_tcp("raw malicious daemon client needs a real TCP daemon; run with --use-tcp") |
| 8 |
claim_ports(PORT) |
| 9 |
|
| 10 |
mod = SCRATCHDIR / 'argv-mod' |
| 11 |
mod.mkdir(parents=True, exist_ok=True) |
| 12 |
conf = SCRATCHDIR / 'argv-limit.conf' |
| 13 |
log = SCRATCHDIR / 'argv-limit.log' |
| 14 |
conf.write_text(f"""\ |
| 15 |
pid file = {SCRATCHDIR}/rsyncd.pid |
| 16 |
use chroot = no |
| 17 |
log file = {log} |
| 18 |
|
| 19 |
[mod] |
| 20 |
path = {mod} |
| 21 |
read only = yes |
| 22 |
""") |
| 23 |
start_rsyncd(conf, PORT) |
| 24 |
|
| 25 |
with socket.create_connection(('127.0.0.1', PORT), timeout=5) as s: |
| 26 |
greeting = s.recv(4096) |
| 27 |
if not greeting.startswith(b'@RSYNCD:'): |
| 28 |
test_fail(f"unexpected daemon greeting: {greeting!r}") |
| 29 |
s.sendall(b'@RSYNCD: 31.0\n') |
| 30 |
s.sendall(b'mod\n') |
| 31 |
ok = s.recv(4096) |
| 32 |
if b'@RSYNCD: OK' not in ok: |
| 33 |
test_fail(f"daemon did not accept test module: {ok!r}") |
| 34 |
|
| 35 |
payload = b''.join(b'a%05d\0' % i for i in range(17000)) + b'\0' |
| 36 |
s.sendall(payload) |
| 37 |
try: |
| 38 |
s.recv(4096) |
| 39 |
except (ConnectionResetError, BrokenPipeError): |
| 40 |
pass |
| 41 |
|
| 42 |
text = log.read_text(errors='replace') |
| 43 |
if 'too many daemon arguments' not in text: |
| 44 |
test_fail("daemon did not reject the malicious client's oversized argv list") |
| 45 |
|
| 46 |
print("daemon-argv-limit: malicious client argv flood is rejected") |