Nginx下WebShell跨站的問題解決方案

來源:互聯網
上載者:User

nginx用於大型網站,但是也有一個很大的問題那就是跨域問題,下面我們來看看關於修改php教程源碼來解決跨域的問題。下面來看方法。

google搜之有兩個比較廣為流傳的方法,其中最完美的莫過於直接修改php原始碼,對開啟目錄進行鑒權(搜出來的資料最早是anxsoft.com提供的代碼)。

因為需要更改php來源程式後,重新編譯php。在使用fpm方式安裝時,打補丁過程中會修改php的檔案,所以需要在打完fpm補丁後再修改php來源程式。

tar zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.14/

vi  main/fopen_wrappers.c

找到php_check_open_basedir_ex方法,在char *end;和pathbuf = estrdup(pg(open_basedir));之間插入以下的代碼:

 

        char path_copy[maxpathlen];
        int path_len;
        path_len = strlen(path);
        if (path_len >= maxpathlen) {
            errno = eperm;
            return -1;
        }
        if (path_len > 0 && path[path_len-1] == php_dir_separator) {
            memcpy(path_copy, path, path_len+1);
            while (path_len > 1 && path_copy[path_len-1] == php_dir_separator) path_len--;
            path_copy[path_len] = '';
            path = (const char *)&path_copy;
        }

        char *env_doc_root;
        if (pg(doc_root)) {
            env_doc_root = estrdup(pg(doc_root));
        } else {
            env_doc_root = sapi_getenv("document_root", sizeof("document_root")-1 tsrmls_cc);
        }
        if (env_doc_root) {
            int res_root = php_check_specific_open_basedir(env_doc_root, path tsrmls_cc);
            efree(env_doc_root);
            if (res_root == 0) {
                return 0;
            }
            if (res_root == -2) {
                errno = eperm;
                return -1;
            }
        }


然後編譯安裝php。

並php.ini的open_basedir配置
open_basedir = "/tmp/:/var/tmp/"

這樣就徹底解決了,webshell跨網站目錄訪問問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.