1

I have a script, which I need to execute with sudo.

#!/bin/bash

cp "$@" /destionation/dir

Is it a good script or someone can bypass the restriction destination dir ?

Thanks for suggestions.

1 Answer 1

0

Well, there's a small typo: /destionation instead of /destination.

There are security issues with this script.

A user could pass `sudo /bin/bash` as the filename, and then they would have a root shell.

They can also nest commands, such as:

`sudo /bin/bash; echo "hello" >> /tmp/from_root`

To form any set of operations that run as the root user.

I'd recommend against using this script because not only does the destination directory not matter, but you have bigger issues.

A possibly better solution is to create a directory that is world-writable so that you don't need the sudo permissions.

1
  • Testing this, it doesn't seem to work for me. I have a script that does echo "$@", but ./script '`echo $0`' returns _`echo $0` (without the underscore). Same with ./script \`echo \$0\` . Does bash automatically escape the arguments it passes to scripts?
    – Zaz
    Commented Aug 6, 2014 at 11:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .