리눅스 php 보안설정


php.ini 파일을 다음과 같이 수정

1. allow_url_fopen 
On --> Off

2. magic_quotes_gpc 
Off --> On

3. register_globals 
On --> Off

** php 관련 프로그램 최신 버전 업그레이드


 웹서버 헤더에서 PHP 버전 정보 숨기기

php.ini 파일에서

expose_php = On 를
expose_php = Off 로 바꾸고 웹서버를 재실행하면 된다

### Apache 웹서버
(1) 소스 수정
src/include/httpd.h :
#define SERVER_BASEVERSION "Apache/[x.x.x.]"

(2) Conf 설정
httpd.conf 파일에서
ServerTokens 설정

ServerTokens Prod[uctOnly]
  --> Server: Apache
ServerTokens Min[imal]
  --> Server: Apache/1.3.0
ServerTokens OS
  --> Server: Apache/1.3.0 (Unix)
ServerTokens Full (or not specified)
  --> Server: Apache/1.3.0 (Unix) PHP/3.0 MyMod/1.2

### Proftpd

Conf 설정
proftpd.conf 파일에서
ServerIdent on "[x.x.x]"

### Sendmail
(1) 소스 수정
sendmail/version.c
char Version[] = "[x.x.x]";
(2) Conf 설정
/etc/sendmail.cf:
# SMTP initial login message
O SmtpGreetingMessage=$j [x.x.x]

### Bind
Conf 설정
/etc/named.conf 파일에서
options {
        directory "/var/named";
        version "x.x.x";
};

### SSH1/OpenSSH
소스 수정
version.h 파일에서
#define SSH_VERSION "[x.x.x]"

### SSH2
소스 수정
apps/ssh/ssh2version.h 파일에서
#define SSH2_VERSION "[x.x.x]"

### IMAP (imapd,ipop2d,ipop3d)
소스 수정
src/imapd/imapd.c 파일에서 char *version = "[x.x.x]";
src/ipopd/ipop2d.c 파일에서 char *version = "[x.x.x]";
src/ipopd/ipop3d.c 파일에서 char *version = "[x.x.x]";

 

에러처리 PHP 에 연결된 데이타베이스 외부프로그램등의 에러메세지가 노출되지않고 서버의 에러
로그에 남기도록 설정


log_erros = Off

mysql.trace_mode=Off


1. 
php 에서 오류 발생시 디렉토리 경로의 내용을 좌악 보여주면 이 정보를 악용할 소지가 있습니다.
php.ini 에서 display_errors를 Off 로 하면됩니다 (기본값은 On 입니다.)

display_errors=Off

2. 
phpinfo() 함수는 시스템내의 php,http,mysql 과 관련한 모든 정보를 보여 줍니다.
따라서 운용시 막아두는 것이 좋습니다. phpinfo() 스크립트를 금지 시키는 옵션 입니다.

disable_functions = phpinfo()

3. 
php 내에서 스크립트 함수를 ( exec() ) 모두 막을수 있지만, 불편함을 초래 할수 있습니다. 이경우 실행될 디렉토리를 지정해 주고 이 내에있는 것만 실행 하도록 하면 됩니다.

safe_mode = On  ( 디폴트는 Off 입니다. )
safe_mode_exec_dir=/usr/local/bin   ( 지정할 디렉토리 디폴트는 없습니다. )


#. 외부 파일 불러오기 방지
  ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
  allow_url_fopen=off  로 설정

 

#. 특수문자 필터링설정
   ; Magic quotes for incoming GET/POST/Cookie data.
   ; GET 방식으로 입력되는 ".."는 일반적으로 필터링 하도록 설계되고 있다.
   ; 쉘에서는 ".\./"는 ".." 과 동일하게 간주된다.
   ; 이에 특수문자에 대한 전체적인 제한이 필요하다.
   magic_quotes_gpc = On

 

#. 위험한 함수 사용방지
   ; This directive allows you to disable certain functions for security reasons.
   ; It receives a comma-delimited list of function names. This directive is
   ; *NOT* affected by whether Safe Mode is turned On or Off.
   disable_functions =

 

#. 안전한 세션관리
   ; Argument passed to save_handler.  In the case of files, this is the path
   ; where data files are stored. Note: Windows users have to change this
   ; variable in order to use PHP's session functions.
   ; As of PHP 4.0.1, you can define the path as:
   ;     session.save_path = "N;/path"
   ; where N is an integer.  Instead of storing all the session files in
   ; /path, what this will do is use subdirectories N-levels deep, and
   ; store the session data in those directories.  This is useful if you
   ; or your OS have problems with lots of files in one directory, and is
   ; a more efficient layout for servers that handle lots of sessions.
   ; NOTE 1: PHP will not create this directory structure automatically.
   ;         You can use the script in the ext/session dir for that purpose.
   ; NOTE 2: See the section on garbage collection below if you choose to
   ;         use subdirectories for session storage
   ; 이 부분을 /tmp/session처럼 디렉토리를 따로 만들고 
   ; session.save_path = /tmp/session 디렉토리를
   ; chown nobody.nobody /tmp/session
   ; chmod 750 /tmp/session  이렇게 해주시면 됩니다.
   session.save_path = /tmp

 

#. 에러처리
   ; 만일 PHP나 연결된 데이터베이스, 외부 프로그램 등의 에러메시지가 임의의 사용자가 볼수 있도록 
   ; 화면에 나타난다면, 이것은 시스템의 정보를 노출하기 때문에 공격의 수단으로 될수 있다.
   ; 이에 에러메시지를 보여주기 보다는 서버의 에러 로그로 남기도록 설정을 바꿔주어야 한다.
   ;---------------------------------------------------------------------------------
   ; Log errors into a log file (server-specific log, stderr, or error_log (below))
   ; As stated above, you're strongly advised to use error logging in place of
   ; error displaying on production web sites.
   log_errors = Off
   ; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
   ; SQL-Erros will be displayed.
   mysql.trace_mode = Off 



출처: http://newsirin.tistory.com/101 [Nothing Else Matters]

이 글이 마음에 드셨나요?
지인과 공유해보세요.



Profile

Mr.키아

삶이란 꿈과 희망을 가지고 살아가야한다는 것이다.
대한민국 20대 청년으로 열심히 살아가고있으며
키큰아이, 키큰아이닷컴 등 현재 몇몇 서비스를 운영하고 있습니다.



엮인글 0

https://mr.kikni.com/tip/trackback?document_srl=5925&key=77e

댓글 0

"php 보안설정"의 첫댓글을 달아주세요!

댓글 달기

댓글을 쓸 수 있는 권한이 없습니다.

팁공유

간단한 일상 팁부터 지식이 필요한 테크니컬 자료를 수집 하는 공간입니다.


커뮤니티



제휴


당신의 인터넷은 감청당하고 있습니다.

광고



kikni