Re: SFTP and SCP

From: Simon Tatham (anakin_at_pobox.com)
Date: 02/09/05


Date: 09 Feb 2005 15:30:09 +0000 (GMT)

Richard E. Silverman <res@qoxp.net> wrote:
> Both scp and sftp use insecure protocols which derive their security from
> running on top of SSH. In what way do you see sftp as having "improved
> security?"

I can't speak for the previous poster, but there's at least one way
in which SFTP is a security improvement over SCP, which is to do
with wildcard expansion.

In SCP, wildcard expansion is done on the server, under a set of
matching rules chosen by the server. Different servers can totally
legitimately have different rules. As an extreme example from the
real world, if I send a request for '[ab]*.txt', a Unix machine will
interpret this as a request for any file whose name begins with a or
b and ends in '.txt', whereas a VMS box will interpret it as a
request for any file ending in '.txt', and will search a
subdirectory called 'ab' for those files. So VMS could reasonably
return a file called 'passwords.txt' in response to that wildcard.

This means that an SCP client is practically unable to validate the
returned file names against the wildcard it asked for. So if you sit
in your home directory and type `scp blofeld:harmless*.txt .', the
SCP server on blofeld could send back a file called `.bashrc', and
unless the SCP client had been told what wildcard convention to
expect the server to be using (or at least had some heuristics about
the range of sensible wildcard conventions that _might_ be in use),
it would quite probably accept the download and overwrite your
startup script.

SFTP is proof against any attacks of this type, since there are no
wildcards in the protocol at all: in order to perform a wildcard-
based download from a server, the client must retrieve the list of
files in the remote directory and filter them _itself_, so it is
never sent a filename it isn't expecting.

PuTTY's SCP client actually _disallows_ wildcard-based downloads
(defined as any download in which the server returns a filename that
isn't precisely equivalent to the filename we asked it for) to
protect against attacks of this type; if you do want to do a
wildcard-based download, you have to do it using the `-unsafe'
option. When in SFTP mode, however, PSCP permits wildcards without
worrying.

(There are plenty of reasons why this attack might not be
significant in a particular case, of course. If you're downloading a
file containing a _program_ you're about to run, for example, then a
malicious person in control of your SSH server machine could gain
control of your client machine much more easily.)

All of this is completely independent of the secure transport over
which both protocols travel, since it involves no third party.

-- 
Simon Tatham         "I'm going to pull his head off. Ear by ear."
<anakin@pobox.com>                          - a games teacher


Relevant Pages

  • Re: FTP partially blocked-- how to trace?
    ... something on the server to only allow secure FTP. ... I changed the protocol in WinSCP from SFTP to SCP and it ...
    (comp.security.firewalls)
  • Re: Confusing! ssh, ssh1, ssh2, etc.
    ... > SSH Comm Corp's ssh2 uses a completely different protocol than OpenSSH's ... "The solution is to install either the OpenSSH or SSH1 version of scp on ... the server under the name "scp1," somewhere in the sshd2's PATH." ... The "sftp" program uses the sftp protocol and expects an sftp server ...
    (comp.security.ssh)
  • Re: copy a bunch of rile, then delete from source
    ... Copy a number of files (using a wildcard, ... I want to delete the files from the source server. ... ssh keys, cronjob, and scp. ... is the return status of the previous command. ...
    (RedHat)
  • Re: copy a bunch of rile, then delete from source
    ... Copy a number of files (using a wildcard, ... I want to delete the files from the source server. ... ssh keys, cronjob, and scp. ... If the scp is successful, ...
    (RedHat)
  • Re: Advantage -vs- Disadvantage: SFTP -vs- SCP
    ... My primary concern is overall security of the server (even if that ... It depends what you mean by SFTP. ... if you mean crusty old FTP tarted up with some SSL ... just use sftp or scp natively from Terminal.app. ...
    (freebsd-questions)