最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

本文實例講述了PHP實現(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);/*主要針對一些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)容感興趣的讀者可查看本站專題:《php程序設(shè)計安全教程》、《php安全過濾技巧總結(jié)》、《PHP運算與運算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

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

相關(guān)文章

  • php對數(shù)組內(nèi)元素進行隨機調(diào)換的方法

    php對數(shù)組內(nèi)元素進行隨機調(diào)換的方法

    這篇文章主要介紹了php對數(shù)組內(nèi)元素進行隨機調(diào)換的方法,通過自定義函數(shù)實現(xiàn)對數(shù)組內(nèi)元素進行隨機調(diào)換的功能,涉及php操作數(shù)組的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • 從PHP的源碼中深入了解stdClass類

    從PHP的源碼中深入了解stdClass類

    這篇文章主要介紹了從分析PHP的源碼角度深入了解stdClass類,并總結(jié)了stdClass類到底是是什么,需要的朋友可以參考下
    2014-04-04
  • php數(shù)組函數(shù)序列之each() - 獲取數(shù)組當(dāng)前內(nèi)部指針所指向元素的鍵名和鍵值,并將指針移到下一位

    php數(shù)組函數(shù)序列之each() - 獲取數(shù)組當(dāng)前內(nèi)部指針所指向元素的鍵名和鍵值,并將指針移到下一位

    each() 函數(shù)生成一個由數(shù)組當(dāng)前內(nèi)部指針所指向的元素的鍵名和鍵值組成的數(shù)組,并把內(nèi)部指針向前移動。返回的數(shù)組中包括的四個元素:鍵名為 0,1,key 和 value。單元 0 和 key 包含有數(shù)組單元的鍵名,1 和 value 包含有數(shù)據(jù)
    2011-10-10
  • PHP中Too few arguments to function的問題及解決

    PHP中Too few arguments to function的問題及解決

    這篇文章主要介紹了PHP中Too few arguments to function的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • 聊聊 PHP 8 新特性 Attributes

    聊聊 PHP 8 新特性 Attributes

    這篇文章主要介紹了PHP 8 新特性 Attributes的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)php,感興趣的朋友可以了解下
    2020-08-08
  • mysql_connect localhost和127.0.0.1的區(qū)別(網(wǎng)絡(luò)層闡述)

    mysql_connect localhost和127.0.0.1的區(qū)別(網(wǎng)絡(luò)層闡述)

    這篇文章主要介紹了mysql_connect localhost和127.0.0.1的區(qū)別(網(wǎng)絡(luò)層闡述),本文從網(wǎng)絡(luò)通信層面講解了它們的不同,需要的朋友可以參考下
    2015-03-03
  • 解析link_mysql的php版

    解析link_mysql的php版

    本篇文章是對link_mysql的php版的實現(xiàn)進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • 國外PHP程序員的13個好習(xí)慣小結(jié)

    國外PHP程序員的13個好習(xí)慣小結(jié)

    我是一個PHP新手,只有6個月的PHP編程經(jīng)歷,并且是在一位經(jīng)過認證的zend工程師的指導(dǎo)下完成工作的,每當(dāng)我編寫腳本時,我會注意一些能讓我做得更好的細節(jié)
    2012-02-02
  • PHP操作ZipArchive實現(xiàn)文件上傳下載功能

    PHP操作ZipArchive實現(xiàn)文件上傳下載功能

    在很多實際生產(chǎn)場景都需要批量上傳、下載一些文件的處理,本文將利用PHP?ZipArchive實現(xiàn)文件上傳下載功能,有需要的小伙伴可以參考一下
    2024-03-03
  • php的socket編程詳解

    php的socket編程詳解

    socket的英文原義是“孔”或“插座”。作為BSD UNIX的進程通信機制,取后一種意思。用于描述IP地址和端口,是一個通信鏈的句柄。在Internet上的主機一般運行了多個服務(wù)軟件,同時提供幾種服務(wù)。每種服務(wù)都打開一個Socket并綁定到一個端口上,不同的端口對應(yīng)于不同的服務(wù)
    2016-11-11

最新評論

五台县| 阿瓦提县| 建瓯市| 兴山县| 望奎县| 丽江市| 南靖县| 贵德县| 德兴市| 陇川县| 沭阳县| 志丹县| 门头沟区| 张家界市| 怀柔区| 上饶市| 卫辉市| 温宿县| 科技| 新密市| 忻城县| 库尔勒市| 黔南| 东兰县| 手机| 武乡县| 嵊州市| 安陆市| 沾化县| 滁州市| 青阳县| 永济市| 密云县| 盐源县| 井冈山市| 太和县| 正镶白旗| 西丰县| 侯马市| 武定县| 嘉黎县|