tmxklab
[pwnable.kr] cmd2 본문
1. 문제 확인
참고로 패스워드는 이전 문제였던 cmd1의 flag값이다.
[ cmd2.c ]
#include <stdio.h>
#include <string.h>
int filter(char* cmd){
int r=0;
r += strstr(cmd, "=")!=0;
r += strstr(cmd, "PATH")!=0;
r += strstr(cmd, "export")!=0;
r += strstr(cmd, "/")!=0;
r += strstr(cmd, "`")!=0;
r += strstr(cmd, "flag")!=0;
return r;
}
extern char** environ;
void delete_env(){
char** p;
for(p=environ; *p; p++) memset(*p, 0, strlen(*p));
}
int main(int argc, char* argv[], char** envp){
delete_env();
putenv("PATH=/no_command_execution_until_you_become_a_hacker");
if(filter(argv[1])) return 0;
printf("%s\n", argv[1]);
system( argv[1] );
return 0;
}
2. 접근 방법
필터링 통과 ㄱㄱ
3. 문제 풀이
몇 개 명령어는 찾을 수 없다고 뜸 (ex. $cat)
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옵션을 이용ㄱㄱ
4. 몰랐던 개념
'War Game > pwnable.kr' 카테고리의 다른 글
[pwnable.kr] memcpy (0) | 2020.12.02 |
---|---|
[pwnable.kr] uaf (0) | 2020.12.02 |
[pwnable.kr] cmd1 (0) | 2020.12.02 |
[pwnable.kr] lotto (0) | 2020.12.02 |
[pwnable.kr] blackjack (0) | 2020.12.02 |
Comments