PHP 보안 · 3 min read · Oct 25, 2025

CentOS 5.0에서 Suhosin으로 PHP5 강화하는 방법 - 페이지 2

4 Suhosin 설치

Suhosin은 여기에서 다운로드할 수 있습니다: http://www.hardened-php.net/suhosin/download.html

Suhosin 패치를 설치하려면 PHP5를 소스에서 다시 컴파일해야 하지만, 우리는 이를 위해 CentOS 5.0 PHP5.src.rpm 패키지를 사용할 것입니다 (rpmbuild 명령어를 사용하여), 그래서 Suhosin이 포함된 새로운 PHP5.rpm 패키지를 설치할 수 있습니다. 이렇게 하면 rpmbuild가 이를 처리하므로 올바른 PHP5 구성 옵션에 대해 걱정할 필요가 없습니다.

하지만 먼저 Hardened-PHP 프로젝트의 릴리스 서명 키를 복사하여 GNU Privacy Guard 키체인에 가져옵니다:

wget http://www.hardened-php.net/hardened-php-signature-key.asc  
gpg --import < hardened-php-signature-key.asc

그런 다음 CentOS 5.0 미러에서 현재 설치된 PHP 버전(이 예제에서는 5.1.6)에 맞는 PHP5.src.rpm 패키지를 /usr/src로 다운로드하고 설치합니다:

cd /usr/src  
wget http://ftp-stud.fht-esslingen.de/pub/Mirrors/centos/5.0/updates/SRPMS/php-5.1.6-12.el5.src.rpm

(위에서 보시다시피, 저는 CentOS 미러의 updates/ 디렉토리에서 최신 PHP5.src.rpm을 다운로드합니다; 물론 os/ 디렉토리에서 원본 .src.rpm을 다운로드할 수도 있습니다, 예: http://ftp-stud.fht-esslingen.de/pub/Mirrors/centos/5.0/os/SRPMS/php-5.1.6-5.el5.src.rpm. 그렇게 하시면 이 튜토리얼의 나머지 부분에서 파일 이름을 조정해야 합니다.)

rpm -ivh php-5.1.6-12.el5.src.rpm

이와 같은 경고가 표시되면:

warning: user mockbuild does not exist - using root

무시하셔도 됩니다.

다음으로, PHP 버전에 맞는 Suhosin 패치를 /usr/src/redhat/SOURCES에 다운로드합니다 (Suhosin 다운로드 페이지에서 모든 사용 가능한 패치를 찾을 수 있습니다):

cd /usr/src/redhat/SOURCES  
wget http://www.hardened-php.net/suhosin/_media/suhosin-patch-5.1.6-0.9.6.patch.gz

이제 다운로드한 패치의 MD5 합계가 Suhosin 다운로드 페이지에 게시된 것과 동일한지 확인해야 합니다:

md5sum suhosin-patch-5.1.6-0.9.6.patch.gz

MD5 합계가 괜찮다면, 디지털 서명을 다음과 같이 확인할 수 있습니다:

wget http://www.hardened-php.net/suhosin/_media/suhosin-patch-5.1.6-0.9.6.patch.gz.sig  
gpg suhosin-patch-5.1.6-0.9.6.patch.gz.sig

출력에서 이 줄을 보시면:

gpg: Good signature from "Hardened-PHP Signature Key"

다운로드한 패치에 문제가 없으며, 계속 진행할 수 있습니다.

이제 Suhosin 패치를 압축 해제하고, CentOS 명명 규칙에 맞게 이름을 변경한 후, /usr/src/redhat/SPECS/php.spec 파일을 수정하여 rpmbuild 명령이 PHP5를 재구성할 때 Suhosin 패치를 포함해야 함을 알립니다:

gunzip suhosin-patch-5.1.6-0.9.6.patch.gz  
mv suhosin-patch-5.1.6-0.9.6.patch php-5.1.6-suhosin.patch  
cd /usr/src/redhat/SPECS/  
vi php.spec

모든 패치가 나열된 구문에 Patch0: php-5.1.6-suhosin.patch를 추가하고, 같은 구문에서 Patch14: php-5.1.6-ecalloc.patch 줄을 주석 처리합니다 (ecalloc 패치는 Suhosin과 충돌합니다), 그런 다음 %setup -q 구문에 %patch0 -p1 -b .suhosin을 추가하고 같은 구문에서 %patch14 -p1 -b .ecalloc 줄을 주석 처리합니다:

| [...] Source51: php.ini Patch0: php-5.1.6-suhosin.patch Patch1: php-5.1.4-gnusrc.patch Patch2: php-5.1.4-warnings.patch Patch5: php-4.3.3-install.patch Patch6: php-5.0.4-norpath.patch Patch7: php-4.3.2-libtool15.patch Patch13: php-5.0.2-phpize64.patch # Patch14: php-5.1.6-ecalloc.patch [...] %setup -q %patch0 -p1 -b .suhosin %patch1 -p1 -b .gnusrc %patch2 -p1 -b .warnings %patch5 -p1 -b .install %patch6 -p1 -b .norpath %patch7 -p1 -b .libtool15 %patch13 -p1 -b .phpize64 # %patch14 -p1 -b .ecalloc [...] |

이제 PHP5를 재구성합니다:

rpmbuild -ba php.spec

설치된 PHP5 모듈에 따라, rpmbuild는 다양한 PHP5 모듈을 위한 새로운 패키지를 빌드하는 데 필요한 누락된 패키지에 대해 불평할 것입니다:

[root@server1 SPECS]# rpmbuild -ba php.spec  
cat: /usr/include/httpd/.mmn: No such file or directory  
error: Failed build dependencies:  
        aspell-devel >= 0.50.0 is needed by php-5.1.6-12.i386  
        httpd-devel >= 2.0.46-1 is needed by php-5.1.6-12.i386  
        libjpeg-devel is needed by php-5.1.6-12.i386  
        libpng-devel is needed by php-5.1.6-12.i386  
        pcre-devel >= 4.5 is needed by php-5.1.6-12.i386  
        libc-client-devel is needed by php-5.1.6-12.i386  
        mysql-devel >= 4.1.0 is needed by php-5.1.6-12.i386  
        postgresql-devel is needed by php-5.1.6-12.i386  
        unixODBC-devel is needed by php-5.1.6-12.i386  
        net-snmp-devel is needed by php-5.1.6-12.i386  
        gd-devel is needed by php-5.1.6-12.i386  
        freetype-devel is needed by php-5.1.6-12.i386  
[root@server1 SPECS]#

이와 같은 오류가 표시되면, 누락된 패키지를 설치합니다, 예를 들어:

yum install aspell-devel httpd-devel libjpeg-devel libpng-devel pcre-devel libc-client-devel mysql-devel postgresql-devel unixODBC-devel net-snmp-devel gd-devel freetype-devel

그 후, rpmbuild를 다시 실행합니다:

rpmbuild -ba php.spec

이제 PHP5와 모든 설치된 PHP5 모듈이 다시 컴파일되고 /usr/src/redhat/RPMS/i386 디렉토리에 새로운 .rpm 패키지가 생성됩니다. 이 작업은 시간이 걸릴 수 있으니 인내심을 가져주세요.

그 후, 새로운 PHP5 패키지를 다음과 같이 설치할 수 있습니다:

cd /usr/src/redhat/RPMS/i386  
rpm -Uvh --force php-*

이것으로 Suhosin 패치가 완료되었습니다.

이제 Suhosin PHP 확장을 빌드할 것입니다. 먼저 /usr/src 디렉토리에 소스를 다운로드합니다 (Suhosin 확장의 소스는 Suhosin 다운로드 페이지에서 사용할 수 있습니다):

cd /usr/src  
wget http://www.hardened-php.net/suhosin/_media/suhosin-0.9.20.tgz

다음으로 MD5 합계와 서명을 다시 확인합니다:

md5sum suhosin-0.9.20.tgz
wget http://www.hardened-php.net/suhosin/_media/suhosin-0.9.20.tgz.sig  
gpg suhosin-0.9.20.tgz.sig

그런 다음 소스를 압축 해제하고 확장을 다음과 같이 빌드합니다:

tar xvfz suhosin-0.9.20.tgz  
cd suhosin-0.9.20  
phpize  
./configure  
make  
make install

Suhosin 확장을 활성화하려면 /etc/php.d/suhosin.ini 파일을 만들고 그 안에 extension=suhosin.so 줄을 넣습니다:

vi /etc/php.d/suhosin.ini

| extension=suhosin.so |

이제 남은 것은 Apache2를 재시작하는 것입니다:

/etc/init.d/httpd restart

이제 브라우저에서 info.php 페이지를 다시 호출해 보세요 (예: http://192.168.0.100/info.php). 모든 것이 잘 진행되었다면, 이제 페이지의 두 곳에서 Suhosin이 언급되는 것을 볼 수 있어야 합니다:

그게 전부입니다. 원하신다면 Suhosin을 구성할 수 있습니다 (http://www.hardened-php.net/suhosin/configuration.html 참조), 하지만 Suhosin은 기본 구성으로 즉시 작동하므로, 자신이 무엇을 하고 있는지 확실히 아는 것이 중요합니다.

5 링크

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.