http://a.site 로 접속 하는 주소를 http://a.site:8000 으로 포워딩 하고 싶을때. 뭐... a.site 로 들어와도 프로그램의 변수로 구분을 해서 들어가도 되겠지만 특별한 경우 a.site 로 들어왔는데 포트를 달아줘야 할경우 사용하면 된다. html의 meta 테그를 써도 되지만 Apache 차원의 포워딩을 해보자
ModSecurity 는 아파치(apache)에서 사용하는 대표적인 웹방화벽 모듈이다. 아파치에 모듈을 설치하고, 룰(Rule) 설정을 통해 설정한 조건에 맞는 경우 차단을 할 수 있다. modsecurity 2.x 을 기준으로한 간단한 예이다.
- 웹서버명을 숨기거나 속인다.
SecServerSignature "lighttpd"
- 특정 메소드의 사용만 허용한다. (POST, GET, OPTIONS, HEAD 메소드만 허용)
SecRule REQUEST_METHOD "!^((?:(?:POS|GE)T|OPTIONS|HEAD))$" \ "phase:1,log,auditlog,status:501,msg:'Method is not allowed by policy', severity:'2',,id:'960032',"
- 요청한 HTTP 프로토콜 버전이 1.0, 1.1이 아닐 경우 차단한다.
SecRule REQUEST_PROTOCOL "!^HTTP/(1\.[01])$" \ "t:none, deny,log,auditlog,status:505,msg:'HTTP protocol version is not allowed by policy', severity:'2',,id:'960034',"
- GET, HEAD 메소드는 Content-Length가 0이 아닌 경우는 차단하고, POST는 Content-Length header가 없으면 차단한다.
SecRule REQUEST_METHOD "^(GET|HEAD)$" "chain,deny,log,auditlog,status:400,msg:'GET or HEAD requests with bodies', severity:'2',,id:'960011'," SecRule REQUEST_HEADERS:Content-Length "!^0?$"
SecRule REQUEST_METHOD "^POST$" "chain,deny,log,auditlog,status:400,msg:'POST request must have a Content-Length header',,id:'960012',severity:'4'" SecRule &REQUEST_HEADERS:Content-Length "@eq 0"
오픈소스 IDS인 snort에 기본 룰을 제공하는 것처럼 ModSecurity 에서도 modsecurity-core-rules 이름으로 룰 파일을 제공하고 있으니 참고하기 바란다. 룰에 대해서는 이만하고 원래 꺼내려한 얘기거리로 들어가자.
REMO를 사용하기 위해서는 ruby 1.8.2이상, irb, sqlite3-ruby 환경이 필요하다. 또한 ModSecurity 모듈이 설치되지 않은 테스트나 개발 서버, 개인 PC 등에 설치해도 무관하다. 다음과 같이 실행한 후 http://서버:3000/main/index 로 접속하면 설정화면을 볼 수 있다.
wget http://remo.netnea.com/files/remo-0.2.0.tar.gz tar xvzf remo-0.2.0.tar.gz cd remo-0.2.0 ruby script/server
REMO화면에서 메소드와 URI등을 새로 입력한 다음, 원하는 조건을 정의한다. 그 후 'generate' 버튼을 누르면 파일로 룰셋 파일을 다운로드 받을 수 있다. 받은 룰셋을 다음과 같이 apache 설정에서 include해주면 된다.
<IfModule mod_security2.c> Include /파일경로/rulefile.conf </IfModule>
REMO툴은 ModSecurity 룰 생성의 모든 것을 제공해주지는 않는다. modsecurity-core-rules 룰 파일을 보면 룰 설정이 쉽지않다는 것을 알 수 있다. 이 툴은 이런 복잡한 룰을 보고 고개를 설레설레 젓지 않도록 보조적인 역할을 하는 툴로 여기면 된다.
AuthName WebLog ## 인증창의 이름 AuthType Basic ## 인증 타입 보통 Basic를 사용 AuthUserFile /usr/local/apache/htdocs/weblog/.htpasswd ## htpasswd를 이용하여 생성되는 .htpasswd의 위치 AuthGroupFile /dev/null ## 그룹으로 인증할경우는 그룹 파일을 아닐경우 null 을 넣는다. <Limit GET POST> require valid-user ## 인증된 사용자만 접속 허용 하기 </Limit>
htpasswd -n[mdps] username htpasswd -nb[mdps] username password -c Create a new file. -n Don't update file; display results on stdout. -m Force MD5 encryption of the password. -d Force CRYPT encryption of the password (default). -p Do not encrypt the password (plaintext). -s Force SHA encryption of the password. -b Use the password from the command line rather than prompting for it. -D Delete the specified user. On Windows, NetWare and TPF systems the '-m' flag is used by default. On all other systems, the '-p' flag will probably not work.