[mod_python] os.system-not working

deepak battu deepak.battu at yahoo.co.in
Mon May 28 03:46:31 EDT 2007


Thank you Graham , it resolved the problem
  i changed the command to 
  cmd = "/usr/bin/nmap -O " + myip + "> /tmp/tmp.txt 2>&1"
 and the error came like no root priviliges. 
 so i changed the priviliges of  nmap  , using  chmod +s /usr/bin/nmap
and now it is working.

----- Original Message ----
From: Graham Dumpleton <graham.dumpleton at gmail.com>
To: deepak battu <deepak.battu at yahoo.co.in>
Cc: mod_python <mod_python at modpython.org>
Sent: Monday, 28 May, 2007 2:22:50 AM
Subject: Re: [mod_python] os.system-not working

On 27/05/07, deepak battu <deepak.battu at yahoo.co.in> wrote:
>
> hello graham,
> i have tried it by using the absolute path like this :
>     cmd = "/usr/bin/nmap -O " + myip + "> /tmp/tmp.txt"
>     os.system(cmd)
> but no change.

Change your command to:

     cmd = "/usr/bin/nmap -O " + myip + "> /tmp/tmp.txt 2>&1"
     os.system(cmd)

This will ensure that standard error is also capture into output file
and you can then maybe see what is going wrong with your command line.

Another option is to have:

  import sys
  sys.stderr.flush()

immediately after os.system call to ensure that any standard error
messages are properly flushed through to Apache log.

Also suggest you log then actual command being run to the Apache error
log before you do it. Ie.,

     cmd = "/usr/bin/nmap -O " + myip + "> /tmp/tmp.txt 2>&1"
     apache.log_error('RUNNING: ' + cmd)
     os.system(cmd)

Then you can see what what is being run is what you expect.

Note, please use reply-all so discussion stays on the mailing list as
others may have ideas.

Graham

>  i have votice that this thing worked for another command:
>    cmd = "/usr/bin/nmap -sP " + myip + "> /tmp/tmp.txt"
>      os.system(cmd)
>
> and coming to the myip variable it is giving the correct ip .
> plz help me.
>
>
> ----- Original Message ----
> From: Graham Dumpleton <graham.dumpleton at gmail.com>
> To: deepak battu <deepak.battu at yahoo.co.in>
> Cc: mod_python at modpython.org
> Sent: Sunday, 27 May, 2007 4:54:28 PM
> Subject: Re: [mod_python] os.system-not working
>
> On 27/05/07, deepak battu <deepak.battu at yahoo.co.in> wrote:
> >
> > cmd = "nmap -O " + myip + ">
> > /usr/local/apache2/htdocs/test/temp/tmp.txt"
> >  os.system(cmd)
> >
> >  Iran this code in python it is working but when i run this in mod_python
> > through apache it is not showing any errors but not giving the correct
> > result. plz help me.
>
> Specify an absolute path for the location of 'nmap' because Apache
> runs with a quite restrictive PATH and thus the program may not be
> able to be found.
>
> Also, Apache runs as a special user which may not have write access to
> where you are trying to write the output. Try writing the output file
> to /tmp instead.
>
> Finally, I hope your 'myip' value isn't being supplied through a user
> editable field in a form because if it has you have just exposed your
> box in a way that a remote user could execute arbitrary commands on
> your box.
>
> Graham
>
>
>  ________________________________
>  Download prohibited? No problem! CHAT from any browser, without download.







      Did you know? You can CHAT without downloading messenger. Click here http://in.messenger.yahoo.com/webmessengerpromo.php
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20070528/ff4160bf/attachment.html


More information about the Mod_python mailing list