This script wants to modify:
- /usr/local/program/*
- /etc/program/*
- $HOME/.program
Do you want to execute this? [Yes/No]
..because you know, what happens when you execute a script that does rm -rf /usr in the 100th step?
That doesn't mean what you want is completely unattainable, you just need to figure out whether you're okay with false positives, false negatives, or your tool just giving up on certain scripts (or some combination thereof).
Such a static analyser would have two interesting aspects: on the end user side, the one mentioned of outputting the touched paths, and also doubling as being a linter for the script developer.
But if you run it first in the container to see whether is does anything bad and then run it on the host (or a more valuable container), no.
The script might check whether it runs in a container. It might depend on the wall clock time. On /dev/urandom, whatever. As somebody already mentioned, the halting problem. No can do.
(you know, like proprietary drivers almost always do)
It would be a huge improvement for sysadmins if a linter could be run in advance of executing a shell script, and use chroot and other sandboxing like creating a user without net cap rights etc in case it found something potentially malicious.
This would still allow the script to steal data though, as installer script generally require internet access.
It's basically, "get off the shoulders of giants. If you aren't expert enough to detect exploits in <lang> then you're not worthy enough."
How would you ever begin a career, let alone become a desirable team member?
Do you run on Gentoo? and presumably read the millions of lines of code your machine is running on?
People have been downloading and running executables almost pretty much as as the internet has been around... and the world is still going 'round.
That's really the only use case for this tool that I could get behind, and I commend you for your diligence.
Or just, you know, read them before you run them.
"Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something."
It would be interesting if you could mount the snapshot then attempt to merge in the changes to the live system once approved. I don't know if any filesystems that support merges though.
#!/bin/sh
rm not ^H^H^H^H expected
Gives: -> rm expected
Run command? [Y/n]
rm: cannot remove 'not': No such file or directory
rm: cannot remove ''$'\b\b\b\b': No such file or directory
rm: cannot remove 'expected': No such file or directoryThis script, for example looks sort of innocuous when run through your tool because it's not obvious the HEREDOC is going to the stdin of a Perl interpreter. Your tool shows them like they are two separate things that don't do much by themselves.
Looking at the script itself, it's more obvious.
#!/bin/sh
cat<<'EOF'|perl -nE'BEGIN{shift(@ARGV)}s#(.*)#$1#ee' /dev/null
say "hello"; #arbitrary perl code
EOF
That's probably a nit, really, though. I don't know that anyone would target it on purpose.https://www.gnu.org/software/bash/manual/html_node/The-Restr...
Can you provide example of a scenario where this restricted shell is useful?
> # Ask for only a single character of input, so the user does not need to type an extra enter
plus
> echo "Please answer by typing n (for no), y (for yes), or Enter (also for yes)"
seem like it will lead to “y[enter]” so you accidentally accept a second line before you read it.
I made a little demonstration script.
deno run --prompt https://crux.land/4Lc2E2
Spoiler: https://share.getcloudapp.com/ApuYR00w if you can't run above. accept_whatsapp_terms_and_conditions="true"
Run command? [Y/n]