| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import os |
| 10 |
import subprocess |
| 11 |
|
| 12 |
from rsyncfns import SCRATCHDIR, SRCDIR, rmtree, rsync_argv, test_fail, rsh_cmd |
| 13 |
|
| 14 |
base = SCRATCHDIR / 'remote-shell-newline' |
| 15 |
rmtree(base) |
| 16 |
src = base / 'src' |
| 17 |
src.mkdir(parents=True) |
| 18 |
(src / 'f').write_text('payload\n') |
| 19 |
sentinel = base / 'pwned' |
| 20 |
|
| 21 |
env = os.environ.copy() |
| 22 |
env['RSYNC_RSH'] = rsh_cmd(None, '--no-cd') |
| 23 |
dest = f"lh:{base}/dest\ntouch {sentinel}\n#" |
| 24 |
subprocess.run(rsync_argv('-a', f'{src}/', dest), |
| 25 |
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=env) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
if sentinel.exists(): |
| 33 |
test_fail("remote-shell newline injection executed the sentinel command") |
| 34 |
if (base / 'dest').exists(): |
| 35 |
test_fail("remote-shell newline split the destination " |
| 36 |
"(eval ran the server into base/dest as a separate command)") |
| 37 |
|
| 38 |
print("remote-shell-newline-escaping: newline in a remote arg is quoted, not executed") |