Escaping shell commands

I

Inspector Chan

Hi,

I'm using some external data on shell commands which are to be
executed with os.system (other functions doesn't provide enough
flexibility for executing these shell lines).

So I have decided to user re.escape() for escaping these data before
using it on the created command lines.

Quick example:

malicious external data in var 'data':

data= '; touch /home/user/I0wnzu'

shell command to be executed is 'command':

command= 'echo I am so happy' + re.escape(data)

This way the generated shell lines is:

echo I am so happy\;\ touch\ \/home\/user\/I0wnzu

With this example it looks safe... But I'm not quite sure about this
method of escaping input.

¿Is this breakable?
If so... ¿how?
¿Does anyone knows a better way to get this done?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top