Show HN: Run unknown shell script with a line-by-line confirmation prompt
gist.github.com
gist.github.com
#!/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.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.
The argument doesn't rely on infinite memory.
In real systems external inputs provide an infinite source of "memory" to read from.
(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.
> # 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.https://www.gnu.org/software/bash/manual/html_node/The-Restr...
Can you provide example of a scenario where this restricted shell is useful?
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.
1. You probably will need network to run whatever script this is. Once you give the script network access, you are open to a whole bunch of issues. Perhaps your ssh private keys leave your system for example.
2. If you don't give it network access, it probably won't do anything malicious. Most of these scripts exist just to download some "thing", install it, maybe run it, and maybe update an RC file. The malicious code might be in the executables downloaded by the script rather than the script itself.
3. Just because a script does something reasonable in a VM doesn't mean it isn't malicious and won't do something else when it is run on bare metal.
In the end, you have to trust whatever software you decide to run (scripts included). How you gain that trust is up to you. I would steer away from gaining that trust by running the script and seeing what happens. Personally, I just rely on the reputation of the source of the software.
Verifying that some script doesn't screw up the configuration of my machine is a different story. I hate it when some script decides to run "pip install" or some other thing that subverts my package manager. Here, taking a snapshot is a reasonable choice.
accept_whatsapp_terms_and_conditions="true"
Run command? [Y/n]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."
Fortunately, my terminal emulator doesn't run on paste.
The entire newline-inclusive text is pasted into the terminal and nothing is run until I hit Return.
Input: https://pastebin.com/LpDW2r0d
Result: https://streamable.com/94z5oq
But if the site is nefarious it can adjust my copy so that I copy a mailious command rather than the one I verified.
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?
* Ancient script written by people at the company no longer here that may encode a bunch of assumptions and lots of dead code
* Personal script that is not to the level of full production
* Run untrusted script in a constrained environment to see at what stage it does something ugly - this will bypass obfuscation based on adding lots of dead code
That's like 3 things I already thought of while writing this comment. In like the 90 s it took me to compose this. These ostentatiously dramatic comments of yours aren't that interesting. Hopefully coming generations of engineers will look at your comments and be like "I wish I wasn't like that".
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.