| 1 |
|
| 2 |
"""A write client must not use a forged dot entry to wipe a daemon module.""" |
| 3 |
|
| 4 |
import time |
| 5 |
|
| 6 |
from rsyncfns import ( |
| 7 |
SCRATCHDIR, claim_ports, makepath, require_tcp, rmtree, start_rsyncd, |
| 8 |
test_fail, |
| 9 |
) |
| 10 |
import rsync_proto as rp |
| 11 |
|
| 12 |
PORT = 13013 |
| 13 |
|
| 14 |
require_tcp("the malicious daemon client needs a real TCP socket; run with --use-tcp") |
| 15 |
claim_ports(PORT) |
| 16 |
|
| 17 |
base = SCRATCHDIR / 'daemon-dot-file-force-wipe' |
| 18 |
rmtree(base) |
| 19 |
mod = base / 'mod' |
| 20 |
makepath(mod / 'private') |
| 21 |
sentinel = mod / 'private' / 'must-survive' |
| 22 |
sentinel.write_text('pre-existing module data\n') |
| 23 |
|
| 24 |
conf = base / 'rsyncd.conf' |
| 25 |
conf.write_text(f"""\ |
| 26 |
pid file = {base}/rsyncd.pid |
| 27 |
use chroot = no |
| 28 |
|
| 29 |
[mod] |
| 30 |
path = {mod} |
| 31 |
read only = no |
| 32 |
write only = yes |
| 33 |
refuse options = delete |
| 34 |
""") |
| 35 |
start_rsyncd(conf, PORT) |
| 36 |
|
| 37 |
s = rp.DaemonClient('127.0.0.1', PORT) |
| 38 |
s.handshake( |
| 39 |
'mod', |
| 40 |
['--server', '-re.LsfxCIu', '--force', '--no-inc-recursive', '.', 'mod/'], |
| 41 |
greeting_version=30, |
| 42 |
) |
| 43 |
s.send_flat_flist([ |
| 44 |
rp.FileEntry('.', mode=rp.S_IFREG | 0o644, length=0), |
| 45 |
]) |
| 46 |
s.drain(timeout=5) |
| 47 |
s.close() |
| 48 |
|
| 49 |
for _ in range(50): |
| 50 |
if not sentinel.exists(): |
| 51 |
break |
| 52 |
time.sleep(0.02) |
| 53 |
|
| 54 |
if not sentinel.exists(): |
| 55 |
test_fail( |
| 56 |
'write-only client bypassed refuse-options=delete by sending a regular ' |
| 57 |
'dot entry with --force and recursively wiped the daemon module root') |
| 58 |
|
| 59 |
print('daemon-dot-file-force-wipe: daemon rejected a non-directory dot root ' |
| 60 |
'from a write-only client') |