diff --git a/intercept/argv_compound.go b/intercept/argv_compound.go index 0d85d30..f640b40 100644 --- a/intercept/argv_compound.go +++ b/intercept/argv_compound.go @@ -737,17 +737,40 @@ func flockMatchesArgv(rule []string, args []callWord, depth int) bool { // parallel's input separators (:::, :::+, ::::, ::::+), and matches the // wrapped command (including single-string shell commands like // "parallel 'nmap -p 80 {}' ::: target"). +// +// When no command precedes ":::", GNU parallel executes each argument after +// ":::" as a command line, so each literal argument up to the next separator +// is parsed as a Bash line at depth+1. +// +// Note: "parallel -a FILE" / "--arg-file FILE" and "parallel :::: FILE" read +// command lines from a file that the matcher does not read. func parallelMatchesArgv(rule []string, args []callWord, depth int) bool { + isParallelSep := func(w callWord) bool { + return w.Literal && (w.Value == ":::" || w.Value == ":::+" || w.Value == "::::" || w.Value == "::::+") + } for _, cand := range stripOneWrapperCandidates("parallel", args) { end := len(cand) for idx, w := range cand { - if w.Literal && (w.Value == ":::" || w.Value == ":::+" || w.Value == "::::" || w.Value == "::::+") { + if isParallelSep(w) { end = idx break } } cmd := cand[:end] if len(cmd) == 0 { + // No command before separator: for ":::" each following literal + // argument (until any subsequent separator) runs as a command line. + // For ":::+", "::::", and "::::+", do not guess. + if end < len(cand) && cand[end].Literal && cand[end].Value == ":::" && depth < argvMaxNestedPayloads { + for _, arg := range cand[end+1:] { + if isParallelSep(arg) { + break + } + if arg.Literal && bashCommandMatchesArgv(rule, arg.Value, depth+1) { + return true + } + } + } continue } if callMatchesArgv(rule, cmd, depth) { diff --git a/intercept/argv_compound_test.go b/intercept/argv_compound_test.go index 4a4fb0a..4e18d93 100644 --- a/intercept/argv_compound_test.go +++ b/intercept/argv_compound_test.go @@ -79,6 +79,10 @@ func TestArgvDenyAndAskCompoundAndWrapped(t *testing.T) { {"parallel bare", "parallel nmap"}, {"parallel with jobs and :::", "parallel -j 4 nmap -p 80 {} ::: 10.0.0.1"}, {"parallel quoted shell string", "parallel -j 4 'nmap -p 80 {}' ::: 10.0.0.1"}, + {"parallel no command ::: bare", "parallel ::: nmap"}, + {"parallel no command ::: quoted line", `parallel ::: "nmap -p 80 x"`}, + {"parallel no command -j2 ::: bare", "parallel -j2 ::: nmap"}, + {"parallel no command ::: multiple lines", "parallel ::: echo nmap"}, {"busybox", "busybox nmap -p 80 x"}, {"busybox sh -c", "busybox sh -c 'nmap -p 80 x'"}, {"chroot", "chroot / nmap -p 80 x"}, @@ -157,6 +161,10 @@ func TestArgvDenyAndAskCompoundAndWrapped(t *testing.T) { {"shell -- before -c treats -c as script", "bash -- -c 'nmap -p 80 x'"}, {"find -exec echo nmap", `find . -exec echo nmap \;`}, {"parallel echo with nmap input", "parallel echo ::: nmap"}, + {"parallel no command ::: echo nmap quoted", `parallel ::: "echo nmap"`}, + {"parallel echo nmap ::: x", "parallel echo nmap ::: x"}, + {"parallel :::: file input", "parallel :::: nmap"}, + {"parallel :::+ separator", "parallel :::+ nmap"}, {"chroot without command", "chroot /"}, {"busybox list mode", "busybox --list"}, {"eval opaque leading arg", "eval $CMD nmap"},