Search code examples
phplinuxnginxshell-execnmap

Trying to execute the following command shell_exec("sudo /usr/bin/nmap -n -sn ".$_SERVER['REMOTE_ADDR']) but it returns NULL


I'm running

  • nginx 1.17.4
  • php 7.4
  • arch linux 5.4.2

Trying to execute the following command to get my user MAC address from IP (this script will run on my lan server) and $_SERVER['REMOTE_ADDR'] does return a valid ip

shell_exec("sudo /usr/bin/nmap -n -sn ".$_SERVER['REMOTE_ADDR'])

But it returns null so I tried the following to get a more info

shell_exec("sudo /usr/bin/nmap -n -sn ".$_SERVER['REMOTE_ADDR'] ." 2>&1")

And got the following: sudo: effective uid is not 0, is sudo installed setuid root?

I don't understand why I get this error because I have added the following in my sudder file

http ALL=NOPASSWD: /usr/bin/nmap

I've modified my passwd to allow login from HTTP to try it in shell and it works but not when I run it in the browser.

Help please!

Thanks


Solution

  • since my server is arch linux I decide to go ask in that arch forum and found was able to fix my issue. so for anybody interested please view

    https://bbs.archlinux.org/viewtopic.php?pid=1877560#p1877560

    Basically for me it was changing the php-fpm service file to the following

    /etc/systemd/system/multi-user.target.wants/php-fpm.service
    
    Set NoNewPrivileges=false
    
    comment CapabilityBoundingSet