WildCards?
Wildcard는 OS에서 파일에 대해 다중처리를 위해 사용되는 기호입니다. 보편적으로 많이 사용하는건 * ? 등이 있고 덕분에 번거로운 작업을 한번에 처리할 수 있게 되죠. 뭐 대충 이런 경우이죠.
|
|
정리해보면 이정도 문자들이 있습니다.
|
|
와일드 카드를 활용하면 완벽하게 기억이 나지 않는 path, command에 대해서도
|
|
|
|
http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm
Evasion 1 - Wildcards
Wildcard를 이용하면 문자를 적게 사용하면서 명령어를 쓸 수 있습니다. 이것을 이용해서 문자열 기반의 필터링 규칙을 우회할 수 있게 됩니다.
원본 구문
|
|
Evasion
|
|
모두 passwd 파일을 불러올 수 있습니다.
Output
|
|
Evasion 2 - Quotation marks and backslash
quot(" ‘) 문자와 backslash는 문자열을 표기합니다. 커맨드라인에서도 동일하게 문자열을 표기하는데, quot, slash가 있던 없던 명령으로 보기 때문에 문자열을 자르는 용도로도 사용이 가능합니다. 아래 명령을 보면..
|
|
모두 사용자 계정이 확인됩니다. 위에 wildcard와 조합을 해보면.. 이런 패턴이 가능하겠지요.
|
|
Evasion 3 - $IFS(입력필드 구분자)
공백 사용 불가능한 상황에선 내부변수나 특수문자 ,< 등을 이용해서 우회가 가능합니다. 여기서 $IFS는 입력필드 구분자로 기본적으로 따로 쓰이면 공백과 같은 의미를 지니며 특정 값에 대해 공백으로 치환해줄 수 있습니다.
|
|
언어에서 사용하는 부분도 똑같이 적용될까?
모든 함수가 공통적이진 않겠지만, 기본적으로 os 관련 함수는 동일하게 wildcard 처리를 진행합니다.
Ruby exec
|
|
Python os.system
|
|
추가적인 포인트?
쉘에선 wildcard와 같이 여러가지 사용할 수 있는 트릭들이 존재합니다. 잘 활용해보면 또다른 패턴을 만들 수 있을 것 같네요 :)
$1, $2, $3, … are the positional parameters. “$@” is an array-like construct of all positional parameters, {$1, $2, $3 …}. “$*” is the IFS expansion of all positional parameters, $1 $2 $3 …. $# is the number of positional parameters. $- current options set for the shell. $$ pid of the current shell (not subshell). $_ most recent parameter (or the abs path of the command to start the current shell immediately after startup). $IFS is the (input) field separator. $? is the most recent foreground pipeline exit status. $! is the PID of the most recent background command. $0 is the name of the shell or shell script. (https://stackoverflow.com/questions/5163144/what-are-the-special-dollar-sign-shell-variables )