Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

쟝이의 세상

추가 보안 적용 본문

자료

추가 보안 적용

zyangee 2024. 9. 20. 13:32

TRACE, PUT, DELETE 메소드 비활성화하여 보안 강화 조치

< 각 메소드 비활성화 이유 >

PUT, DELETE : 임의로 서버 내 파일 생성 또는 삭제할 수 있는 메소드
-> 인가되지 않은 사용자로 인해 서버가 조작될 위험 존재

TRACE: 클라이언트가 서버로 전송한 요청을 다시 그대로 반환해주는 메소드
-> 쿠키 및 세션 값이 그대로 반환되어 XST(Cross-Site Tracing) 같은 공격에 사용 (사용자의 쿠키나 민감한 정보를 탈취할 수 있는 보안 취약점을 제공)

 

- web.config 파일 수정

<확인 결과>
Allow에 설정했던 GET, POST만 보이는 것을 확인할 수 있다.

 

 

robots.txt 설정

민감한 정보의 노출 방지, 중복 콘텐츠 관리, 서버 부하 감소 등의 목적

robots.txt

: 검색 엔진 로봇(크롤러)가 웹사이트의 특정 페이지나 디렉토리를 크롤링하지 않도록 지침을 제공하기 위해 사용

ex) 비밀번호가 필요한 페이지나 개인 정보가 포함된 페이지를 로봇이 수집하지 못하도록 차단 가능

  • User-agent: * - 모든 검색 엔진 크롤러에게 적용
  • Disallow: /private - /private 디렉토리 내의 페이지를 크롤링하지 않도록 설정
  • Allow: /public - /public 디렉토리 내의 페이지는 크롤링할 수 있도록 허용

 

XSS 공격 방지 설정

X-XSS-Protection 헤더

: 입력값을 검증하는 방식. XSS 공격을 감지할 때 페이지 로드를 중지시킬 수 있다.

지시자 설명
0; XSS 필터 비활성화
1; XSS 필터 활성화, 악성 스크립트 삭제
1; mode=block XSS 필터 활성화 및 공격 감지 시 브라우저 페이지의 로드 제한
1; report=<URI> XSS 필터 활성화 및 공격 감지 시 보고
<확인 결과>
아래 X-XSS-Protection 이 설정한 대로 header에 나오는 것을 확인할 수 있다.

 

 

웹 응용 프로그램 방화벽(WAF) 사용

웹 서비스의 공격을 효과적으로 차단할 수 있는 웹 방화벽

-> 웹 서비스를 통해서 공격을 시도하는 XSS, SQL Injection, Command Execute와 같은 공격을 효과적으로 차단하는 역할

 

1) ModSecurityIIS_2.9.1-64b.msi 파일 다운로드

 

2) ModSecurity 설정

Perform ModSecurityIIS configuration. 체크 안했을 때

1) 환경변수 먼저 설정
-> C:\Windows\System32\inetsrv\
-> C:\Program Files\ModSecurity IIS


2) cmd에 명령어 입력 후 IIS 재시작

-> appcmd.exe install module /name:"ModSecurity IIS" /image:"C:\Windows\System32\inetsrv\ModSecurityIIS.dll" -> iisreset

 

3) IIS 설정 파일 확인 및 수정

-> 위치 : C:\Windows\System32\inetsrv\config\applicationHost.config

 

4) 로그파일 별도로 기록하기 위한 코드 추가

-> 위치: C\Program Files\ModSecurity IIS\modsecurity.conf

<각 코드 설명>
- SecAuditLogParts ABIJDEFHZ

A Audit event
B Request body
I Input data
J JSON encoded request body
D Data related to the audit event
E Request headers
F Response headers
H Response body
Z Trailing empth line
- SecAuditLogType Serial
: 로그가 하나의 파일에 연속적으로 기록
- SecAuditLog C:\inetpub\log\modsec_audit.log
: 감사 로그 파일이 저장될 경로 설정

 

 

SQL Injection 공격 시도

ID 값에 OR '1'='1 을 입력하면??

시큐어 코드를 적용한 로그인 페이지 시큐어 코드를 적용하지 않은 로그인
로그인 실패 메시지 창이 출력 사용하고 있는 SQL Server에 대한 ODBC 드라이버 정보가 나타난다.
쿼리 문법 오류가 있는 경우, SQL 오류 메시지가 나타날 수 있다.

 

 

URL Rewrite 설정

1) URL Rewrite 설치

(링크: https://www.iis.net/downloads/microsoft/url-rewrite)

 

2) web.config 파일 수정

rule 1. Rewrite to Product
stopProcessing="true" 이 규칙이 매칙되면 다른 규칙은 처리되지 않는다.
match url="^products/([0-9]+)$" URL이 products/ 다음에 숫자(ex. 123)가 오는 경우에 매칭
- ^ : URL의 시작
- $ : URL의 끝
action type="Rewrite" url="product.aspx?id={R:1}" 실제 URL을 변경하는 작업
{R:1} : 정규 표현식에서 첫 번째 괄호에 매칭된 값을 의미
즉, products/123 요청이 product.aspx?id=123으로 변경
rule2. Redirect to HTTPS
stopProcessing="true" 이 규칙이 매칙되면 다른 규칙은 처리되지 않는다.
match url="(.*)" 모든 URL에 매칭
<add input="{HTTPS}" pattern="off" /> HTTPS가 비활성화된 경우에만 이 규칙이 적용
즉, 현재 요청이 HTTP일 때만 리디렉션
action type="Redirect" url="https://{HTTP_HOST}/{R:1}" 클라이언트를 새로운 URL로 리디렉션
{HTTP_HOST} : 현재 요청의 호스트 이름
{R:1} : 요청된 URL의 경로
ex) http://example.com 일 경우 https://example.com 으로으로 리디렉션
redirectType="Permanent" 301 리디렉션을 의미
검색 엔진 URL이 영구적으로 변경되었음을 알리는 데 사용

 

3) 리디렉션 확인

https 로 리디렉션 되는 것을 확인할 수 있다.

 

 

CRS 설정

1) CRS 다운로드 및 압축 해제

(링크: https://github.com/coreruleset/coreruleset/releases/tag/v4.6.0)

 

2) modsecurity.conf 파일 수정

Include "C:/Program Files/ModSecurity CRS/crs-setup.conf.example"

ModSecurity에서 사용할 기본 설정을 로드

Include "C:/Program Files/ModSecurity CRS/rules/*.conf"

ModSecurity에서 활성화할 규칙을 설정하는데 사용

 

 

HttpOnly 플래그와 CSP 설정, HTTP응답헤더 rewrite 규칙 추가

- web.config 파일 수정

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <!-- HTTP 압축 활성화 -->
    <httpCompression>
      <dynamicTypes>
        <add mimeType="text/*" enabled="true"/>
      </dynamicTypes>
      <staticTypes>
        <add mimeType="text/*" enabled="true"/>
      </staticTypes>
    </httpCompression>

    <!-- MIME 타입 설정 -->
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>

    <!-- Content Security Policy (CSP) 설정 : 현재의 문제- CSP를 활성화 하면 사이트 서비스가 제대로 되지 않음-->
    <httpProtocol>
      <customHeaders>  <!--엄격한 처리-->
        <add name="Content-Security-Policy" value="default-src 'self'; script-src 'self' https://www.google.com https://cdnjs.cloudflare.com https://code.getmdl.io; style-src 'self' https://maxcdn.bootstrapcdn.com https://code.getmdl.io https://fonts.googleapis.com; img-src 'self' data: https://*; connect-src 'self' https://update.googleapis.com https://clientservices.googleapis.com; font-src 'self' https://fonts.googleapis.com; report-uri /csp-report-endpoint;" />        
<!--느슨한 처리
<add name="Content-Security-Policy" value="default-src *; script-src *; style-src *; img-src *; connect-src *; font-src *; report-uri /csp-report-endpoint;" /> -->
      </customHeaders>
    </httpProtocol>

    <!-- HTTP 응답 헤더 리라이트 규칙 추가 -->
    <rewrite>
      <outboundRules>
        <rule name="Add HttpOnly" enabled="true" stopProcessing="true">
          <match serverVariable="RESPONSE_Set-Cookie" pattern="^(.*)(; HttpOnly)?$" />
          <action type="Rewrite" value="{R:1}; HttpOnly" />
        </rule>
      </outboundRules>
    </rewrite>
  </system.webServer>
</configuration>