DEV&OPS/Java
JAVA 보안 Process Control
ALEPH.GEM
2022. 8. 18. 17:53
Process Control 프로세스 제어
정의
신뢰되지 않는 소스나 환경에서 라이브러리를 적재하거나 명령을 실행하면 악의적인 코드가 실행될 수 있습니다.
방어 방법
라이브러리를 적재할 때 절대 경로를 사용합니다.
안전하지 않은 코드의 예
public void loadLibrary() throws Exception{
//외부 라이브러리 호출 시 절대 경로를 사용하지 않고 있습니다.
Runtime.getRuntime().loadLibrary("libraryName");
}
안전한 코드의 예
public void loadLibrary() throws Exception{
//외부 라이브러리 호출 시 절대 경로를 지정합니다.
Runtime.getRuntime().loadLibrary("/usr/lib/libraryName");
}
안전하지 않은 코드의 예
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String command = request.getParameter("command");
if (command.equals(UPLOAD_library_COMMAND)){
String libraryName = request.getParameter(library_NAME_PARAM);
String additionalOperation = request.getParameter(CONVERT_OPERATION_PARAM);
if(additionalOperation != null){
String [] arguments = new String [1];
arguments[0] = libraryName;
Runtime.getRuntime().exec(additionalOperation, arguments, null);
}
}
}
사용자 입력값을 라이브러리 실행시 인자값으로 사용하고 있습니다.
안전한 코드의 예
public DocService(){
additionalOperations = new Hashtable<String, String>();
additionalOperations.put("Doc", "/LIBRARY/DOC.LIB");
additionalOperations.put("UTF", "/LIBRARY/UTF.LIB");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String command = request.getParameter("command");
if (command.equals(UPLOAD_library_COMMAND)){
String libraryName = request.getParameter(library_NAME_PARAM);
String additionalOperation = request.getParameter(CONVERT_OPERATION_PARAM);
if(additionalOperation != null){
String [] arguments = new String [1];
arguments[0] = libraryName;
Runtime.getRuntime().exec(additionalOperations.get(additionalOperation), arguments, null);
}
}
}
해시테이블을 이용해 정해진 이름의 라이브러리만 절대 경로를 통해 로딩되도록 해야 합니다.
참고
http://cwe.mitre.org/data/definitions/114.html
CWE - CWE-114: Process Control (4.8)
div.collapseblock { display:inline} Weakness ID: 114Abstraction: ClassStructure: Simple Executing commands or loading libraries from an untrusted source or in an untrusted environment can cause an application to execute malicious commands (and payloads) on
cwe.mitre.org
728x90