4 ms·
A "ssh://..." URL can result in a "ssh" command line with a hostname that begins with a dash "-", which would cause the "ssh" command to instead (mis)treat it a
by jomar 9y ago
A "ssh://..." URL can result in a "ssh" command line with a hostname that begins with a dash "-", which would cause the "ssh" command to instead (mis)treat it as an option.
It's a shame, because the Git dispatching code ought to be able to invoke the ssh command via
ssh -p 22 -etc -etc -- <hostname>
to prevent interpreting options in <hostname>, thus defusing the in-band signalling causing this. But I suppose it can't depend on every ssh implementation understanding this "--" POSIX utility syntax guideline.
- numbsafari 9y agoHow is this any different than a SQL-injection attack? Seems to me like git shouldn't be using the shell in order to invoke ssh at all.
- jjnoakes 9y agoI haven't checked git, but even if git uses exec*() directly and skips the shell (which I suspect it does), the problem still exists. The issue isn't one of shell quoting, but one of ssh treating the argument list ["ssh", "-oProxyCommand=something", "remote-cmd"] not as ["ssh", hostname, command] but as ["ssh", option, hostname].
- deckar01 9y agoThere are C libraries for SSH, like libssh, that would avoid these type of vulnerabilities. https://www.libssh.org/ https://www.libssh.org/
- peff 9y agoOne downside of libraries like libssh is that they don't behave the same way as your regular ssh command. So thing you've configured like host aliases, proxy commands, etc, don't just work out of the box (and in some cases may not even be supported at all).
- deckar01 9y agoTrue. It sounds like there is room for an ORM-like sanitizer for SSH that is responsible for translating a C API to sanitized commands. I have no clue what to search to find if that already exists.
- virtualized 9y agoIt almost seems like ad-hoc text formats like command line argument syntaxes are difficult to use correctly.
- snakeanus 9y agolibgit2 depends on libssh2 actually.
- numbsafari 9y agoGot it. Seems to me the the use of "=" notation for CLI args would be rife with situations like this. Yikes... [also, still going through the code, but it looks like they are setting up for a call to exec*()]
- wahern 9y agoYes, which is why "--" is the standard way to avoid this stuff, and why people should generally avoid writing their own options processor and instead use getopt() or getopt_long(), which provide consistent, standard semantics.
- peff 9y agoExactly. It's an option injection attack. There's no shell involved.
- rschoon 9y agoIn this case, it's not the shell that's the problem, it's ssh's command line argument parsing that you need to be careful with.
- nobodyorother 9y agoNot just SSH's library parsing, but every SSH implementation's argument parsing.
- ekimekim 9y ago> it can't depend on every ssh implementation understanding this Indeed, from a comment[1] above: > We discussed that, but it wasn't clear that doing so was portable. It works for OpenSSH. It doesn't for PuTTY. We don't know what other implementations people might have as `ssh` on their systems. [1]https://news.ycombinator.com/item?id=14989578 https://news.ycombinator.com/item?id=14989578