티스토리 뷰

728x90
반응형

 포스팅은 WebtoB PHP 설치 및 연동 가이드입니다.


 

1. PHP 설치 테스트 환경

테스트 환경 정보

OS : Linux 2.6.39_200.2.4.1

WebtoB Version : WebtoB 4.1.8.1

PHP Version : PHP-5.5.30

 

설치 경로

WebtoB : /user/nrson/webtob

PHP : /user/nrson/phpinstall/php-5.5.30

* PHP 설치 전 cc 또는 gcc 컴파일러가 선 설치 되어야 PHP 설치 작업을 진행할 수 있습니다.

 

2. PHP 설치 가이드

WebtoB 설치는 선행 작업 되어있다고 가정하고 설명합니다.

 

PHP 설치 바이너리 다운로드

http://php.net/downloads.php

해당 경로에서 설치 바이너리를 다운로드 받으실 수 있습니다. Unix, Linux : 아래 이미지에서 보이듯이 .gz 확장자 파일을 다운로드 받으실 수 있습니다. Window : Windows downloads를 클릭하여 파일을 다운로드 받으실 수 있습니다.



본 문서에서는 Windows Version의 경우 Next 버튼만 클릭하여 쉽게 설치할 수 있으므로 생략하겠으며, Linux 대상으로 테스트를 진행하도록 하겠습니다.

해당 블록 부분을 클릭하게되면 국가별 설치 파일을 다운로드 받으실 수 있으며 Korea 부분은 없기때문에 United States 국가를 선택하여 설치하도록 하겠습니다. 아래 이미지는 참고하세요.

php.net을 클릭하시면 다운로드가 진행됩니다. 받으신 파일은 서버에 업로드 해주십시오.

 

PHP 설치 진행 1단계 : configure

1) 다운로드 받은 파일을 서버에 업로드 합니다.

nrson@infrasvr:/user/nrson/phpinstall>ls

php-5.5.30.tar.gz

 

2) 해당 파일 압축을 해제합니다.

nrson@infrasvr:/user/nrson/phpinstall>tar -xvzf php-5.5.30.tar.gz

. . . 생략

php-5.5.30/README.TESTING

php-5.5.30/config.sub

php-5.5.30/makerpm

php-5.5.30/README.input_filter

php-5.5.30/Makefile.frag

nrson@infrasvr:/user/nrson/phpinstall>

 

3) Configure 작업 진행

nrson@infrasvr:/user/nrson/phpinstall/php-5.5.30>./configure --prefix=/user/nrson/webtob/php

--prefix : PHP 설치 Directory 경로 지정하는 옵션으로 지정하지 않으면 현재 위치에 설치가 진행됩니다.

 

nrson@infrasvr:/user/nrson/phpinstall/php-5.5.30>./configure --prefix=/user/nrson/webtob/php

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking for a sed that does not truncate output... /bin/sed

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

checking for cc... cc

checking whether the C compiler works...

. . . 중략

Generating files

configure: creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+

 

Thank you for using PHP.

 

config.status: creating php5.spec

config.status: creating main/build-defs.h

config.status: creating scripts/phpize

config.status: creating scripts/man1/phpize.1

config.status: creating scripts/php-config

config.status: creating scripts/man1/php-config.1

config.status: creating sapi/cli/php.1

config.status: creating sapi/cgi/php-cgi.1

config.status: creating ext/phar/phar.1

config.status: creating ext/phar/phar.phar.1

config.status: creating main/php_config.h

config.status: executing default commands

nrson@infrasvr:/user/nrson/phpinstall/php-5.5.30>

정상 configure 작업을 진행한 결과입니다.

 

* cc 컴파일러 설치 서버에서는 해당 에러가 발생합니다.

php 설치 cc or gcc 컴파일러 설치 여부를 먼저 확인하신 진행해주시기 바랍니다.

nrson@ibmtest:/home/nrson/source/php-5.5.30>./configure --prefix=/home/nrson/webtob/php

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -E

checking for a sed that does not truncate output... /usr/bin/sed

checking build system type... powerpc-ibm-aix5.3.0.0

checking host system type... powerpc-ibm-aix5.3.0.0

checking target system type... powerpc-ibm-aix5.3.0.0

checking for cc... no

checking for gcc... no

configure: error: in `/home/nrson/source/php-5.5.30':

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

 

PHP 설치 2단계 : make

nrson@infrasvr:/user/nrson/phpinstall/php-5.5.30>make

/bin/sh /user/nrson/phpinstall/php-5.5.30/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/opcache/ -I/user/nrson/phpinstall/php-5.5.30/ext/opcache/ -DPHP_ATOM_INC -I/user/nrson/phpinstall/php-5.5.30/include -I/user/nrson/phpinstall/php-5.5.30/main -I/user/nrson/phpinstall/php-5.5.30 -I/user/nrson/phpinstall/php-5.5.30/ext/date/lib -I/user/nrson/phpinstall/php-5.5.30/ext/ereg/regex -I/usr/include/libxml2 -I/user/nrson/phpinstall/php-5.5.30/ext/sqlite3/libsqlite -I/user/nrson/phpinstall/php-5.5.30/TSRM -I/user/nrson/phpinstall/php-5.5.30/Zend    -I/usr/include -g -O2 -fvisibility=hidden   -c /user/nrson/phpinstall/php-5.5.30/ext/opcache/ZendAccelerator.c -o ext/opcache/ZendAccelerator.lo

. . . 중략

Generating phar.php

Generating phar.phar

PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.

directorygraphiterator.inc

directorytreeiterator.inc

clicommand.inc

pharcommand.inc

invertedregexiterator.inc

phar.inc

 

Build complete.

Don't forget to run 'make test'.

 

nrson@infrasvr:/user/nrson/phpinstall/php-5.5.30>

 

PHP 설치 3단계 : make install

nrson@infrasvr:/user/nrson/phpinstall/php-5.5.30>make install

Installing shared extensions:     /user/nrson/webtob/php/lib/php/extensions/no-debug-non-zts-20121212/

Installing PHP CLI binary:        /user/nrson/webtob/php/bin/

Installing PHP CLI man page:      /user/nrson/webtob/php/php/man/man1/

Installing PHP CGI binary:        /user/nrson/webtob/php/bin/

Installing PHP CGI man page:      /user/nrson/webtob/php/php/man/man1/

Installing build environment:     /user/nrson/webtob/php/lib/php/build/

Installing header files:          /user/nrson/webtob/php/include/php/

Installing helper programs:       /user/nrson/webtob/php/bin/

  program: phpize

  program: php-config

Installing man pages:             /user/nrson/webtob/php/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PEAR environment:      /user/nrson/webtob/php/lib/php/

[PEAR] Archive_Tar    - installed: 1.3.12

[PEAR] Console_Getopt - installed: 1.3.1

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util       - installed: 1.2.3

[PEAR] PEAR           - installed: 1.9.5

Wrote PEAR system config file at: /user/nrson/webtob/php/etc/pear.conf

You may want to add: /user/nrson/webtob/php/lib/php to your php.ini include_path

/user/nrson/phpinstall/php-5.5.30/build/shtool install -c ext/phar/phar.phar /user/nrson/webtob/php/bin

ln -s -f phar.phar /user/nrson/webtob/php/bin/phar

Installing PDO headers:          /user/nrson/webtob/php/include/php/ext/pdo/

 

PHP 설치 4단계 : finish

install이 완료되면, ./configure 작업에서 지정한 PHP 설치 경로에 php 생성이 되었는지 확인합니다.

nrson@infrasvr:/user/nrson/webtob/php>ls

bin  etc  include  lib  php

 

 

 

3. WebtoB-PHP 연동 설정

연동 설정 방법

WebtoB-PHP 연동 설정 1단계 : php.ini 설정

설치한 php 디렉토리에서 php.ini-development php.ini-production 파일을 실제 webtob 연동할 php lib 디렉토리로 복사하는 작업을 거칩니다. 해당 ini 파일은 php 설치할 경우 default 제공되는 파일입니다.

간혹, php.ini-recommended 파일 하나만 존재하는 경우가 있으며 경우에는 해당 파일을 사용하시면 됩니다.

1) ini 파일 복사

nrson@infrasvr:/user/nrson/phpinstall/php-5.5.30>cp -p php.ini-development php.ini-production /user/nrson/webtob/php/lib

2) 정상 복사되었는지 확인

nrson@infrasvr:/user/nrson/webtob/php/lib>ls

php  php.ini-development  php.ini-production

 

WebtoB-PHP 연동 설정 2단계 : WebtoB 설정

*VHOST

vhost2    DOCROOT="/user/nrson/webtob/docs",

                PORT = "8010",

                HOSTNAME = "192.168.2.31",

                HOSTALIAS = "www.nrson.co.kr",

                ServiceOrder = "ext,uri"

#별도 vhost 추가해주었습니다. (이는 해당 사용환경에 따라 추가여부를 결정하시기 바랍니다.)

 

*SVRGROUP

phpg            SVRTYPE = PHP, ScriptLoc = "/php/bin/php-cgi", VhostName = vhost2

#php 처리할 SVRGROUP 추가해줍니다.

여기서, ScriptLoc 경우 WEBTOBDIR / 생각하여 상대경로로 설정하도록 합니다.

 

*SERVER

PHP             SVGNAME = phpg, MinProc = 10, MaxProc = 10, ASQCount = 1

#php 처리할 SERVER 추가해줍니다.

 

*EXT

php             MimeType = "application/x-httpd-php", SvrType = PHP

php5            MimeType = "application/x-httpd-php", SvrType = PHP

#php 확장자 분기 처리를 위해 추가해줍니다.

 

WebtoB-PHP 연동 설정 3단계 : WebtoB 컴파일 및 기동

1) WebtoB 컴파일

nrson@infrasvr:/user/nrson/webtob/config>wscfl -i http.m

CFL0446: SVRGROUP NodeName is no longer necessary. Can be removed. line=57

Current configuration:

        Number of client handler(HTH) = 1

        Supported maximum user per node = 8063

        Supported maximum user per handler = 8063

Successfully created the configuration file (/user/nrson/webtob/config/wsconfig) for node infrasvr.

The host name of the running machine is infrasvr.

 

2) Webtob 기동

nrson@infrasvr:/user/nrson/webtob/config>wsboot

Booting WebtoB on node (infrasvr)

Starting WSM at Wed Dec  2 18:27:24 2015

Starting HTL at Wed Dec  2 18:27:24 2015

Starting HTH at Wed Dec  2 18:27:24 2015

         Current WebtoB Configuration:

                Number of client handlers (HTH) = 1

                Supported maximum user per node = 8063

                Supported maximum user per handler = 8063

Starting SVR(htmls) at Wed Dec  2 18:27:24 2015

Starting SVR(htmls) at Wed Dec  2 18:27:24 2015

Starting SVR(phps) at Wed Dec  2 18:27:24 2015

Starting SVR(phps) at Wed Dec  2 18:27:24 2015

nrson@infrasvr:/user/nrson/webtob/config>

 

 

연동 설정 테스트

WebtoB-PHP 연동 설정 확인

nrson@infrasvr:/user/nrson/webtob/config>wsadmin

--- Welcome to WebtoB Admin (Type "quit" to leave) ---

$$1 infrasvr (wsadm) [2015/12/02:18:28:44]: si

--------------------------------------------------------------------------------

 hth   svrname (svri)   status     count cqcnt    aqcnt qpcnt emcnt rscnt rbcnt

--------------------------------------------------------------------------------

   0  html       (  0)   RDY           0     0        0     0     0     0     0

   0  PHP       (  1)   RDY           0     0        0     0     0     0     0

 

PHP status RDY 것을 확인할 있습니다.

WEBTOB DOCROOT test.php 하나 생성합니다.

nrson@infrasvr:/user/nrson/webtob/docs>cat test.php

<?

phpinfo();

?>

 

생성 , 해당 페이지를 호출합니다.

 



 

 

4. PHP의 자체 취약점 조치방법
PHP 버전별 취약코드 수행테스트
a. 서버 디렉토리 노출테스트 :
특정이미지(.png, .gif)에 아래와 같은 코드를 입력하여 디렉토리 노출테스트 수행



1) php 5.6.21(정상)

2) php 5.0.0(노출) / 엑세스로그 : 192.168.41.39 - - [26/May/2016:19:59:01 +0900] "GET /image2.png/.php HTTP/1.1" 200 130

3) php 5.6.21(정상) / 엑세스로그 : 192.168.41.39 - - [26/May/2016:20:03:00 +0900] "GET /image2.png/.php HTTP/1.1" 500 172

 

결과
1) php 4.4.9(노출)
2) php 5.0.0(노출)
3) php 5.6.21(정상)

 

b. 취약코드를 통한 유닉스 명령어 수행테스트



가) php 4.4.9(노출) / 엑세스로그 : 192.168.41.39 - - [26/May/2016:19:51:00 +0900] "POST /image1.png/.php HTTP/1.1" 200

나) php 5.0.0(노출) / 엑세스로그 : 192.168.41.39 - - [26/May/2016:19:58:00 +0900] "POST /image1.png/.php HTTP/1.1" 200

다) php 5.6.21(정상) / 엑세스로그 : 192.168.41.39 - - [26/May/2016:20:07:00 +0900] "POST /image1.png/.php HTTP/1.1" 200

 

결과
1) php 4.4.9(노출)
2) php 5.0.0(노출)
3) php 5.6.21(정상)

 

조치방법

a. PHP 업그레이드

최신버전의 보안이 강화된 PHP 5.6 이상으로 업그레이드 수행하여 취약점을 제거합니다.



 

b. WebtoB ebtoB ebtoB ebtoB ebtoB ebtoB 설정을 통한 우회방법

PHP 자체취약점에 대해 WebtoB는 다음과 같은 설정을 지원합니다.

$WEBTOBDIR/config/http.m

 

*NODE

URLRewrite = Y,

URLRewriteConfig - "$(WEBTOBDIR)/config/rewrite.conf"

 

*rewrite.conf의 내용

RewriteRule \/.(php3.*|php4.*|php5.*|php.*|php)$ - [NC,F]

 

본 포스팅에서 취약점이 발견된 PHP 4.4.9에서 테스트 결과 가이드 하는 취약점에 대해 웹서버는 403으로 응답합니다.

PHP 연동을 위해 유용하게 사용하시기를 바랍니다.

고맙습니다.

 

728x90
반응형