make a password protected bash script resist/refus

2019-07-25 04:02发布

问题:

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored.

The code:

read -p 'Script: ' S &&
  C=$S.crypt \
  H='eval "$((dd if=$0 bs=1 skip=//|gpg -d) 2>/dev/null)";
    exit;' &&
  gpg -c<$S | cat >$C <(echo $H | sed s://:$(echo "$H" | wc -c):) - \
    <(chmod +x $C)

回答1:

Given that it is an interpreted script that at some point must be loaded into memory and interpreted it is impossible to completely avoid anyone being able to dump out the contents of the script. It can easily be achieved i.e. with a wrapper script around the bash executable...