中国设计秀欢迎投稿
中国品牌形像设计网
平面设计 画册 VI欣赏 包装 CG-插画 搜索 个人网页 Alexa排名 CSS 建站资源 下载专区 JS特效 品牌服装 服装院校 专题欣赏 SEO 图标欣赏 专题
深圳网站建设 广州网站设计 域名注册 上海网站建设 虚拟主机 广州网站建设 广州网页设计 签名设计 虚拟主机 域名注册 品牌形象设计 设计联盟
求创科技
上海网麒科技
中国福网
中国设计秀
亿恩科技
中国设计秀
中国设计秀
当前位置:网络学院首页 >> 编程开发 >> php >> 在LINUX环境下用PHP执行Root命令

在LINUX环境下用PHP执行Root命令 (1)

来源:中国设计秀    作者:    点击:95     加入收藏    发表评论
0
顶一下
中资源

    在玩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; }

编译该文件: 
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

好了,已经设置上了,再写一个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]

[1] [2]
2007-08-27 15:47:00    出处:
热点文章/相关文章
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明 | 网站公告 | 友情链接 | 留言 | 旧版入口