Subprocess quote problem

A

Adriano Monteiro

Hi Folks,

I'm working on a script that executes a command with arbitrary
options. Most of its options works fine with subprocess, but at least
one (as far as I know) is giving me a headache. The program that I'm
trying to execute is Nmap, and the problematic option is the -iL, that
is used to indicate a file with the targets that nmap should scan.

If I open my terminal, and write: nmap -iL "/tmp/target_list" , nmap
picks the file, read it and scan every target written inside it.

But, if I try to use the same scan on my command execution script, it
makes nmap raise a strange error:

"Failed to open input file "/home/adriano/umit/test/targets" for reading
QUITTING!"


This is not a permission issue. I put this target_file file on /tmp
and set chmod 777 on it.


The script:

<code>
_stdout_handler = open(self.stdout_output, "w+")
_stderr_handler = open(self.stderr_output, "w+")
command = ['nmap', '-T', 'Aggressive', '-n', '-F', '-iL',
'"/home/adriano/umit/test/targets"']

command_process = Popen(command, bufsize=1,
stdin=PIPE,
stdout=_stdout_handler.fileno(),
stderr=_stderr_handler.fileno(),
shell=False)
</code>

The problem seens to be the double quoted path. But it doesn't make
any sense for me, as any other command that I put there works fine.

Any clue?


Cheeers!

--
Adriano Monteiro Marques
http://umit.sourceforge.net
(e-mail address removed)

"Don't stay in bed, unless you can make money in bed." - George Burns
 
L

Lawrence D'Oliveiro

"Failed to open input file "/home/adriano/umit/test/targets" for reading
QUITTING!"

Which is not the same as saying:

"Failed to open input file /home/adriano/umit/test/targets for reading
QUITTING!"

Spot the difference?
command = ['nmap', '-T', 'Aggressive', '-n', '-F', '-iL',
'"/home/adriano/umit/test/targets"']

Why exactly where you putting quotes within quotes in the path? That kind of
thing is only necessary when typing things on the shell command line, to
prevent the shell itself misinterpreting things, like putting word breaks
in the wrong places or having wrong behaviours triggered by special
characters.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top