Recent Posts
Recent Comments
Link
06-30 12:53
Today
Total
관리 메뉴

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

JAVA 보안 OS Command Injection 본문

DEV&OPS/Java

JAVA 보안 OS Command Injection

ALEPH.GEM 2022. 8. 3. 18:02

OS Command Injection

사용자 입력값에 운영체제 명령어를 넣어서 실행하는 경우 시스템을 직접 공격할 수 있습니다.

그래서 외부 입력 값을 그대로 시스템 내부 명령어로 사용하지 않아야 합니다.

만약 명령을 실행해야 하는 경우 미리 명령어 생성에 필요한 값들을 지정해놓고 외부 입력을 참고하여 사용합니다. 

 

아래 예제는 cmd.exe 를 사용하여 rmanDB.bat 배치 명령을 실행하여 외부 입력값인 dir_type을 인자 로 사용하는 경우 입니다.

...
String version = props.getProperty("dir_type");
String cmd = new String("cmd.exe /K \"rmanDB.bat \"");
Runtime.getRuntime().exec(cmd + " c:\\prog_cmd\\" + version);
...

아래 처럼 미리 정의된 인자값의 배열을 만들어 놓고 외부 입력에 따라 적절한 인자값을 선택해서 부적절한 명령어가 실행되지 않도록 막습니다.

String version[] ={"1.0", "1.1"};
int VersionSelection = Integer.parseInt(props.getProperty("version"));
String cmd = new String("cmd.exe /K \"rmanDB.bat \"");
String vs = "";
if(versionSelection == 0){
    vs = version[0];
}else{
    vs = version[1];
}
Runtime.getRuntime().exec(cmd + " c:\\prog_cmd\\" + vs);

 

 

참고

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

 

CWE - CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (4.8)

div.collapseblock { display:inline} CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')Weakness ID: 78Abstraction: BaseStructure: Simple The software constructs all or part of an OS command using externally-in

cwe.mitre.org

https://www.owasp.org/index.php/ 

 

OWASP Foundation, the Open Source Foundation for Application Security | OWASP Foundation

OWASP Foundation, the Open Source Foundation for Application Security on the main website for The OWASP Foundation. OWASP is a nonprofit foundation that works to improve the security of software.

owasp.org

 

 

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

 

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

 

cwe.mitre.org

 

 

 

 

 

 

728x90