欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)webshell掃描文件木馬的方法

 更新時(shí)間:2017年07月31日 12:24:46   作者:無(wú)法自拔  
這篇文章主要介紹了PHP實(shí)現(xiàn)webshell掃描文件木馬的方法,涉及php針對(duì)數(shù)值傳輸?shù)倪^(guò)濾操作與文件識(shí)別等相關(guān)安全操作技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)webshell掃描文件木馬的方法。分享給大家供大家參考,具體如下:

可掃描 weevelyshell 生成 或加密的shell 及各種變異webshell

目前僅支持php

支持掃描 weevelyshell 生成 或加密的shell
支持掃描callback一句話shell
支持各種php大馬

<!DOCTYPE html>
<html>
<head>
    <meta charset='gb2312'>
    <title>PHP web shell scan</title>
</head>
<body>
</body>
<?php
define("SELF",php_self());
error_reporting(E_ERROR);
ini_set('max_execution_time',20000);
ini_set('memory_limit','512M');
header("content-Type: text/html; charset=gb2312");
function weevelyshell($file){
    $content=file_get_contents($file);
    if(
        (
        preg_match('#(\$\w{2,4}\s?=\s?str_replace\("\w+","","[\w_]+"\);\s?)+#s',$content)&&
      preg_match('#(\$\w{2,4}\s?=\s?"[\w\d\+\/\=]+";\s?)+#',$content)&&               preg_match('#\$[\w]{2,4}\s?=\s\$[\w]{2,4}\(\'\',\s?\$\w{2,4}\(\$\w{2,4}\("\w{1,4}",\s?"",\s?\$\w{2,4}\.\$\w{2,4}\.\$\w{2,4}\.\$\w{2,4}\)\)\);\s+?\$\w{2,4}\(\)\;#',$content))
          ||
          (preg_match('#\$\w+\d\s?=\s?str_replace\(\"[\w\d]+\",\"\",\"[\w\d]+\"\);#s',$content)&&
        preg_match('#\$\w+\s?=\s?\$[\w\d]+\(\'\',\s?\$[\w\d]+\(\$\w+\(\$\w+\(\"[[:punct:]]+\",\s?\"\",\s?\$\w+\.\$\w+\.\$\w+\.\$\w+\)\)\)\);\s?\$\w+\(\);#s',$content))
        ){
        return true;
    }
}
function callbackshell($file){
    $content=file_get_contents($file);
    if(
        preg_match('#\$\w+\s?=\s?\$_(?:GET|POST|REQUEST|COOKIE|SERVER)\[.*?\]#is',$content)&&
        preg_match('#\$\w+\s?=\s?(?:new)?\s?array\w*\s?\(.*?_(?:GET|POST|REQUEST|COOKIE|SERVER)\[.*?\].*?\)+#is',$content)&&
        preg_match('#(?:array_(?:reduce|map|udiff|walk|walk_recursive|filter)|u[ak]sort)\s?\(.*?\)+?#is',$content)
        )
            return true;
}
function php_self(){
  $php_self=substr($_SERVER['PHP_SELF'],strrpos($_SERVER['PHP_SELF'],'/')+1);
  return $php_self;
}
$matches = array(
        '/mb_ereg_replace\([\'\*\s\,\.\"]+\$_(?:GET|POST|REQUEST|COOKIE|SERVER)\[[\'\"].*?[\'\"][\]][\,\s\'\"]+e[\'\"]'/is,
        '/preg_filter\([\'\"\|\.\*e]+.*\$_(?:GET|POST|REQUEST|COOKIE|SERVER)/is',
        '/create_function\s?\(.*assert\(/is',
        '/ini_get\(\'safe_mode\'\)/i',
        '/get_current_user\(.*?\)/i',
        '/@?assert\s?\(\$.*?\)/i',
        '/proc_open\s?\(.*?pipe\',\s?\'w\'\)/is',
    '/sTr_RepLaCe\s?\([\'\"].*?[\'\"],[\'\"].*?[\'\"]\s?,\s?\'a[[:alnum:][:punct:]]+?s[[:alnum:][:punct:]]+?s[[:alnum:][:punct:]]+?e[[:alnum:][:punct:]]+?r[[:alnum:][:punct:]]+?t[[:alnum:][:punct:]]+?\)/i',
        '/preg_replace_callback\(.*?create_function\(/is',
        '/filter_var(?:_array)?\s?.*?\$_(?:GET|POST|REQUEST|COOKIE|SERVER)\[[\'\"][[:punct:][:alnum:]]+[\'\"]\][[:punct:][:alnum:][:space:]]+?assert[\'\"]\)/is',
        '/ob_start\([\'\"]+assert[\'\"]+\)/is',
        '/new\s?ReflectionFunction\(.*?->invoke\(/is',
      '/PDO::FETCH_FUNC/',
        '/\$\w+.*\s?(?:=|->)\s?.*?[\'\"]assert[\'\"]\)?/i',
        '/\$\w+->(?:sqlite)?createFunction\(.*?\)/i',
        '/eval\([\"\']?\\\?\$\w+\s?=\s?.*?\)/i',
        '/eval\(.*?gzinflate\(base64_decode\(/i',
        '/copy\(\$HTTP_POST_FILES\[\'\w+\'\]\s?\[\'tmp_name\'\]/i',
        '/register_(?:shutdown|tick)_function\s?\(\$\w+,\s\$_(?:GET|POST|REQUEST|COOKIE|SERVER)\[.*?\]\)/is',
        '/register_(?:shutdown|tick)_function\s?\(?[\'\"]assert[\"\'].*?\)/i',
        '/call_user_func.*?\([\"|\']assert[\"|\'],.*\$_(?:GET|POST|REQUEST|COOKIE|SERVER)\[[\'|\"].*\]\)+/is',
      '/preg_replace\(.*?e.*?\'\s?,\s?.*?\w+\(.*?\)/i',
    '/function_exists\s*\(\s*[\'|\"](popen|exec|proc_open|system|passthru)+[\'|\"]\s*\)/i',
    '/(exec|shell_exec|system|passthru)+\s*\(\s*\$_(\w+)\[(.*)\]\s*\)/i',
    '/(exec|shell_exec|system|passthru)+\s*\(\$\w+\)/i',
    '/(exec|shell_exec|system|passthru)\s?\(\w+\(\"http_.*\"\)\)/i',
         '/(?:john\.barker446@gmail\.com|xb5@hotmail\.com|shopen@aventgrup\.net|milw0rm\.com|www\.aventgrup\.net|mgeisler@mgeisler\.net)/i',
      '/Php\s*?Shell/i',
    '/((udp|tcp)\:\/\/(.*)\;)+/i',
    '/preg_replace\s*\((.*)\/e(.*)\,\s*\$_(.*)\,(.*)\)/i',
    '/preg_replace\s*\((.*)\(base64_decode\(\$/i',
    '/(eval|assert|include|require|include_once|require_once)+\s*\(\s*(base64_decode|str_rot13|gz(\w+)|file_(\w+)_contents|(.*)php\:\/\/input)+/i',
    '/(eval|assert|include|require|include_once|require_once|array_map|array_walk)+\s*\(.*?\$_(?:GET|POST|REQUEST|COOKIE|SERVER|SESSION)+\[(.*)\]\s*\)/i',
    '/eval\s*\(\s*\(\s*\$\$(\w+)/i',
      '/((?:include|require|include_once|require_once)+\s*\(?\s*[\'|\"]\w+\.(?!php).*[\'|\"])/i',
    '/\$_(\w+)(.*)(eval|assert|include|require|include_once|require_once)+\s*\(\s*\$(\w+)\s*\)/i',
    '/\(\s*\$_FILES\[(.*)\]\[(.*)\]\s*\,\s*\$_(GET|POST|REQUEST|FILES)+\[(.*)\]\[(.*)\]\s*\)/i',
    '/(fopen|fwrite|fputs|file_put_contents)+\s*\((.*)\$_(GET|POST|REQUEST|COOKIE|SERVER)+\[(.*)\](.*)\)/i',
    '/echo\s*curl_exec\s*\(\s*\$(\w+)\s*\)/i',
    '/new com\s*\(\s*[\'|\"]shell(.*)[\'|\"]\s*\)/i',
    '/\$(.*)\s*\((.*)\/e(.*)\,\s*\$_(.*)\,(.*)\)/i',
    '/\$_\=(.*)\$_/i',
    '/\$_(GET|POST|REQUEST|COOKIE|SERVER)+\[(.*)\]\(\s*\$(.*)\)/i',
    '/\$(\w+)\s*\(\s*\$_(GET|POST|REQUEST|COOKIE|SERVER)+\[(.*)\]\s*\)/i',
    '/\$(\w+)\s*\(\s*\$\{(.*)\}/i',
    '/\$(\w+)\s*\(\s*chr\(\d+\)/i'
);
function antivirus($dir,$exs,$matches) {
    if(($handle = @opendir($dir)) == NULL) return false;
    while(false !== ($name = readdir($handle))) {
        if($name == '.' || $name == '..') continue;
        $path = $dir.$name;
        if(strstr($name,SELF)) continue;
        //$path=iconv("UTF-8","gb2312",$path);
        if(is_dir($path)) {
            //chmod($path,0777);/*主要針對(duì)一些0111的目錄*/
            if(is_readable($path)) antivirus($path.'/',$exs,$matches);
        } elseif(strpos($name,';') > -1 || strpos($name,'%00') > -1 || strpos($name,'/') > -1) {
            echo '特征 <input type="text" style="width:250px;" value="解析漏洞">     '.$path.'<div></div>'; flush(); ob_flush();
        }
        else {
            if(!preg_match($exs,$name)) continue;
            if(filesize($path) > 10000000) continue;
            $fp = fopen($path,'r');
            $code = fread($fp,filesize($path));
            fclose($fp);
            if(empty($code)) continue;
            if(weevelyshell($path)){
            echo '特征 <input type="text" style="width:250px;" value="weevely 加密shell">     '.$path.'<div></div>'; flush(); ob_flush();
        }elseif(callbackshell($path)){
                echo '特征 <input type="text" style="width:250px;" value="Callback shell">     '.$path.'<div></div>'; flush(); ob_flush();
        }
            foreach($matches as $matche) {
                $array = array();
                preg_match($matche,$code,$array);
                if(!$array) continue;
                if(strpos($array[0],"\x24\x74\x68\x69\x73\x2d\x3e")) continue;
                $len = strlen($array[0]);
                if($len > 6 && $len < 200) {
                    echo '特征 <input type="text" style="width:250px;" value="'.htmlspecialchars($array[0]).'">    '.$path.'<div></div>';
                    flush(); ob_flush(); break;
                }
            }
            unset($code,$array);
        }
    }
    closedir($handle);
    return true;
}
function strdir($str) { return str_replace(array('\\','//','//'),array('/','/','/'),chop($str)); }
echo '<form method="POST">';
echo '路徑: <input type="text" name="dir" value="'.($_POST['dir'] ? strdir($_POST['dir'].'/') : strdir($_SERVER['DOCUMENT_ROOT'].'/')).'" style="width:398px;"><div></div>';
echo '后綴: <input type="text" name="exs" value="'.($_POST['exs'] ? $_POST['exs'] : '.php|.inc|.phtml').'" style="width:398px;"><div></div>';
echo '操作: <input type="submit" style="width:80px;" value="scan"><div></div>';
echo '</form>';
if(file_exists($_POST['dir']) && $_POST['exs']) {
    $dir = strdir($_POST['dir'].'/');
    $exs = '/('.str_replace('.','\\.',$_POST['exs']).')/i';
    echo antivirus($dir,$exs,$matches) ? '</br ><div></div>掃描完畢!' : '</br > <div></div>掃描中斷';
}
?>
</html>

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《php程序設(shè)計(jì)安全教程》、《php安全過(guò)濾技巧總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門(mén)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • PHP實(shí)現(xiàn)JS中escape與unescape的方法

    PHP實(shí)現(xiàn)JS中escape與unescape的方法

    這篇文章主要介紹了PHP實(shí)現(xiàn)JS中escape與unescape的方法,通過(guò)json_encode和json_decode方法實(shí)現(xiàn)JS中escape與unescape函數(shù)的功能,需要的朋友可以參考下
    2016-07-07
  • PHP區(qū)塊查詢實(shí)現(xiàn)方法分析

    PHP區(qū)塊查詢實(shí)現(xiàn)方法分析

    這篇文章主要介紹了PHP區(qū)塊查詢實(shí)現(xiàn)方法,結(jié)合實(shí)例形式簡(jiǎn)單分析了php區(qū)塊查詢的概念、原理、實(shí)現(xiàn)與使用操作技巧,需要的朋友可以參考下
    2018-05-05
  • 如何批量替換相對(duì)地址為絕對(duì)地址(利用bat批處理實(shí)現(xiàn))

    如何批量替換相對(duì)地址為絕對(duì)地址(利用bat批處理實(shí)現(xiàn))

    你的url鏈接是相對(duì)路徑你想把他批量替換成絕對(duì)路徑該怎么做呢?下面與大家分享下具體的實(shí)現(xiàn)思路及代碼,只需點(diǎn)擊bat文件,全部頁(yè)面里的相對(duì)地址就會(huì)變成絕對(duì)地址了
    2013-05-05
  • 啟用OPCache提高PHP程序性能的方法

    啟用OPCache提高PHP程序性能的方法

    今天小編就為大家分享一篇關(guān)于啟用OPCache提高PHP程序性能的方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • php在linux下檢測(cè)mysql同步狀態(tài)的方法

    php在linux下檢測(cè)mysql同步狀態(tài)的方法

    這篇文章主要介紹了php在linux下檢測(cè)mysql同步狀態(tài)的方法,是Linux下使用php檢測(cè)mysql同步狀態(tài)的實(shí)用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • 使用PHP實(shí)現(xiàn)生成HTML靜態(tài)頁(yè)面

    使用PHP實(shí)現(xiàn)生成HTML靜態(tài)頁(yè)面

    在PHP網(wǎng)站開(kāi)發(fā)中為了網(wǎng)站推廣和SEO等需要,需要對(duì)網(wǎng)站進(jìn)行全站或局部靜態(tài)化處理,PHP生成靜態(tài)HTML頁(yè)面有多種方法,比如利用PHP模板、緩存等實(shí)現(xiàn)頁(yè)面靜態(tài)化,今天就以PHP實(shí)例教程形式討論P(yáng)HP生成靜態(tài)頁(yè)面的方法。
    2015-11-11
  • ecshop 2.72如何修改后臺(tái)訪問(wèn)地址

    ecshop 2.72如何修改后臺(tái)訪問(wèn)地址

    這篇文章主要介紹了ecshop 2.72如何修改后臺(tái)訪問(wèn)地址的方法,需要的朋友可以參考下
    2015-03-03
  • PHP抽象類(lèi)基本用法示例

    PHP抽象類(lèi)基本用法示例

    這篇文章主要介紹了PHP抽象類(lèi)基本用法,結(jié)合實(shí)例形式分析了php抽象類(lèi)的概念、原理、定義、使用方法及相關(guān)操作注意事項(xiàng),代碼注釋包含較為詳盡的說(shuō)明信息,需要的朋友可以參考下
    2018-12-12
  • php獲取當(dāng)前域名的方法示例

    php獲取當(dāng)前域名的方法示例

    在Web開(kāi)發(fā)中,獲取域名相關(guān)信息,是一項(xiàng)必備的能力,而PHP天生地具有解析URI的能力,所以PHP獲取域名也變得非常簡(jiǎn)單,在這里整理了一些,PHP獲取當(dāng)前域名的方法和技巧,需要的朋友可以參考下
    2023-11-11
  • PHP常用的排序和查找算法

    PHP常用的排序和查找算法

    這篇文章主要介紹了PHP四種基本排序算法和兩種查找算法示例,本文用一個(gè)實(shí)例講解冒泡排序法、快速排序法、選擇排序法、插入排序法的使用,需要的朋友可以參考下
    2015-08-08

最新評(píng)論