#!/usr/bin/env python3 # MOLO-CLI-001: shell command injection in `molo new `. See README.md. import os import subprocess import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib")) import molo_audit as m def main(): m.arm_watchdog(30) if not os.path.exists(m.MOLO): m.verdict_skip("%s not built (run make)" % m.MOLO) tmp = m.scratch_dir() marker = os.path.join(tmp, "pwned") name = 'x"; touch %s; echo "' % marker # breaks out of the double-quoted -C arg subprocess.run([m.MOLO, "new", name, "--force"], cwd=tmp, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=20) if os.path.exists(marker): m.verdict_fail( "`molo new %r` ran an injected `touch` command via the unescaped " "system(\"git -C \\\"\" + dir + \"\\\" init ...\") call in " "src/cli/cli/scaffolder.cpp; the project name reaches a shell with no " "quoting beyond a single pair of double quotes" % name ) m.verdict_pass("the injected command did not run; scaffolder.cpp no longer " "passes the project name through a shell unescaped") if __name__ == "__main__": main()