linux下php调用系统命令(root权限)
来源:互联网 发布:荣耀盒子pro 安装软件 编辑:程序博客网 时间:2024/05/17 01:30
在玩C 以前 玩过一段时间的PHP, 哪个时候需要用PHP 来运行root命令,一直未果,直到有一天搜索到了super这个插件.
随着玩C的日子多了.发现可以用C语言来包裹 要运行的外部命令. 实验了一下.成功了.
不需要任何外部工具就可以实现用PHP 执行root命令.
我下面就把方法发布给大家,有需求用php来运行root命令的朋友可以不用发愁了.
平台:Linux. 实验命令iptables 当前的目录是/var/www/html/http
写程序的时候 用root用户
大家都知道iptables 非root用户不能运行.
首先写个C程序
命名为:ipt.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
uid_t uid ,euid;
char cmd[1024];
uid = getuid() ;
euid = geteuid();
printf("my uid :%u/n",getuid()); //这里显示的是当前的uid 可以注释掉.
printf("my euid :%u/n",geteuid()); //这里显示的是当前的euid
if(setreuid(euid, uid)) //交换 这两个id
perror("setreuid");
printf("after setreuid uid :%u/n",getuid());
printf("afer sertreuid euid :%u/n",geteuid());
system("/sbin/iptables -L"); //执行iptables -L命令
return 0;
}
[/CODE]
编译该文件 gcc -o ipt -Wall ipt.c
在该路径下生成ipt 这个可执行文件.
如果现在用PHP网页调用 该ipt的话,即使setreuid了 也是不行的.
接下来要做的是chmod u+s ./ipt
ls 一下
-rwsr-xr-x 1 root root 5382 Jul 2 21:45 ipt
s位已经设置上了.
再写一个php页面调用它.
<?php
echo '<pre>';
$last_line = system('/var/www/html/http/ipt', $retval);
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
在浏览器中浏览.
[color=Red]Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)
target prot opt source destination [/color]
[color=Blue]my uid :48
my euid :0
after setreuid uid :0
afer sertreuid euid :48[/color]
转自:http://linux.chinaitlab.com/PHP/437044.html
chmod u+s
chmod u+s就是让这个程序不管由哪个用户启动,都以root身份运行,但前提是这个用户首先要有对这个程序的执行权限,否则他根本就启动不了这个程序。也就是说,u+s权限决定的是程序运行的身份,而x权限决定的是程序是否能被运行
参考自http://www.chinalinuxpub.com/bbs/showthread.php?t=40390
- linux下php调用系统命令(root权限)
- php调用Linux命令启动程序(root权限)
- php执行root权限linux命令
- PHP通过ROOT权限执行linux命令
- php 调用linux命令权限问题解决
- 如何让PHP以root权限执行系统命令
- PHP以ROOT权限执行系统命令的方法
- 让PHP以ROOT权限执行系统命令的方法
- 如何让PHP以root权限执行系统命令
- android java获得root权限调用linux命令
- Android 截图程序实现 需要root权限 (调用linux 命令)
- android java获得root权限调用linux命令
- adb命令下以root权限进入android系统
- Linux下LAMPP使用root权限调用shell
- ubuntu下获得linux命令的root权限
- linux系统下的权限操作命令
- Linux系统下在普通用户如何使用root权限
- Linux系统下给非root用户添加sudo权限
- C#创建用户控件:IPv4地址输入框
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- 如何修改SAP 登录后的背景图片(事务码 SMW0,SM30)
- Emacs 窗体的透明设置
- CString.Format 用法
- linux下php调用系统命令(root权限)
- Unity3D之iOS拍照
- json 基本原理
- GetBuffer, ReleaseBuffer, GetBufferSetLength
- directshow自带sample概要介绍
- 下载优酷视频
- 一只小蜜蜂...
- gSOAP使用小记
- AsyncTask简单说明