기본 콘텐츠로 건너뛰기

라벨이 CTF인 게시물 표시

Insecure-programming-stack2

Insecure-programming-stack2 Insecure Programming by example Stack 2 # include <stdio.h> int main ( ) { int cookie ; char buf [ 80 ] ; printf ( "buf: %08x cookie: %08x\n" , & buf , & cookie ) ; gets ( buf ) ; if ( cookie == 0x01020305 ) printf ( "you win!\n" ) ; } 이번 문제의 경우 목표 cookie 값이 0x01020305로 ASCII 코드로 확인해보면 문자로 입력이 불가한 값임을 알 수 있다. ASCII Table Tables For convenience, below are more compact tables in hex and decimal. 2 3 4 5 6 7 30 40 50 60 70 80 90 100 110 120 ------------- --------------------------------- 0: 0 @ P ` p 0: ( 2 < F P Z d n x 1: ! 1 A Q a q 1: ) 3 = G Q [ e o y 2: " 2 B R b r 2: * 4 > H R \ f p z 3: # 3 C S c s 3: ! + 5 ? I S ] g q { 4: $ 4 D T d t 4: " , 6 @ J T ^ h r | 5: % 5 E U e u 5: #

Insecure-programming-stack1

Insecure-programming-stack1 Insecure Programming by example Stack 1 # include <stdio.h> int main ( ) { int cookie ; char buf [ 80 ] ; printf ( "buf: %08x cookie: %08x\n" , & buf , & cookie ) ; gets ( buf ) ; if ( cookie == 0x41424344 ) printf ( "you win!\n" ) ; } cookie 변수 값이 0x41424344인 경우 you win! 을 출력하는 프로그램 소스 코드이다. 하지만 정상적인 프로그램 사용을 통해서 cookie 값에 값을 삽입할 수 있는 방법은 존재하지 않으므로 buf[80] 배열에 값을 넘치게 삽입하여 cookie 변수 값을 조작해야 한다. $ echo `python -c "print 'a'*80+'DCBA'" ` | ./stack1.exe buf: 0028fe6c cookie: 0028febc you win ! 위와 같이 python을 이용하여 임의의 문자 80개를 삽입한 후 cookie 변수 값에 넣을 값 지정하면 쉽게 해결할 수 있다. 주의할 점은 리틀엔디언 방식으로 문자를 역순으로 넣어주어야한다는 점이다. 추가적으로 심볼 파일을 생성하거나 gdb를 통해서 어셈블리어 구성을 살펴보자. 간단한 코드로 특이 사항은 없으므로 간단히 눈으로 읽고 지나쳐도 좋다. gcc -S -masm = intel -O3 -o stack1.s ./stack1.c Non-debugging symbols: 0x00000000 __deregister_frame_info 0x00000000 __register_frame_info 0x0040

Bandit11

Bandit11 Bandit Level 11 이번 level은 ROT13(13회 순환)된 대소문자를 원래대로 돌려 패스워드 값을 구하는 문제이다. tr 명령어를 사용하면 이를 쉽게 구할 수 있다. ascii table을 참고하면 13번째 문자는 n 이라는 것을 알 수 있다. 이를 참고하여 tr 명령어 구문을 구성해보자. ASCII Table Tables For convenience, below are more compact tables in hex and decimal. 2 3 4 5 6 7 30 40 50 60 70 80 90 100 110 120 ------------- --------------------------------- 0: 0 @ P ` p 0: ( 2 < F P Z d n x 1: ! 1 A Q a q 1: ) 3 = G Q [ e o y 2: " 2 B R b r 2: * 4 > H R \ f p z 3: # 3 C S c s 3: ! + 5 ? I S ] g q { 4: $ 4 D T d t 4: " , 6 @ J T ^ h r | 5: % 5 E U e u 5: # - 7 A K U _ i s } 6: & 6 F V f v 6: $ . 8 B L V ` j t ~ 7: ' 7 G W g w 7: % / 9 C M W a k u DEL 8: ( 8 H X h x 8: & 0 : D N X b l v 9: ) 9

Bandit10

Bandit10 Bandit Level 10 이번 level의 패스워드는 base64로 인코딩되어 있다. 간단히 base64 명령어를 이용하여 디코딩 후 패스워드를 얻을 수 있다. bandit10@bandit:~$ ls -al total 24 drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 29 root root 4096 Nov 13 15:57 .. -rw-r--r-- 1 root root 220 Sep 1 2015 .bash_logout -rw-r--r-- 1 root root 3771 Sep 1 2015 .bashrc -rw-r--r-- 1 root root 655 Jun 24 2016 .profile -rw-r----- 1 bandit11 bandit10 69 Nov 13 15:58 data.txt bandit10@bandit:~$ base64 -d data.txt The password is IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR

Bandit9

Bandit9 Bandit Level 9 data.txt 파일에서 = 으로 시작하는 문자열 중 이번 level의 패스워드가 있다. 우선 문자열 목록을 얻기 위해서는 strings 명령어를 사용해야한다. 그렇게 얻은 목록에서 grep 명령어를 이용하여 = 이 포함된 문자열을 추출해내면 패스워드를 확인할 수 있다. bandit9@bandit:~$ ls -al total 40 drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 29 root root 4096 Nov 13 15:57 .. -rw-r--r-- 1 root root 220 Sep 1 2015 .bash_logout -rw-r--r-- 1 root root 3771 Sep 1 2015 .bashrc -rw-r--r-- 1 root root 655 Jun 24 2016 .profile -rw-r----- 1 bandit10 bandit9 19379 Nov 13 15:58 data.txt bandit9@bandit:~$ strings data.txt | grep = == == == == == theOkM L = 8@ = hrV` == == == == == password == == == == == is H ) = QU > ] ".x = { = u/,i_ { = jh = GUl e = y: 4H5 = ) == == == == == truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk = /wW ~BX =

Bandit8

Bandit8 Bandit Level 8 data.txt 에서 중복되지 않는 문자열이 이번 level의 패스워드이다. 중복 제거를 위해서 흔히 sort 와 uniq 를 활용한다. uniq [-c/d/D/u][파일 명] c: 중복 수 출력 d: 중복 라인 중 한 열만 출력 D: 중복되는 모든 열 출력 u: 중복 열이 없는 열만 출력 bandit8@bandit:~$ ls -al total 56 drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 29 root root 4096 Nov 13 15:57 .. -rw-r--r-- 1 root root 220 Sep 1 2015 .bash_logout -rw-r--r-- 1 root root 3771 Sep 1 2015 .bashrc -rw-r--r-- 1 root root 655 Jun 24 2016 .profile -rw-r----- 1 bandit9 bandit8 33033 Nov 13 15:58 data.txt bandit8@bandit:~$ cat data.txt | sort | uniq -u UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR

Bandit7

Bandit7 Bandit Level 7 패스워드를 찾을 수 있는 단서 하나를 제공하고 있다. The password for the next level is stored in the file data.txt next to the word millionth grep 명령어를 이용하여 data.txt 파일에 저장된 millionth 문자열 위치를 찾고, 그 뒤에 삽입된 패스워드 를 확인한다. bandit7@bandit:~$ ls -al total 4108 drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 29 root root 4096 Nov 13 15:57 .. -rw-r--r-- 1 root root 220 Sep 1 2015 .bash_logout -rw-r--r-- 1 root root 3771 Sep 1 2015 .bashrc -rw-r--r-- 1 root root 655 Jun 24 2016 .profile -rw-r----- 1 bandit8 bandit7 4184396 Nov 13 15:58 data.txt bandit7@bandit:~$ grep -rn millionth ./data.txt 34210:millionth cvX2JJa4CFALtqS87jk27qwqGhBM9plV

Bandit6

Bandit6 Bandit Level 6 패스워드 파일을 찾을 수 있는 세 가지 단서를 제공하고 있다. owned by user bandit7 owned by group bandit6 33 bytes in size 이 정보를 조합하여 find 명령어를 구성하여 문제를 해결할 수 있다. -user [유저 명] -group [그룹 명] 2> /dev/null (/dev/null로 표준 에러 리다이렉트) bandit6@bandit:~$ find / -size 33c -user bandit7 -group bandit6 2 > /dev/null /var/lib/dpkg/info/bandit7.password bandit6@bandit:~$ cat /var/lib/dpkg/info/bandit7.password HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs

Bandit5

Bandit5 Bandit Level 5 패스워드 파일을 찾을 수 있는 세 가지 단서를 제공하고 있다. human-readable 1033 bytes in size not executable 이 정보를 조합하여 find 명령어를 구성하여 문제를 해결할 수 있다. -size [+파일크기/-파일크기/파일크기][b/c/k/w] b: 블록단위 512kb, c: byte, k: kbyte, w: 2byte 워드 (default: b) -perm [-][권한] ([-]: 최소한) -exec [command] {} ; bandit5@bandit:~/inhere$ ls -al total 88 drwxr-x--- 22 root bandit5 4096 Nov 13 15:58 . drwxr-xr-x 3 root root 4096 Nov 13 15:58 .. drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere00 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere01 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere02 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere03 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere04 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere05 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere06 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere07 drwxr-x--- 2 root bandit5 4096 Nov 13 15:58 maybehere08 drwxr-x--- 2 root ba

Bandit4

Bandit4 Bandit Level 4 inhere 디렉터리 안에 파일들의 내용을 확인해보면 -file07 만이 내용을 제대로 출력하고 있다. 해당 파일이 이번 level의 해답이다. bandit4@bandit:~/inhere$ ls -al total 48 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file00 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file01 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file02 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file03 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file04 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file05 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file06 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file07 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file08 -rw-r----- 1 bandit5 bandit4 33 Nov 13 15:58 -file09 drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 3 root root 4096 Nov 13 15:58 .. bandit4@bandit:~/inhere$ cat ./ "-file07" koReBOKuIDDepwhWk7jZC0RTdopnAYKh

Bandit3

Bandit3 Bandit Level 3 inhere 폴더 안에 숨김 파일이 존재한다. ls 명령어를 -a 옵션 없이 사용하면 숨김 파일을 출력하지 않는다. 흔히 디렉터리 목록 출력을 위해 사용하는 ls -al 을 사용하여 숨김 파일 확인 후 cat 으로 파일 내용을 확인하자. bandit3@bandit:~$ ls -al total 24 drwxr-xr-x 3 root root 4096 Nov 13 15:58 . drwxr-xr-x 29 root root 4096 Nov 13 15:57 .. -rw-r--r-- 1 root root 220 Sep 1 2015 .bash_logout -rw-r--r-- 1 root root 3771 Sep 1 2015 .bashrc -rw-r--r-- 1 root root 655 Jun 24 2016 .profile drwxr-xr-x 2 root root 4096 Nov 13 15:58 inhere bandit3@bandit:~$ cd inhere/ bandit3@bandit:~/inhere$ ls -al total 12 drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 3 root root 4096 Nov 13 15:58 .. -rw-r----- 1 bandit4 bandit3 33 Nov 13 15:58 .hidden bandit3@bandit:~/inhere$ cat ./.hidden pIwrPrtPN36QITSp3EQaw936yaFoFgAB

Bandit2

Bandit2 Bandit Level 2 파일 명에 공백이 삽입되어 있을 경우 전체 파일 명을 싱글 쿼터 혹은 더블 쿼터로 묶어주거나 공백 앞에 역슬러시를 입력하여 처리한다. bandit2@bandit:~$ ls -al total 24 drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 29 root root 4096 Nov 13 15:57 .. -rw-r--r-- 1 root root 220 Sep 1 2015 .bash_logout -rw-r--r-- 1 root root 3771 Sep 1 2015 .bashrc -rw-r--r-- 1 root root 655 Jun 24 2016 .profile -rw-r----- 1 bandit3 bandit2 33 Nov 13 15:58 spaces in this filename bandit2@bandit:~$ cat 'spaces in this filename' UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK bandit2@bandit:~$ cat "spaces in this filename" UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK bandit2@bandit:~$ cat ./spaces\ in\ this\ filename UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK

Bandit1

Bandit1 Bandit Level 1 level 0와 유사하게 파일 명이 - 라서 경로 없이 파일 명만 사용하면 내용이 출력되지 않으므로 절대 경로 혹은 상대 경로를 명시하여 cat 명령어로 읽으면 내용을 확인할 수 있다. bandit1@bandit:~$ ls -al total 24 -rw-r----- 1 bandit2 bandit1 33 Nov 13 15:58 - drwxr-xr-x 2 root root 4096 Nov 13 15:58 . drwxr-xr-x 29 root root 4096 Nov 13 15:57 .. -rw-r--r-- 1 root root 220 Sep 1 2015 .bash_logout -rw-r--r-- 1 root root 3771 Sep 1 2015 .bashrc -rw-r--r-- 1 root root 655 Jun 24 2016 .profile bandit1@bandit:~$ cat ./- CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9

Bandit0

Bandit0 Bandit Level 0 OverTheWire - bandit 페이지에서 Level 0을 선택하여 제공된 SSH 서버에 접속하면 readme 파일을 확인할 수 있다. 간단히 출력하여 내용을 확인해보면 bandit1의 접속 패스워드 정보를 확인할 수 있다. bandit0@bandit:~$ ls readme bandit0@bandit:~$ cat readme boJ9jbbUNNfktd78OOpsqOltutMc3MY1

SHA-2017-Teaser-Round_Website Attack

SHA-2017 Teaser-Round Network Website Attack write up 문제 풀이를 위한 pcap 파일이 주어진다. PCAP 은 Packet Capture 의미로 네트워크 트래픽을 캡쳐하기 위한 API 로 구성이 되어 있다. 윈도우로 포팅되어 있는 것은 WinPcap 이며, 유닉스 환경에서는 libpcap 이다. libpcap 과 winpcap 라이브러리를 이용하여 캡쳐된 패킷을 파일로 저장하거나, 저장된 패킷을 읽고 또는 다른 프로그램에서 라이브러리를 이용해 패킷파일을 분석/편집 등을 할 수 있다. 이를 이용한 대표적인 패킷 캡쳐 프로그램이 tcpdump 나 wireshark 이다. 출처 : 패킷인사이드 와이어 샤크를 이용하여 pcap을 열어보면 TCP, IPA 패킷이 저장되어 있는 것을 확인할 수 있다. IPA 패킷 내용을 확인해보면 HTTP 패킷으로 보이므로 분석의 용이성을 위해서 HTTP 패킷으로 변환하여 분석하도록 한다. Wireshark -> Analyze -> Enabled Protocol -> GSM over IP 체크 해제 참고 URL Data which has been sent over TCP\IP has been recognized by wireshark as “IPA” Protocol [Malformed Packet: GSM over IP] 패킷의 흐름을 살펴보면 다음과 같다. Created with Raphaël 2.1.2 237 237 208 208 GET /?action=search&word=&sort=stock Encrypt/Encoding 302 Found GET /?action=display&what=[encrypt string] 여기서 word 의 값만 변경되는 데 총 3개의 word 를 요청한다. kl Trad AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA