ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Secure Coding - Command Injection
    Java/Spring 2018. 9. 7. 14:39
    반응형

    Command Injection


    Cmdi - .sh나 .bash 등 배치파일이나 커맨드 입력으로 injection 수행


    Tools - Encoder/Hash -> programs=calc.exe&shutdown -t -s 36000 붙이고 URL Encoding


    programs%3Dcalc.exe%26shutdown -t -s 36000를 붙여놓고 요청을 수행한다.


    WhiteList기법을 이용해서 Cmdi를 방어한다.


    Runtime.getRuntime().exec("cmd.exe /c " + command); 로 OS에 명령을 실행한다.


    String command = request.getParameter("programs");


    WhiteList 기법 -> Map을 사용한다.


    Map<String, String> whiteList = new HashMap<>();

    whiteList.put("1", "calc.exe");

    whiteList.put("2", "notepad.exe");


    등록 번호 외에는 동작이 되면 안된다.


    command = whiteList.get(command);


    try {

    if ( command != null ) {

    Runtime.getRuntime().exec("cmd.exe /c " + command);

    }

    } catch (IOException e) {

    throw new RuntimeException(e.getMessage(), e);

    }

    ModelAndView view = new ModelAndView("attack/sqlInjection/sqlInjection");

    return view;

    반응형

    'Java > Spring' 카테고리의 다른 글

    @Qualifier("")  (0) 2018.09.08
    Secure Coding - 패스워드 정책  (0) 2018.09.07
    Secure Coding - SQL injection  (0) 2018.09.07
    Secure Coding - Paros  (0) 2018.09.07
    Secure Coding - 보안 취약점 관리 사이트  (0) 2018.09.07

    댓글

Designed by Tistory.