독까의 이야기

IIS + node.js  환경을 구축하였다. 


진행하면서 확인 된 사항들에 대해 기록을 한다. 



node.js 프로그램은 공식 홈페이지에서 다운 받으면 된다. 


https://nodejs.org/ko/



iisnode 모듈은 github 에서 다운 받으면 된다.


https://github.com/tjanczuk/iisnode/wiki/iisnode-releases


두 개 다 default 로 설치를 진행 하면 된다. 



필수로 구축되어 있어야 하는 사항에 대해 확인 한다. 



1.  웹폴더가 등록 된 파티션에 Users 의 "읽기" 권한이 할당되어 있어야 한다. 없을시 아래와 같은 오류 출력 된다. 


Application has thrown an uncaught exception and is terminated:
Error: EPERM: operation not permitted, lstat 'd:\'
    at Object.realpathSync (fs.js:1617:13)
    at toRealPath (module.js:164:13)
    at Function.Module._findPath (module.js:213:22)
    at Function.Module._resolveFilename (module.js:545:25)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Program Files (x86)\iisnode\interceptor.js:210:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)






2.  해당 웹사이트의 web.config 에 구문 추가가 필요하다. 


        <handlers>
            <add name="iisnode" path="*.js" verb="*" modules="iisnode" resourceType="File" />
        </handlers>


만약 구문을 추가 했는데, 아래와 같은 오류가 출력 된다면 구문을 한 줄 더 추가 한다. (x64 버전 설치시에만)


The iisnode module is unable to start the node.exe process. Make sure the node.exe executable is available at the location specified in the system.webServer/iisnode/@nodeProcessCommandLine element of web.config. By default node.exe is expected in one of the directories listed in the PATH environment variable.


 <iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade" nodeProcessCommandLine="\program files\nodejs\node.exe"/>



3.  iisnode 폴더가 웹사이트 루트 디렉토리에 생성되어 있어야 한다. 폴더가 없거나 생성 할 수 있는 권한이 없을 시에는 아래와 같은 오류 출력 된다. 


iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1002
HTTP reason: Internal Server Error

You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'.
In addition to the log of stdout and stderr of the node.exe process, consider using debugging and ETW traces to further diagnose the problem.
The node.exe process has not written any information to stderr or iisnode was unable to capture this information. Frequent reason is that the iisnode module is unable to create a log file to capture stdout and stderr output from node.exe. Please check that the identity of the IIS application pool running the node.js application has read and write access permissions to the directory on the server where the node.js application is located. Alternatively you can disable logging by setting system.webServer/iisnode/@loggingEnabled element of web.config to 'false'. 


루트 디렉토리에 응용프로그램풀 계정을 쓰기 및 삭제 권한 포함하여 할당하면, 자동으로 iisnode 폴더를 생성하고, 로그 기록 및 삭제 해준다.


또는 iisnode 폴더를 생성하고, 해당 폴더에 응용프로그램풀 계정을 쓰기 및 삭제 권한 포함하여 할당하면 로그 기록 및 삭제 가능하다. 




쓰기 권한이 할당 된 폴더는 반드시 처리기 매핑에서 스크립트 사용 권한을 제거해야 한다. 


보안 침해로 인해 웹쉘 업로드 및 스크립트 실행으로 인해 서버 권한 탈취 가능성을 방지해야 한다. 



특정 업체의 보안 정책에 따른 IIS 설정 변경이 필요함.

[재현절차]
 1.[보안] Response 값 헤더에 서버정보 노출
   ex) server : Microsoft-IIS/8.5
 
 [결함내용]
 1.[보안] 부적절한 환경 설정 - 불필요한 서버 정보 노출

 

OS : Windows 2012 R2 / IIS 8.5

URL Rewrite 2.0 다운로드 및 설치


IIS 최상단 트리의 URL Rewrite 기본 설정 진행.

 

[아웃바운드 정책 추가]

RESPONSE_SERVER

 RESPONSE_X-POWERED-BY

RESPONSE_X-ASPNET-VERSION

 

웹사이트 출력 후, 개발자 도구를 이용하여 응답 헤더 조회시 아래와 같이 결과 확인 가능.

 

그런데, 위의 설정으로는 정상적으로 호출이 완료 된 웹페이지에 대해서만 적용되는 걸로 확인 됨.

존재하지 않는 페이지 호출이나, .net 호출시에는 안 먹힘. (서버 정보가 그대로 노출 됨)

 

어떻게 처리를 해야 하나 구글 검색을 했는데, 모듈을 생성해서 적용하는 것을 권장 했음.

"How to remove IIS/ASP.NET Response Headers"

https://serverfault.com/questions/24885/how-to-remove-iis-asp-net-response-headers

 

본문에 있는 내용을 적용해볼까도 했는데, 이미 만들어진 모듈이 있을 것 같아서 다시 검색.

 

EASILY REMOVE UNWANTED HTTP HEADERS IN IIS 7.0 TO 8.5

https://www.dionach.com/blog/easily-remove-unwanted-http-headers-in-iis-70-to-85

내용을 읽어보니 설치 후 바로 적용이 가능한 것으로 보임.

개발 페이지에 접속하여 내용을 확인.

https://github.com/dionach/stripheaders

MS에서 만든것이 아닌, 서드파티 모듈 이기는 했지만 일단 적용을 해보기로 함.

 

iis_stripheaders_module_1.0.5.msi

 

이상 없이 설치 완료 후, web.config 에 아래의 구문 추가.

    <stripHeaders>
      <header name="Server" />
      <header name="X-Powered-By" />
      <header name="X-Aspnet-Version" />

    </stripHeaders>

    </system.webServer>

 

웹페이지 호출 테스트 진행을 해보니, Server 정보 부분이 제거 되어 있음을 확인.

보안에 대한 검증이 완료 된 것이라면, 이 모듈을 사용하는 것이 간편해서 좋을 것 같음.


IIS 6.0 + 톰캣 5.5 연동 웹사이트 .html 및 .asp 호출 불가

 

1.  IIS 에 test.com 신규 웹사이트 세팅

2.  생성 된 웹사이트에 가상 디렉토리 생성
  -  별칭 : jakarta
  -  경로 : isapi 모듈 이 등록되어 있는 경로 설정 / c:\tomcat\ISAPI\

3.  웹사이트 선택 우클릭 - 속성 - ISAPI 필터 - 추가 - jakarta - 모듈 경로 선택 : c:\tomcat\ISAPI\isapi_redirect.dll - 권한은 "실행" 포함

4.  index.jsp 파일 생성 후 호출 테스트 / 정상 호출 확인

5.  index.asp 및 index.html 파일 생성하여 호출 테스트 / 404 에러 발생 / 에러 코드 발생 주체는 톰캣 / jsp 를 제외한 기타 문서는 IIS 에서 처리해야 되는게 원칙
     ->  IIS 로그 확인 / .jsp 호출 로그만 기록되어 있음

6.  c:\tomcat\confg\uriworkermap.properties 편집
  -  전역 처리 설정값 /*=wlb 주석 처리     =>  #/*=wlb

7.  톰캣 및 IIS 재시작

8.  .html 및 .asp 정상 호출

9.  .jsp 파일 자동 호출 불가 / 기본 문서에 등록되어 있는 .jsp 파일도 웹브라우저에서 직접 파일명 지정해서 호출해야 됨

10.  c:\tomcat\conf\uriworkermap.properties 내용 원복

11.  c:\tomcat\conf\server.xml 편집

12.  호스트 추가
      <Host name="test.com"  appBase="D:\WWW\TEST" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
      <Context path="" docBase="D:\WWW\TEST" debug="5">
      <Logger className="org.apache.catalina.logger.FileLogger" prefix="test.com_log." suffix=".txt" timestamp="true" />
      </Context>
      </Host>
      </Engine>
      </Service>

13.  톰캣 및 IIS 재시작

14.  상태 변동 없음

15.  위 server.xml 추가 내용 중 Alias 값 추가
      <Host name="test.com"  appBase="D:\WWW\TEST" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
      <Context path="" docBase="D:\WWW\TEST" debug="5">
      <Logger className="org.apache.catalina.logger.FileLogger" prefix="test.com_log." suffix=".txt" timestamp="true" />
      </Context>
      <Alias>www.test.com</Alias>
      <Alias>test.com</Alias>
      </Host>
      </Engine>
      </Service>

16.  톰캣 및 IIS 재시작

17.  .asp / .jsp / .html 모두 정상 출력