아파치 톰캣 보안 가이드

2016. 8. 26. 14:12·프로젝트 관련 조사/웹
반응형

출처:https://geekflare.com/apache-tomcat-hardening-and-security-guide/


Apache Tomcat Hardening and Security Guide



Tomcat is one of the most popular Servlet and JSP Container servers. It’s used by some of following high traffic websites:

  • LinkedIn.com
  • Dailymail.co.uk
  • Comcast.net
  • Wallmart.com
  • Reuters.com
  • Meetup.com
  • Webs.com

Below diagram shows the market position of Tomcat in terms of popularity and traffic compared.

Having default configuration may have much sensitive information, which helps hacker to prepare for an attack the Tomcat server. This practical guide provides you the necessary skill set to secure Apache Tomcat server.

It was great to see the overwhelming response on my article about Apache Web Server Hardening and Security Guide. In this article, I will talk about how to harden and secure Apache Tomcat server. Following are tested on Tomcat 6.x and I don’t see any reason it won’t work with Tomcat 5.x, 7.x or 8.x

Audience

This is designed for Middleware Administrator, Application Support, System Analyst or anyone working or eager to learn Tomcat Hardening and Security. Fair knowledge of Tomcat & UNIX command is mandatory.

BONUS (Download in PDF Format): Tomcat Security & Hardening Guide

Pre-requisite

We require some tool to examine HTTP Headers for verification. Let’s do this by install firebug add-on in Firefox.

  • Open Firefox
  • Access https://addons.mozilla.org/en-US/firefox/addon/firebug/
  • Click on Add to Firefox

  • Click on Install Now
  • Restart Firefox
  • You can see firebug icon at right top bar

We will use this icon to open firebug console to view HTTP Headers information.

There are many online tools also available which helps to check in HTTP header information. Below are some of them you can try out.

  • www.seositecheckup.com
  • www.apikitchen.com
  • http://web-sniffer.net

Note: as a best practice, you must take backup of any file you are about to modify.

We will call Tomcat Installation folder as $tomcat throughout this guidelines.

1. Remove Server Banner

Removing Server Banner from HTTP Header is one of the first things to do as hardening. Having server banner expose the product you are using and leads to information leakage vulnerability.

Implementation:

  • Go to $tomcat/conf folder
  • Modify server.xml by using vi
  • Add following under Connector port and save the file
Server =” “

Ex: –

<Connector port="8080" protocol="HTTP/1.1" 
connectionTimeout="20000" 
Server =" " 
redirectPort="8443" />

Verification:

  • Open Firefox with firebug
  • Access Tomcat application
  • You will notice Server value is blank now.

2. Starting Tomcat with a Security Manager

Security Manager protects you from an untrusted applet running in your browser. Running Tomcat with a security manager is definitely better than running without one. Tomcat has very good documentation on Tomcat Security Manager. 

Implementation:

All you got to do is to start tomcat with –security argument.

Chandans:bin root# ./startup.sh -security
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Using Security Manager Chandans:bin root#

3. Enable access log logging

The default configuration doesn’t capture access logs. The access log is very useful in troubleshooting to check request type, requester IP address, status code, etc.

Implementation:

  • Go to $tomcat/conf
  • Modify server.xml by using vi
  • Go to the end of the file and uncomment Valve entry for valves.AccessLogValue
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" 
prefix="localhost_access_log."
suffix=".txt"
pattern="common" resolveHosts="false"/>
  • Restart Tomcat server and you should see localhost_access_log is created under $tomcat/logs folder

4. Enforced HTTPS

It’s good to force redirect all HTTP requests to HTTPS to ensure web application data transmission are over SSL Certification.

Implementation:

  • Go to $tomcat/conf folder
  • Modify web.xml by using vi
  • Add following before </web-app> syntax
<security-constraint> 
<web-resource-collection> 
<web-resource-name>Protected Context</web-resource-name> 
<url-pattern>/*</url-pattern>
</web-resource-collection> 
<user-data-constraint> 
<transport-guarantee>CONFIDENTIAL</transport-guarantee> 
</user-data-constraint> 
</security-constraint>
  • Restart Tomcat and access web application to verify.

Note: ensure Tomcat is configured to run on SSL else it will break the application accessibility.

5. Add Secure flag in cookie

It is possible to steal or manipulate web application session and cookies without having a Secure flag in HTTP Header as Set-Cookie.

Implementation:

  • Go to $tomcat/conf folder
  • Modify server.xml by using vi
  • Add following in Connector port
Secure=”true

Ex:

<Connector port="8080" protocol="HTTP/1.1" 
connectionTimeout="20000" 
Server=" " 
Secure="true" 
redirectPort="8443" />

Verification:

  • Open Firefox with firebug
  • Access your application and check HTTP response header, you should see Secure flag

6. Add HttpOnly in cookie

Best practice to have this enabled at application code level. However, due to bad programming or developer’s unawareness, it comes to Web Infrastructure.

Implementation:

  • Go to $tomcat/conf folder
  • Modify context.xml by using vi
  • Add following  in Context directive
usehttponly=”true”

Ex:-

<context usehttponly="true">
...
</context>

7. Enable Secure Socket Layer (SSL)

To enable Tomcat to listen over HTTPS protocol, you must configure tomcat with SSL. If you are new to SSL, you can refer to Beginner’s Guide to SSL. This assumes you have SSL Certificate imported under keystore.

Implementation:

  • Go to $tomcat/conf folder
  • Modify server.xml by using vi
  • Add following under Connector port
SSLEnabled=”true” scheme=”https” keystoreFile="conf/keystore" keystorePass="password"

Ex:

<Connector port="8080" protocol="HTTP/1.1" 
connectionTimeout="20000" 
Server=" " 
Secure="true" 
SSLEnabled="true" scheme="https" keystoreFile="conf/keystore" keystorePass="password" clientAuth=”false” sslProtocol=”SSLv3” 
redirectPort="8443" />

8. Run Tomcat from non-privileged account

It’s good to use a separate non-privileged user for Tomcat. The idea here is to protect other services running in case of any security hole.

Implementation:

  • Create a UNIX user
  • Change $tomcat ownership to newly created UNIX user

9. Remove default/unwanted applications

By default, Tomcat comes with following web applications, which may or not be required in a production environment. You can delete them to keep it clean and avoid any known security risk with Tomcat default application.

  • ROOT – Default welcome page
  • Docs – Tomcat documentation
  • Examples – JSP and servlets for demonstration
  • Manager, host-manager – Tomcat administration

10. Change SHUTDOWN port and Command

By default, tomcat is configured to be shutdown on 8005 port. Do you know you can shutdown tomcat instance by doing a telnet to IP:port and issuing SHUTDOWN command?

Chandans # telnet localhost 8005
Trying ::1... telnet:
connect to address ::1:
Connection refused Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
SHUTDOWN Connection closed by foreign host.
Chandans #

You see having default configuration leads to high-security risk. It’s recommended to change tomcat shutdown port and default command to something unpredictable.

Implementation:

  • Go to $tomcat/conf folder
  • Modify server.xml by using vi
<Server port="8005" shutdown="SHUTDOWN">

8005 – Change to some other unused port

SHUTDOWN – Change to something complicated

Ex-

<Server port="8867" shutdown="NOTGONNAGUESS">

11. Replace default 404, 403, 500 page

Having default page for not found, forbidden, server error exposes Tomcat version and that leads to security risk if you are running with vulnerable version. Let’s look at default 404 page.

To mitigate, you can first create a general error page and configure web.xml to redirect to general error page.

Implementation:

  • Go to $tomcat/webapps/$application
  • Create an error.jsp file
#vi error.jsp 
<html>
<head> 
<title>404-Page Not Found</title>
</head>
<body> That's an error! </body>
</html>
  • Go to $tomcat/conf folder
  • Add following in web.xml by using vi. Ensure you add before </web-app> syntax
<error-page> 
<error-code>404</error-code> 
<location>/error.jsp</location>
</error-page>
<error-page> 
<error-code>403</error-code> 
<location>/error.jsp</location>
</error-page>
<error-page> 
<error-code>500</error-code> 
<location>/error.jsp</location>
</error-page>
  • Restart tomcat server. Now, let’s test it.

As you can see tomcat information is no more exposed.

You can do this for java.lang.Exception as well. This will help in not exposing tomcat version information if any java lang exception.

Just add following in web.xml and restart tomcat server.

<error-page> 
<exception-type>java.lang.Exception</exception-type> 
<location>/error.jsp</location>
</error-page>

I hope above guide gives you an idea no securing Tomcat. If you like this, please share with your friends.

반응형
저작자표시 (새창열림)

'프로젝트 관련 조사 > 웹' 카테고리의 다른 글

ASP request.ServerVariable("QUERY_STRING")  (0) 2016.11.16
Tomcat SSL 적용 (테스트 인증서-Trial Version)  (0) 2016.08.29
스프링 시큐리티 로그인  (0) 2016.08.08
3장 데이터베이스로 이동하는 Authentication 정보  (0) 2016.08.08
1장 스프링 시큐리티란?  (0) 2016.08.08
'프로젝트 관련 조사/웹' 카테고리의 다른 글
  • ASP request.ServerVariable("QUERY_STRING")
  • Tomcat SSL 적용 (테스트 인증서-Trial Version)
  • 스프링 시큐리티 로그인
  • 3장 데이터베이스로 이동하는 Authentication 정보
호레
호레
창업 / IT / 육아 / 일상 / 여행
    반응형
  • 호레
    Unique Life
    호레
  • 전체
    오늘
    어제
    • 분류 전체보기
      • 법률
        • 기본
        • 개인정보보호법
        • 정보통신망법
        • 전자금융거래법
        • 전자금융감독규정
        • 신용정보법
        • 온라인투자연계금융업법
      • 창업
        • 외식업 관련
        • 임대업 관련
        • 유통업 관련
        • 세무 관련
        • 마케팅 관련
        • 기타 지식
        • 트렌드
        • Youtube
      • IT기술 관련
        • 모바일
        • 윈도우
        • 리눅스
        • MAC OS
        • 네트워크
        • 빅데이터 관련
        • A.I 인공지능
        • 파이썬_루비 등 언어
        • 쿠버네티스
        • 기타 기술
      • 퍼블릭 클라우드 관련
        • Azure
        • GCP
        • AWS
      • 정보보안 관련
        • QRadar
        • Splunk
        • System
        • Web
      • 기타
        • 세상 모든 정보
        • 서적
      • 게임 관련
        • 유니티
      • 부동산
      • 맛집 찾기
        • 강남역
        • 양재역
        • 판교역
        • ★★★★★
        • ★★★★
        • ★★★
        • ★★
        • ★
      • 결혼_육아 생활
        • 리얼후기
        • 일상
        • 육아
        • 사랑
        • Food
      • 영어
        • 스피킹
        • 문법
        • 팝송
        • 영화
      • K-컨텐츠
        • 드라마
        • 영화
        • 예능
      • 독서
      • 프로젝트 관련 조사
        • 시스템 구축
        • 로그 관련
        • 웹
        • APT
        • 모의 해킹
        • DB
        • 허니팟
        • 수리카타
        • 알고리즘
        • FDS
      • 기업별 구내 식당 평가
        • 한국관광공사
        • KT telecop
        • KT M&S
        • KT powertel
        • KT cs 연수원
        • 진에어
      • 대학 생활
        • 위드윈연구소
        • 진로 고민
        • 채용정보
        • 자동차
        • 주식
        • 악성코드
        • 게임 보안
      • 쉐어하우스
  • 블로그 메뉴

    • 홈
    • 게임 관련
    • IT 기술 관련
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    돈까스
    무역전쟁
    수제버거존맛
    판교맛집
    판교
    마케팅
    보안가이드
    복리후생
    맛집
    런치
    유니티
    판교역
    수제버거맛집
    상호관세
    AWS
    대통령
    쥬쥬랜드
    이재곧죽습니다
    점심
    수제버거
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
호레
아파치 톰캣 보안 가이드
상단으로

티스토리툴바