Recent Posts
Recent Comments
Link
07-02 05:38
Today
Total
관리 메뉴

삶 가운데 남긴 기록 AACII.TISTORY.COM

JAVA 보안 Unrestricted Upload of File with Dangerous Type 본문

DEV&OPS/Java

JAVA 보안 Unrestricted Upload of File with Dangerous Type

ALEPH.GEM 2022. 8. 4. 15:26

Unrestricted Upload of File with Dangerous Type(위험한 형식 파일 업로드)

서버측에서 실행할 수 있는 파일(asp, jsp, php 등) 이 업로드 가능할 때, 이 파일을 이용해 시스템 내부 명령어를 실행하여 공격하는 방법입니다.

업로드하는 파일의 유효성 검사로 방어합니다.

white list 확장자만 업로드 합니다. 

업로드 디렉토리를 웹서버의 다큐먼트 외부에 설정합니다.

파일 실행 권한을 설정할 수 있는 경우 실행 권한을 제거합니다.

 

 

안전한 코드의 예

...
public void upload(HttpServletRequest request) throws SevletException{
    MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
    String next = (String)mRequest.getFileNames().next();
    MultipartFile file = mRequest.getFile(next);
    if(file == null)
        return;
        
    //업로드 파일 크기 제한
    int size = file.getSize();
    if(size > MAX_FILE_SIZE) throw new ServletException("에러");
    
    String fileNmae = file.getOriginalFilename().toLowerCase();
    
    //화이트 리스트 확장자 체크
    if(fileName != null){
      if(fileName.endsWith(".doc") || fileName.endsWith(".hwp")){
          /* 업로드 루틴*/
      }
    }
    ...
}

 

 

참고

http://cwe.mitre.org/data/definitions/434.html

 

CWE - CWE-434: Unrestricted Upload of File with Dangerous Type (4.8)

div.collapseblock { display:inline} CWE-434: Unrestricted Upload of File with Dangerous TypeWeakness ID: 434Abstraction: BaseStructure: Simple The software allows the attacker to upload or transfer files of dangerous types that can be automatically process

cwe.mitre.org

http://cwe.mitre.org/top25/

 

https://cwe.mitre.org/top25/

 

cwe.mitre.org

 

 

 

 

 

 

 

 

 

 

 

728x90

'DEV&OPS > Java' 카테고리의 다른 글

JAVA 보안 Cross-Site Request Forgery  (0) 2022.08.04
JAVA 보안 URL Redirection to Untrusted Site  (0) 2022.08.04
JAVA 보안 OS Command Injection  (0) 2022.08.03
JAVA 보안 Cross-site Scripting  (0) 2022.08.03
JAVA 보안 Resource Injection  (0) 2022.08.03