php执行root命令
一.确定php的sysem等函数可用
二.编写c程序,如ipt.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
uid_t uid ,euid;
uid = getuid() ;
euid = geteuid();
if(setreuid(euid, uid)) //交换这两个id
perror("setreuid");
system("/sbin/iptables -nL --line-number"); //执行iptables -L命令
return 0;
}
编译
gcc -o ipt -Wall ipt.c
赋予权限:
chmod u+s ipt
php调用:
system("/scripts/ipt",$retval);
三.携带参数
ipt_accept.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(int agrc,char* argv[])
{
uid_t uid ,euid;
uid = getuid() ;
euid = geteuid();
if(setreuid(euid, uid)) //交换这两个id
perror("setreuid");
char buf[500];
sprintf(buf,"iptables -A INPUT -p tcp -s %s --dport 3306 -j ACCEPT",argv[1]);
system(buf); //执行iptables -L命令
return 0;
}
编译
gcc -o ipt_accept -Wall ipt_accept.c
赋予权限:
chmod u+s ipt_accept
php调用:
system("/scripts/ipt_accept " . $ip,$retval);
php执行root命令的更多相关文章
- linux定时任务crontab怎样执行root命令
在/var/spool/cron/文件夹下放置了所有定时任务文件, 1.运行crontab -u $用户名 -e会显示$用户的所有定时任务: 2.运行sudo crontab -e会显示root用户所 ...
- android 应用程序中执行Linux 命令
ADB 无线调试命令son = "setprop service.adb.tcp.port 5555\n" + "stop adbd\n" + "st ...
- 设置非root账号不用sudo直接执行docker命令
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- Linux远程执行Shell命令或脚本
## 远程执行shell命令 ssh [user]@[server] '[command]' # eg. ssh root@192.168.1.1 'uptime' ## 远程执行本地shell脚本 ...
- 执行openstack命令报错【You must provide a username via either -...】
openstack环境搭建好后,openstack的服务都启动了,当执行openstack命令时如nova service list报如下错误 You must provide a username ...
- PHP exec/system启动windows应用程序,执行.bat批处理,执行cmd命令
exec 或者 system 都可以调用cmd 的命令 直接上代码: <?php /** 打开windows的计算器 */ exec('start C:WindowsSystem32calc.e ...
- PHP在linux上执行外部命令
PHP在linux上执行外部命令 一.PHP中调用外部命令介绍二.关于安全问题三.关于超时问题四.关于PHP运行linux环境中命令出现的问题 一.PHP中调用外部命令介绍在PHP中调用外部命令,可以 ...
- Android Java执行Shell命令
最新内容建议直接访问原文:http://www.trinea.cn/android/android-java-execute-shell-commands/ 主要介绍Android或Java应用中如何 ...
- Linux下的crontab定时执行任务命令详解
在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron].cron读取一个或多个配置文件,这些配置文件中包含了命令行及其调用时间.cron的配置文件称为“cr ...
随机推荐
- BestCoder Round #74 (div.2)
组合 1001 LCP Array 第一题就小难,出题的好像是浙大的大牛? 找到一个规律:a[i] = x, s[i..i+x]都想同.a[i] = a[i+1] + 1 (a[i] > 0), ...
- 图论 SRM 674 Div1 VampireTree 250
Problem Statement You are a genealogist specializing in family trees of vampires. Vampire famil ...
- document.images、document.forms、doucument.links——>HTMLCollection
由于历史原因,HTMLDocument类定义了一些快捷属性来访问各种各样的节点.例如,images.forms.links等属性指向香味类似只读数组的<img>.<form>. ...
- javascript拾掇
用javascript如何给span赋值呢?一般有两种方法: 1>输出html <body onload="s()"><span id="hell ...
- foxmail配置office365邮箱
公司用的是office365套装,由于一直不习惯outlook点x就退出程序的设置,导致经常出现没能及时响应邮件的情况.一怒之下,把客户端改成foxmail. 邮箱客户端切换的主要问题出现在foxma ...
- CF 55D. Beautiful numbers(数位DP)
题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #in ...
- usaco silver刷水~其实是回顾一下,补题解
[BZOJ1606][Usaco2008 Dec]Hay For Sale 裸01背包 ;i<=n;i++) for(int j=m;j>=a[i];j--) f[j]=max(f[j], ...
- SpringMVC+Thymeleaf如何处理URL中的动态查询参数
1.使用一个Map<String, String>接收数据 When you request a Map annotated with @RequestParam Spring creat ...
- 纪念逝去的岁月——C/C++快速排序
快速排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...
- Find a way——L
L. Find a way Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave N ...