웹프로그래밍

Global It Leader!!


PHP


 
 

php 소스 암호화 하기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 4,069회 작성일 14-01-18 17:17

본문

서론

  php 소스 개발을 하다보면 공개하기가 꺼려지는 소스가 있기 마련입니다. 또한 디비 커넥트 설정과 계정정보 및 서버 설정에 대한 php 소스코드 들은 암호화가 해킹에 대한 최소한의 예방책일 것이다. 이러한 소스 암호화 툴로는 Zend , 이온큐브 쪽 솔루션이 잘 알려져 있습니다. 실제 여러업체에서 사용중이며 안정적입니다. 물론 유료화 버젼입니다. 하지만 무료버전의 암호화 툴도 있습니다. 오픈소스인 php_screw 입니다.
  해당 솔루션은 일본의 ThePM9.com 이라는 개발업체에서 만들어 졌으며, 현재는 1.5버전까지 개발 되어 졌습니다. php 소스코드를 암호화된 파일로 생성하는 실행 파일과 이를 Zend - Compile에 전달 되기전에 해독하는 php 모듈 형태로 이루어 집니다.

  어떠한 방법으로 암호화하는지는 공개 하지 않을 sourceforge를 통해 해당 소스를 다운 받아 php 동적 모듈을 생성 추가 하는 형태 입니다. 아래부터는 해당 모듈의 설치 법에 대해서 알아 보고겠습니다.


본론

1. 설치 조건
  다운 받은 소스상 README 파일을 읽어보시면 알 수 있겠지만 php_screw-1.5버젼은 PHP5.x 버젼에 zlib 이 설치 되어있어야 하며, UNIX 계열 ( 리눅스 , FreeBSD 등) 에서만 지원 합니다. 그런데 php4 버젼에서도 설치 및 운영이 잘됩니다. (당연한 말씀이겠지만 php가 동적으로 설치 되어 있어야 합니다.) 

2. sourceforge를 통해 해당 파일을 다운 받습니다. (http://sourceforge.net/projects/php-screw/)
 
다운이 안되면 첨부파일 php_screw-1.5.tar.gz  이용하세요


3. 저는 해당 소스를 /usr/local/src 디렉토리에 옮겨 놓았습니다.
  [root@localhost src]# pwd
  /usr/local/src
  [root@localhost src]# ls
  php_screw-1.5.tar.gz

4. 소스 압축 해제
  [root@localhost src]# tar xvzf php_screw-1.5.tar.gz 
  php_screw-1.5/
  php_screw-1.5/zencode.c
  php_screw-1.5/LICENSE
  php_screw-1.5/tools/
  php_screw-1.5/tools/zencode.c
  php_screw-1.5/tools/Makefile
  php_screw-1.5/tools/screw.c
  php_screw-1.5/config.h
  php_screw-1.5/README.en
  php_screw-1.5/config.m4
  php_screw-1.5/Makefile.in
  php_screw-1.5/php_screw.c
  php_screw-1.5/php_screw.h
  php_screw-1.5/my_screw.h
  php_screw-1.5/README.jp

5. phpize 명령어를 이용하여 서버 정보에 맞는 configure 생성
  [root@localhost src]# cd php_screw-1.5
  [root@localhost php_screw-1.5]# /usr/local/php/bin/phpize 
  Configuring for:
  PHP Api Version: 20020918
  Zend Module Api No: 20020429
  Zend Extension Api No: 20050606

6. 생성된 소스 확인 
  [root@localhost php_screw-1.5]# ll
  합계 800
  -rw-rw-rw- 1 root root 1388 1월 12 2004 LICENSE
  -rw-r--r-- 1 root root 3151 4월 4 00:10 Makefile.global
  -rw-rw-rw- 1 root root 245 8월 1 2002 Makefile.in
  -rw-rw-rw- 1 root root 4052 10월 14 2007 README.en
  -rw-rw-rw- 1 root root 3290 10월 14 2007 README.jp
  -rw-r--r-- 1 root root 52186 4월 4 00:10 acinclude.m4
  -rw-r--r-- 1 root root 174501 4월 4 00:10 aclocal.m4
  drwxr-xr-x 2 root root 4096 4월 4 00:10 autom4te.cache
  drwxr-xr-x 2 root root 4096 4월 4 00:10 build
  -rwxr-xr-x 1 root root 41134 4월 4 00:10 config.guess
  -rw-r--r-- 1 root root 1644 10월 13 2007 config.h
  -rw-r--r-- 1 root root 1540 4월 4 00:10 config.h.in
  -rw-rw-rw- 1 root root 593 4월 17 2002 config.m4
  -rwxr-xr-x 1 root root 29708 4월 4 00:10 config.sub
  -rwxr-xr-x 1 root root 279525 4월 4 00:10 configure
  -rw-r--r-- 1 root root 2226 4월 4 00:10 configure.in
  -rw-r--r-- 1 root root 0 4월 4 00:10 install-sh
  -rw-r--r-- 1 root root 143988 4월 4 00:10 ltmain.sh
  -rw-r--r-- 1 root root 0 4월 4 00:10 missing
  -rw-r--r-- 1 root root 0 4월 4 00:10 mkinstalldirs
  -rw-rw-rw- 1 root root 63 8월 1 2002 my_screw.h
  -rw-rw-rw- 1 root root 3142 10월 14 2007 php_screw.c
  -rw-rw-rw- 1 root root 194 8월 1 2002 php_screw.h
  drwxrwxrwx 2 root root 4096 10월 14 2007 tools
  -rw-rw-rw- 1 root root 1772 10월 14 2007 zencode.c

7. SEED key 변경
  - README를 잘 읽어보시면 알겠지만 암호화 할때 특정 키값에 따라 암화된 값이 달라집니다.
  그러므로 각자가 원하시는 값으로 변경 하시면 됩니다. my_screw.h 의 배열의 값을 변경 하시면 됩니다.
  값의 크기에 따른 속도 차이는 없다고 합니다.

  [root@localhost php_screw-1.5]# cat my_screw.h
    short pm9screw_mycryptkey[] = {
     11152, 368, 192, 1281, 62
    };

8. 컴파일 환경 설정
  [root@localhost php_screw-1.5]# ./configure --with-php-config=/usr/local/php/bin/php-config

9. 컴파일
  [root@localhost php_screw-1.5]# make
[내용추가] make 에러
/usr/local/src/php_screw-1.5/php_screw.c: In function 'pm9screw_compile_file':
/usr/local/src/php_screw-1.5/php_screw.c:78: error: too few arguments to function 'org_compile_file'
/usr/local/src/php_screw-1.5/php_screw.c:84: error: too few arguments to function 'org_compile_file'
/usr/local/src/php_screw-1.5/php_screw.c:93: error: too few arguments to function 'org_compile_file'
make: *** [php_screw.lo] 오류 1
php_screw.c 파일의 78,84,93 라인을 수정해줍니다.
org_compile_file(file_handle, type);                                 < 수정 전
org_compile_file(file_handle, type TSRMLS_CC);         < 수정 후
 
그리고 make clean, 다시 make 를 진행합니다.


10. 모듈 확인
  [root@localhost php_screw-1.5]# ll modules/
  합계 32
  -rw-r--r-- 1 root root 721 4월 4 00:25 php_screw.la
  -rwxr-xr-x 1 root root 26781 4월 4 00:25 php_screw.so

11. 모듈 위치 지정
  - 모듈을 확인 하고 make install 을 통해 자동으로 모듈을 특정 디렉토리를 이동 할 수 있지만 경로명이 직관적이지 않아 자체디렉토리를 만들어 줍니다.
  [root@localhost php_screw-1.5]# mkdir /usr/local/lib/php_modules
  [root@localhost php_screw-1.5]# mv modules/php_screw.so /usr/local/lib/php_modules

12. php.ini 설정
  - php.ini 의 설정을 통해 해당 모듈을 로드할 수 있게 합니다. 아래와 같이 
  [root@localhost php_screw-1.5]# vi /usr/local/lib/php.ini
  ......
  extension_dir = "./" 을 extension_dir = "/usr/local/lib/php_modules" 로 수정 및 아래 내용 추가
  extension=php_screw.so
  .....

13. 모듈 확인
  - 아파치 재시작 후 모듈 확인 
  [root@localhost php_screw-1.5]# /usr/local/apache/bin/apachectl restart
  [root@localhost php_screw-1.5]# php -i | grep php_screw
php_screw
php_screw support => enabled
PWD => /usr/local/src/php_screw-1.5
_SERVER["PWD"] => /usr/local/src/php_screw-1.5
_ENV["PWD"] => /usr/local/src/php_screw-1.5
  [root@localhost php_screw-1.5]# 

14. 암호화 명령어 컴파일
  - 모듈 추가가 완료 되면 소스를 암호화하는 툴을 컴파일 해야 합니다.
  해당 소스트 tools 라는 디렉토리에 있습니다.
  [root@localhost php_screw-1.5]# cd tools/
  [root@localhost tools]# pwd
  /usr/local/src/php_screw-1.5/tools

15. 컴파일 및 결과 확인
  [root@localhost tools]# make
  gcc -o screw screw.c zencode.c -lz
  [root@localhost tools]# ll
  합계 24
  -rw-r--r-- 1 root root 105 10월 14 2007 Makefile
  -rwxr-xr-x 1 root root 8644 4월 4 00:34 screw
  -rw-rw-rw- 1 root root 1541 10월 14 2007 screw.c
  -rw-rw-rw- 1 root root 1772 10월 14 2007 zencode.c

16. screw 라는 명려어를 이용해서 암호화하기
  - 사용하기 쉽게 path가 잡혀있는 경로 이동 하기 것이 좋을듯합니다.
  - test.php 자연수를 입력 받아 구구단을 출력하는 소스입니다.
  [root@localhost tools]# mv screw /usr/local/bin
  [root@localhost tools]# cd /home/test/public_html/
  [root@localhost public_html]# ll
  합계 4
  -rw-r--r-- 1 root root 1398 4월 4 00:39 test.php
  [root@localhost public_html]# screw test.php 
  Success Crypting(test.php)
  [root@localhost public_html]# ll
  합계 8
  -rw-r--r-- 1 root root 768 4월 4 00:44 test.php
  -rw-r--r-- 1 root root 1398 4월 4 00:44 test.php.screw

17. 암호화 파일 확인 및 원소스 삭제
  - 위의 결과와 같이 소스이름뒤 .screw 가 붙은 파일이 원 소스이다. 백업 후 삭제 해준다.
  - 암호화 파일 확인
[root@localhost public_html]# cat test.php
생략
 
결론

  설치 및 운영에는 특별히 신경 쓴 부분이 없다. 그러나 서버 이전시 문제 되는 부분이 있다. my_screw.h 에 설정된 SEED key 값을 모르게 된다면 아무리 모듈을 만들어도 해당 소스 웹출력이 되지 않습니다. 원 소스 백업이 중요하며 해당 SEED key 값도 백업 해 놓는것도 중요합니다.

댓글목록

등록된 댓글이 없습니다.

전체 80
게시물 검색
PHP 목록
번호 제목 글쓴이 조회 날짜
60 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4017 10-19
59 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2960 10-22
58 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2906 05-14
57 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3417 02-22
56 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3038 02-22
55 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2855 02-22
54 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3341 12-09
53 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3030 09-23
52 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2908 09-21
51 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2940 08-29
50 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2896 08-06
49 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3192 01-04
48 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3155 06-23
47 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3072 04-07
46 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4903 03-19
45 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3136 09-29
44 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3774 06-25
43 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3427 11-11
42 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3712 07-01
41 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4436 05-21