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
https://cwe.mitre.org/top25/
cwe.mitre.org
728x90