SCP – Familiar, Simple, Insecure, and Slow
gravitational.com
gravitational.com
This doesn't even seem like a valid security concern. But I'm open to hearing about some ways that SCP would be vulnerable in ways that SFTP would not. I am by no means an expert in this subject.
Presumably by now scp is sufficiently tested not to have this bug. But this is precisely a defense against an evil server sending bad bytes.
My favorite:
A Standard for the Transmission of IP Datagrams on Avian Carriers
https://tools.ietf.org/html/rfc1149
Check the dates.
LOL
> Intrusion detection systems (IDSs) have a harder problem. Because of their known propensity for false negatives and false positives, IDSs MUST apply a probabilistic correction factor when evaluating the evil bit. If the evil bit is set, a suitable random number generator [RFC1750] must be consulted to determine if the attempt should be logged. Similarly, if the bit is off, another random number generator must be consulted to determine if it should be logged despite the setting.
i am ashamed (or maybe not) to say that i have engaged in this form of debugging during past moments of desperation...
We safely connect to evil machines all day long. That's what web browser sandboxes and BitTorrent are for.
We download files from evil machines and use checksums to verify the files.
The problem is that remote hosts, even ones you think you control, should be assumed potentially evil (compromised).
There's zero reason for a file transfer utility to support running arbitrary commands on the local machine at the remote host's command. That capability shouldn't exist in the protocol, full stop.
But since it does, if you're going to use scp regardless of what we know about it, there's clearly a broad spectrum of risk separating a random VPS in who knows what cloud running who knows what bits vs. the NAS machine in your closet that's only on a wired LAN behind a firewall running nothing that talks to the outside. Probably not the best choice to use scp to copy files to/from the former.
The amount of time I've saved when I've forgotten that I've done this and it just runs faster is well into the tens of hours. The amount of time I've lost when I forgot and rsync doesn't exist remotely is about 10 seconds total - enough time to read the error message -> `type -a scp` -> "oh yeah" -> use /usr/bin/scp instead.
Highly highly highly recommended.
place rogue SCP in /some/rogue/scp
export PATH=/some/rogue:$PATH
On Linux one could use firejail, qubes, selinux to contain software you are already running to at least some degree.
I often need to transfer very large binary files. When stuck with standard Linux tools, the fastest process is first transfer via scp. If the scp gets interrupted, resume it using rsync with the —-append-verify option.
You aren't necessarily wrong, but there's a whole world of distinction you're glossing over. Netcat is part of a set of tools you can use to construct a somewhat equivalent tool to scp without encryption, but nc by itself without tar and gzip (or whatever) match only the simplest possibly use case of scp, which is copying one file, without compression, and ignoring all permissions and ownership info.
This is also ignoring that you might not even have an open port on one side that the other can reach to have netcat listen on.
mostly either:
rsync -av src dest
or: rsync -av --remove-source-files src destTar may well be better if you know you need all the files and don't need the block checks per file to detect change and minimise data sent.
Rsync can hose the file buffer cache and slow a server down. If you want speed mbuffer is good but lacks channel security too (ZFS send over mbuffer is awesomely fast)
Err, what risks? If you run a server? Sure, but as a replacement for scp, where it's assumed you have an account on the remote system, an rsync server is not the equivalent solution, running rsync across an ssh connection is.
> Rsync over SSH is less risky but not risk free to either side. What is sent and what is asked for do not have to align well)
Glossing over that no system is "risk free", can you explain in a bit more detail here, or reference what you wrote up or some other thing? That's the kind of thing I would really want to know about, and an unsubstantiated throw-away aside does not do justice to the problem if accurate.
Did you event submit these finding as a bug? I would be interested in tracking this if it was accepted. It looks like this note from 3.1.2's release[1] is it, but I'm not sure:
File-list validation in 3.1.2 December 21st, 2015
If you're using a version of rsync older than 3.1.2 as a client and receiving files from an rsync server that you might not fully trust, this version adds extra checking to the file list to prevent the sender from tweaking the paths and/or the transfer requests in a way that could cause a file to be received outside the transfer destination.
The proprietary ssh.com implementation of SSH apparently has one called "scp2", but I don't see any open source version.
Well, except for this, but it's tagged "[MAINTAINER WANTED]" and written in JavaScript:
Seems like a lot of effort when, In Theory, this would be a pretty straightforward wrapper to build on top of libssh, which can load OpenSSH's configuration files, or perhaps on top of OpenSSH's ssh/sftp binaries directly. But I'm too lazy to write one myself, so I was hoping someone already had :)
I think what is lacking is a precise split between file transfer and remote command execution.
If the split were well defined, we could simply and securely split out file transfer as a "thing".
it would allow:
- write-only no-account-required file uploads
- read-only no-account-required file downloads
- an account-required incoming dropbox
- an account-required file store
- full blown remote filesystems (filestore + file protocol goodies)
and a number of other services that involve files and NOT command execution, environment variables, shells, a login or even a user account.
Guess I maybe learned that wrong.