PHP执行root命令
在玩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&nb
相关文档:
<?php
/*
* -------------------------------------------------
* Author : Fanglor
* Email : Fanlor@163.com
* Url : www.skyleft.com
* Date : 2009-10-13
* -------------------------------------------------
*/
function arr_foreach ($arr) {
if (!is_array ($arr)) {
return fa ......
一.环境的安装
下载安装包,Google上搜索php+apache+sql的安装包并安装。
二.扩展编程
针对在PHP环境下掉用C编程(c程序编译的dll),主要有以下两种方式。
1.利用ATL构建DLL组件,然后再PHP里面直接调用,调用方法 ......
原文参考http://www.cnblogs.com/xxcainiao/archive/2009/04/18/1438482.html
稍作修改,做了一个goto按钮:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xh ......
基本概念
PHP 中的数组实际上是一个有序图。图是一种把 values 映射到 keys 的类型。因此既可以把php的数组当做普通数组使用,也可以用它来模拟字典、集合、栈、队列、树等多种其他数据结构。
数组的创建:
创建数组的一般格式为:$arrName = array( [key =>]value, ...),其中key 可以是 integer 或者 string,而val ......