| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import os |
| 10 |
import subprocess |
| 11 |
|
| 12 |
from rsyncfns import ( |
| 13 |
SCRATCHDIR, TOOLDIR, |
| 14 |
assert_exists, assert_not_exists, rmtree, test_fail, test_skipped, |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
mod = SCRATCHDIR / 'module' |
| 19 |
trap_outside = SCRATCHDIR / 'trap' |
| 20 |
rmtree(mod) |
| 21 |
rmtree(trap_outside) |
| 22 |
mod.mkdir(parents=True) |
| 23 |
trap_outside.mkdir(parents=True) |
| 24 |
|
| 25 |
os.symlink('../trap', mod / 'escape_link') |
| 26 |
|
| 27 |
(mod / 'poc-top-to-escape').write_text("poc-top-to-escape\n") |
| 28 |
(trap_outside / 'poc-outside-source').write_text("poc-outside-source\n") |
| 29 |
(mod / 'fixed-top-to-escape').write_text("fixed-top-to-escape\n") |
| 30 |
(trap_outside / 'fixed-outside-source').write_text("fixed-outside-source\n") |
| 31 |
|
| 32 |
proc = subprocess.run([str(TOOLDIR / 't_rename_secure'), '--poc', str(mod)]) |
| 33 |
if proc.returncode == 77: |
| 34 |
test_skipped("t_rename_secure --poc skipped") |
| 35 |
if proc.returncode != 0: |
| 36 |
test_fail("t_rename_secure --poc reported failures (see stderr above)") |
| 37 |
|
| 38 |
|
| 39 |
assert_exists(trap_outside / 'vuln-created', |
| 40 |
"PoC did not create outside file via vulnerable destination-parent rename") |
| 41 |
assert_exists(mod / 'vuln-stolen', |
| 42 |
"PoC did not move outside file into module via vulnerable source-parent rename") |
| 43 |
|
| 44 |
|
| 45 |
assert_not_exists(trap_outside / 'fixed-created', |
| 46 |
"fixed do_rename_at created outside file") |
| 47 |
assert_exists(mod / 'fixed-top-to-escape', |
| 48 |
"fixed do_rename_at consumed protected module source") |
| 49 |
assert_exists(trap_outside / 'fixed-outside-source', |
| 50 |
"fixed do_rename_at consumed protected outside source") |
| 51 |
assert_not_exists(mod / 'fixed-stolen', |
| 52 |
"fixed do_rename_at moved outside file into module") |