了shell_exec不是在PHP网站申请工作 [英] shell_exec not working in php web appl

查看:104
本文介绍了了shell_exec不是在PHP网站申请工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了检测网络interfagces那么它检测到IP地址,子网掩码,广播地址每个接口一个shell脚本,然后它使一个ping到所有的IP地址为这个网络接口。

该脚本执行权限。通常情况下,该脚本将保存在一个名为resultat,但文件的网络接口列表了(eth0 eth1的为wlan0),当我从PHP的了shell_exec 命令一个网页运行此脚本(回声为www数据的用户密码| / usr / lib目录/ cgi-bin目录/须藤-S global.sh斌/庆典/)不产生输出。

如果我运行相同的脚本,用户 www数据终端,结果文件正确填充。

脚本:

 #!/斌/庆典
  #####paramères亲戚联接太子港点菜基地去最近搜索
  HOST_BDD =本地主机
  LOGIN =根
  PASSWD =密码
  NOM_BDD =dbnessus
  ##### CES requettes倒vider莱表前卫德放任拉检测
  vider2 =TRUNCATE machine_connecte
  回声$ vider2 |在/ usr /斌/ MySQL的-h $ HOST_BDD
  -u $ LOGIN -p $ PASSWD -s $ NOM_BDD  vider1 =TRUNCATE接口
  回声$ vider1 |在/ usr /斌/ MySQL的-h $ HOST_BDD
  -u $ LOGIN -p $ PASSWD -s $ NOM_BDD  初始化=ALTER TABLE machine_connecte AUTO_INCREMENT = 0
  回声$初始化|在/ usr /斌/ MySQL的-h $ HOST_BDD
  -u $ LOGIN -p $ PASSWD -s $ NOM_BDD
  ################################################## #####  /usr/lib/cgi-bin/get_interface.sh> / usr / lib目录/ cgi-bin目录/ liste_interfaces
  而读线;
  做  IP = $(/ usr / lib目录/ cgi-bin目录/ get_ip.sh $线)
  面膜= $(/ usr / lib目录/ cgi-bin目录/ get_netmask.sh $线)
  BCAST = $(/ usr / lib目录/ cgi-bin目录/ get_bcast.sh $线)
  ### fonction is_alive_ping
  is_alive_ping()
  {
    平-i 100 -c 1 $ 1>的/ dev / null的2 - ;的/ dev / null的
   [$? -eq 0]放大器;&安培;回声$ I>> / usr / lib目录/ cgi-bin目录/ resultat
  }
  猫的/ dev / null的> / usr / lib目录/ cgi-bin目录/ resultat;
  #########
  ###师宫德八位德住址broadcst
  如果[$ IP!=]
  然后
  I1 =$(回声$ BCAST |切-d,-f1)。
  I2 =$(回声$ BCAST |切-d-f2)。
  I3 =$(回声$ BCAST |切-d,-f3)。
  I4 =$(回声$ BCAST |切-d,-f4)。
  科幻
  ### {主机ID / NETWORKID} / CLASSE杜网格  ##################### A.255.255.255 CLASSE一个
  如果[$ I2==255]
  然后
因为我在$ I1。{1..25​​4}。{1..25​​4} {} 1..25​​4

is_alive_ping $ I和断绝关系
DONE
  科幻
  ##################### A.B.255.255 CLASSE乙
  如果[$ I2=255!]&功放;&安培; [$ I3==255]
  然后
因为我在$ I1。$ I2。{1..25​​4} {} 1..25​​4

is_alive_ping $ I和断绝关系
DONE
  科幻
  ##################### A.B.C.255 CLASSEÇ
  如果[$ I2=255!]&功放;&安培; [!$ i3的=255]&放大器;&放大器; [$ 0-14==255]
  然后
因为我在$ I1,I2 $,$ I3。{} 1..25​​4

is_alive_ping $ I和断绝关系
    DONE
  科幻
  ################
而读ip_up;

主机名= $(在/ usr /斌/ -s的resolveip $ ip_up 2 - ;的/ dev / null的)
如果[$主机名==]
然后
主机名=*
科幻
MAC = $(/ usr / sbin目录/ ARP -a $ ip_up |切-d,-f4)
如果[$ ip_up==$ IP]
然后
MAC = $(/ sbin目录/使用ifconfig $线| grep的的HWaddr'| grep的-v127.0.0.1| awk的'{打印$ 5}')
科幻
OS = $(在/ usr /斌/ NMAP -A $ ip_up | grep的服务信息| awk的'{$打印4,$ 5}')
如果[$ OS==的Unix和Linux] || [$ OS==的Linux]
然后
OS =的Linux
ELIF [$ OS==视窗]
然后
OS =视窗
其他
OS =*
科幻
 #SQL1 =INSERT INTO dbnessus.interfaces(nom_interface)VALUES('$行');
 SQL1 =INSERT INTO忽略dbnessus.interfaces(nom_interface)VALUES('$行');
 SQL2 =INSERT INTO dbnessus.machine_connecte(idmachine,ip_mach,mask_mach,
 nom_mach,mac_mach,os_mach,interfaces_nom_interface)VALUES(NULL,'$ ip_up',
 '$面具,$主机名,$ MAC','$ OS','$行');
 回声$ SQL1 |在/ usr /斌/ MySQL的-h $ HOST_BDD -u $ LOGIN -p $ PASSWD -s $ NOM_BDD
 回声$ SQL2 |在/ usr /斌/ MySQL的-h $ HOST_BDD -u $ LOGIN -p $ PASSWD -s $ NOM_BDD
    完成< / usr / lib目录/ cgi-bin目录/ resultat
  IP =
  完成< / usr / lib目录/ cgi-bin目录/ liste_interfaces
  回声cbon


解决方案

几个思路:


  1. 检查了shell_exec 的php.ini disabled_functions
    (php.ini中:disabled_functions)

  2. 确保PHP是不是在安全模式下运行
    (php.ini中: safe_mode设置

  3. 确保PHP-FPM进程(如果使用PHP-FPM)或https(如果使用APXS)下足够的权限作品(运行shell脚本,并在脚本执行这些命令)
    (在这种情况下,你可以用su到该用户,看看你可以从bash的运行)

对不起,我不能更多到目前为止想到...

I made a shell script that detects network interfagces then for each interface it detects the IP address, mask, broadcast address, then it makes a ping to all IP addresses for this network interface.

The script has execute permissions. Normally, the script will save the list of network interfaces (eth0 eth1 wlan0) in a file called "resultat" but when I run this script from a web page with php's shell_exec command (echo 'password for www-data user' | / usr/lib/cgi-bin/sudo -S global.sh bin/bash/") no output is generated.

If I run the same script as user www-data in the terminal, the result file is correctly populated.

The script:

  #!/bin/bash
  #####   paramères relatives au connexion à la base de données
  HOST_BDD="localhost"
  LOGIN="root"
  PASSWD="password"
  NOM_BDD="dbnessus"
  ##### ces requettes pour vider les tables avant de faire la detection
  vider2="TRUNCATE machine_connecte"
  echo $vider2 | /usr/bin/mysql -h $HOST_BDD 
  -u $LOGIN -p$PASSWD -s $NOM_BDD

  vider1="TRUNCATE interfaces"
  echo $vider1 | /usr/bin/mysql -h $HOST_BDD 
  -u $LOGIN -p$PASSWD -s $NOM_BDD

  initialise="ALTER TABLE machine_connecte AUTO_INCREMENT=0"
  echo $initialise | /usr/bin/mysql -h $HOST_BDD 
  -u $LOGIN -p$PASSWD -s $NOM_BDD
  #######################################################

  /usr/lib/cgi-bin/get_interface.sh > /usr/lib/cgi-bin/liste_interfaces
  while read line; 
  do 

  ip=$(/usr/lib/cgi-bin/get_ip.sh $line)
  mask=$(/usr/lib/cgi-bin/get_netmask.sh $line)
  bcast=$(/usr/lib/cgi-bin/get_bcast.sh $line)


  ###fonction is_alive_ping
  is_alive_ping()
  {
    ping -i 100 -c 1 $1 > /dev/null 2> /dev/null
   [ $? -eq 0 ] && echo  $i >>/usr/lib/cgi-bin/resultat
  }
  cat /dev/null >/usr/lib/cgi-bin/resultat;
  #########


  ###division des octet d'adresse de broadcst
  if [ "$ip" != "" ]
  then
  i1="$(echo $bcast |cut -d"." -f1)"
  i2="$(echo $bcast |cut -d"." -f2)"
  i3="$(echo $bcast |cut -d"." -f3)"
  i4="$(echo $bcast |cut -d"." -f4)"
  fi
  ###  { HostID / NetworkID } / classe du réseau

  ##################### A.255.255.255 Classe A
  if [ "$i2" == "255" ]
  then
for i in "$i1".{1..254}.{1..254}.{1..254}
do
is_alive_ping $i & disown
done
  fi
  ##################### A.B.255.255 Classe B
  if [ "$i2" != "255" ] && [ "$i3" == "255" ]
  then
for i in "$i1.$i2".{1..254}.{1..254} 
do
is_alive_ping $i & disown
done
  fi
  ##################### A.B.C.255 Classe C
  if [ "$i2" != "255" ] && [ "$i3" != "255" ]&& [ "$i4" == "255" ]
  then
for i in "$i1.$i2.$i3".{1..254} 
do
is_alive_ping $i & disown
    done
  fi
  ################
while read ip_up; 
do 
hostname=$(/usr/bin/resolveip -s $ip_up 2>/dev/null)
if [ "$hostname" == "" ]
then
hostname="*"
fi
mac=$(/usr/sbin/arp -a $ip_up |cut -d" " -f4)
if [ "$ip_up" == "$ip" ] 
then
mac=$(/sbin/ifconfig $line |grep 'HWaddr'|grep -v '127.0.0.1'|awk '{ print $5}')
fi
OS=$( /usr/bin/nmap -A $ip_up |grep "Service Info:" |awk '{print $4,$5}' )
if [ "$OS" == "Unix, Linux" ] || [ "$OS" == "Linux" ]
then
OS="Linux"
elif [ "$OS" == "Windows " ]
then 
OS="Windows"
else
OS="*"
fi
 #sql1="INSERT INTO  dbnessus.interfaces (nom_interface)VALUES ('$line');"
 sql1="INSERT IGNORE INTO  dbnessus.interfaces (nom_interface)VALUES ('$line');"
 sql2="INSERT INTO  dbnessus.machine_connecte (idmachine ,ip_mach ,mask_mach,
 nom_mach,mac_mach ,os_mach ,interfaces_nom_interface)VALUES ( NULL,  '$ip_up',
 '$mask', '$hostname', '$mac',  '$OS',  '$line');"


 echo $sql1 | /usr/bin/mysql -h $HOST_BDD -u $LOGIN -p$PASSWD -s $NOM_BDD
 echo $sql2 | /usr/bin/mysql -h $HOST_BDD -u $LOGIN -p$PASSWD -s $NOM_BDD




    done < /usr/lib/cgi-bin/resultat
  ip=""
  done < /usr/lib/cgi-bin/liste_interfaces
  echo "cbon"

解决方案

Several ideas:

  1. Check if shell_exec is in php.ini's disabled_functions (php.ini: disabled_functions)
  2. make sure PHP is not running in safe mode (php.ini: safe_mode)
  3. make sure php-fpm process (if using php-fpm) or https (if using apxs) works under sufficient privilege (to run the shell script and execute these commands in script) (in this case you can su to that user and see if you can run it from bash)

Sorry I am unable to think of more so far...

这篇关于了shell_exec不是在PHP网站申请工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆