Open leogr opened 2 months ago
I am rooting for this new feature! Unfortunately, sometimes we can't make rules precisely on a syscall, and we end up building it on the command line (proc.cmdline
) which is most of the time very tricky and easily bypassable for a number of reasons:
a b c
). Some tools will allow -abc
, -a -b -c
or also any other combination (like -bca
). Nowadays, we should enumerate all the possible sequences to detect this. (n, t) in getopt(proc.args, "nt:")
would totally solve this use case.startswith
, endswith
or even contains
) just on the value of the option and not the whole command line. So I strongly support also implementing getopt(proc.args, "nt:")[t] = val
. Not sure if it can be implemented this way due to the []
but we can certainly think about how to make it happenLastly, if we are going in this direction, I would say that implementing getopt_long
shouldn't be that hard and will let us complete the picture of making stronger detections on command line arguments. 🎉
Motivation
By introducing a transformer that works like the C
getopt()
function, rules authors can more easily match and handle POSIX command-line arguments. This addition will streamline the creation of rules involving command-line options, ensuring greater flexibility and accuracy in rule writing.Feature
Introduce a
getopt(<args>, <optstring>)
transformer to handle command-line arguments, mimicking the functionality of the Cgetopt()
function.Usage examples:
(n, t) in getopt(proc.args, "nt:")
getopt(proc.args, "nt:")[t] = val
getopt(proc.args, "nt:") intersects (n, t)
Alternatives
Doing nothing and sticking with the current way of handling this does not seem a compelling alternative:
Additional context
Design consideration: it is yet to be decided whether the
getopt(<args>, <optstring>)
transformer should mimic thegetopt_long()
function (which also accepts long options starting with two dashes) or if bothgetopt
andgetopt_long
transformers should be introduced. This design choice can be deferred to the implementation stage.References:
cc @darryk10 @loresuso