0

I'm not familar with zenity or shell-exec so I may have made a silly mistake...

The following command line works in an Ubuntu terminal window;

PASSWD="$(zenity --password --title=Authentication)"; echo -e $PASSWD | sudo -S nmap -A 192.168.0.1-255;

It puts up a GUI dialogue box to ask for the password and then nmap runs correctly.

If I put the following code in a php file on my local machine, served by Apache:

$network = '192.168.0.1-255';
$cmd = 'PASSWD="$(zenity --password --title=Authentication)"; echo -e $PASSWD | sudo -S nmap -A ' . $network;
echo $cmd;
$output3 = rtrim(shell_exec($cmd));
echo ($output3);

then $cmd is output as

PASSWD="$(zenity --password --title=Authentication)"; echo -e $PASSWD | sudo -S nmap -A 192.168.0.1-255 

but nothing else happens.

I looked at run zenity from php and tried giving this command first from a terminal:

xhost local:www-data

but that did not help.

Running, for example, "ls" from shell_exec works fine.

I would welcome any suggestions.

3 Answers 3

0

I would use this:

pkexec nmap -A 192.168.0.1-255

pkexec replaces gksudo in newer distributions.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I will need to research how to set up pkexec. Your example as shown does nothing from within php.
0

@danielsedoff I created a file "com.ubuntu.pkexec.nmap.policy" in folder /usr/share/polkit-1 with these contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
  "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
  "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>

  <action id="com.ubuntu.pkexec.nmap">
    <defaults>
      <allow_any>yes</allow_any>
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
    <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/nmap</annotate>
  </action>

</policyconfig>

The command in my php file

pkexec --user root nmap -A 192.168.0.1-255

now works as I hoped without needing interactive authorisation from the user. Thanks.

Comments

0

You can try this This will help you to find the shell_exec function errors:

Add 2>&1 to you Command

Check the below changes:

$network = '192.168.0.1-255';
$cmd = 'PASSWD="$(zenity --password --title=Authentication)"; echo -e $PASSWD | sudo -S nmap -A ' . $network.' 2>&1 ';
echo $cmd;
$output3 = rtrim(shell_exec($cmd));
echo ($output3);

Tryout out the above code . i have added 2>&1 at the end of $cmd.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.