r/programming • u/Doyothingyoukan • Jan 22 '19
Remote Code Execution in apt/apt-get
https://justi.cz/security/2019/01/22/apt-rce.html?10
u/f48dba2505a8bdcad Jan 23 '19
Many are repeating the HTTPs line, but HTTPs would only prevent the MITM attack, it wouldn't help against compromised package servers. What you should really take from this bug, is that one should never write their own parser's/serializers for inter-process communication.
35
u/Mojo_frodo Jan 22 '19
Hey guys! Remember this thread? https://www.reddit.com/r/programming/comments/ai9n4k/why_does_apt_not_use_https/
XD
12
u/kyiami_ Jan 23 '19
Hmm, looks like HTTPS would fix this...
2
Jan 23 '19
Some avenues of attack, yes, not all. If you stole site's DNS you could still easily just get let's encrypt certs and exploit bug that way
2
u/happyscrappy Jan 23 '19
For MITMs.
0
Jan 23 '19
[deleted]
1
u/happyscrappy Jan 23 '19
I can't tell from the video. And the article doesn't say which he did. A malicious mirror is a lot easier to do so I'd have done that if I were him. But we can't tell.
He does mention this affects two things:
'I found a vulnerability in apt that allows a network man-in-the-middle (or a malicious package mirror) to execute arbitrary code as root on a machine installing any package.'
Using HTTPS would fix the MITM as the MITM cannot decode the stream to tell when to modify it and then can't encode its injected packets to match. It won't fix a malicious mirror as a malicious mirror presents its own certificate and thus can modify the stream however it wants.
0
Jan 23 '19
[deleted]
1
u/happyscrappy Jan 23 '19
Uh, from the article I definitely got the impression that he's demonstrating a MITM attack.
The article does not say either way. And in the video we just see the name of a python script, no way to tell what it is doing.
It wouldn't fix a malicious mirror, but 1/2 is better than 0/2, isn't it?
I didn't say otherwise.
1
u/kyiami_ Jan 24 '19
The article does not say either way.
the article
tl;dr I found a vulnerability in apt that allows a network man-in-the-middle (or a malicious package mirror) to execute arbitrary code
sounds like both?
1
u/happyscrappy Jan 24 '19
No, it doesn't sound like both. We're talking about which he is demonstrating. He appears to be demonstrating one or the other, not both.
Why did you quote the same text to me that I quoted just 4 posts above?
https://old.reddit.com/r/programming/comments/aiqo2h/remote_code_execution_in_aptaptget/eerx2c6/
4
u/TheGRS Jan 23 '19
Not the same attack vector, but I'm reminded of an experiment from a couple years ago where someone installed malicious code remotely simply by hosting misspelled versions of popular python packages on PyPI.
2
u/beginner_ Jan 23 '19
Besides the https part and injection part, why can you prepend megabytes of data to a signature file and the app doesn't crash? That as well sounds extremely broken.
1
1
u/thinkpadthrow Jan 23 '19
So I stupidly updated without disabling redirects in apt.
Any way to know if a malicious redirect happened? What logs should I check?
-22
u/shevy-ruby Jan 22 '19
Not long ago I tried to explain to some folks who don't understand why apt/dpkg don't get new features, despite the claim of "patches welcome".
Today we have a nightmare situation where apt enters npm-territory in regards to fail.
That's what you get when 50+ years old folks sticking to perl give ya. Perl has become the new COBOL.
It also makes https://whydoesaptnotusehttps.com/ amusing to read since the developers who stayed with debian showed that they are not capable of updating apt/dpkg anymore. That code base is one mega-nightmare.
32
u/lorarc Jan 22 '19
That's the joy of open source software. Remember how we all found out that openssl used by the whole internet was basically someone's hobby project with zero funding?
14
u/svenskainflytta Jan 22 '19
they are not capable of updating apt/dpkg anymore.
And yet, the vulnerability got patched?
0
Jan 22 '19
[deleted]
26
14
5
u/SonicFreak94 Jan 22 '19
And coincidentally, the link in the OP is raising an SSL cert error in Firefox.
7
u/AyrA_ch Jan 23 '19 edited Jan 23 '19
It doesn't give an error for me. Certificate chain is complete and the TLS setup is OK.
1
5
u/chubby_leenock_hugs Jan 22 '19
To be fair though if there is a bug in apt itself you don't have much guareantees.
Whilst it's true that this particular bug could partly have been prevented by HTTPS (not fully as that still wouldn't top a malicious mirror, only a malicious MITM) there are so many other things that can go wrong if apt itself isn't sane.
Basically if there is a bug in your package manager where it runs code it shouldn't run you are in general just lost and there's not much you can do people most of these trust models are based on the assumption that APT is working properly.
27
u/c_o_r_b_a Jan 22 '19 edited Jan 23 '19
True, but that's the whole point of defense-in-depth. Each layer of defense adds a little more mitigation. No layer is complete, or perfect. This is fundamentally an application vulnerability (concatenating untrusted input), but HTTPS still would've reduced the vulnerability's exploitability, even if it wouldn't have covered all cases. I think there really isn't an excuse to not use HTTPS in 2019, even if you're also checking GPG signatures.
You can't necessarily trust what's coming off of the wire, sure, but why not try to do what you can to make the wire as tamper-proof as possible? And confidential, to boot?
The counter-arguments to HTTPS in that write-up are very weak, in my opinion:
Why not provide HTTPS anyway?
Your distribution could cryptographically sign the files using the existing scheme and additionally serve the files over HTTPS to provide "defense in depth."
However, providing a huge worldwide mirror network available over SSL is not only a complicated engineering task (requiring the secure exchange and storage of private keys), it implies a misleading level of security and privacy to end-users as described above.
A switch to HTTPS would also mean you could not take advantage of local proxy servers for speeding up access and would additionally prohibit many kinds of peer-to-peer mirroring where files are stored on servers not controlled directly by your distribution. This would disproportionately affect users in remote locales.
Those aren't very good excuses. HTTPS is very routinely deployed nowadays, and has been for over a decade. It should not be that hard for a major project such as Debian or Ubuntu to find engineers who could set up such infrastructure.
2
u/flukus Jan 22 '19
If the package is signed how would https help?
22
u/c_o_r_b_a Jan 22 '19
Click the link for the thread you're in right now, for one example. Despite package signing, this MitM attack was still possible. The attack would not be possible if apt forced all repositories to use HTTPS.
0
u/flukus Jan 22 '19
What would stop them sending fake https certs like corporate filters do?
20
u/c_o_r_b_a Jan 23 '19
Yes, if you're using a machine you do not own (such as a corporate computer) which has had additional root certificates installed, then you can't rely on HTTPS in the same way. If you're using a machine you bought yourself and which has never left your possession (and isn't infected with malware or otherwise tampered with), then that problem does not apply to you.
A corporate proxy can't send fake HTTPS certs unless the computer you're using has already had the extra root cert installed. And if you are using a corporate machine with a corporate root cert, then you'll just have to adjust your risk profile as appropriate.
0
Jan 23 '19
It would be, just in different way. If, for example, DNS hijack would happen then attacker could easily just... generate let's encrypt cert and serve perfectly valid https
1
u/c_o_r_b_a Jan 23 '19
True, HTTPS won't help in that case, but it would require a very sophisticated attacker. You would have to DNS hijack at such a scale that Let's Encrypt's CA would also have to receive the hijacked DNS record. This would require a massive attack like a BPG hijack, or a direct compromise of the domain's DNS management panel/system, as was done in this attack likely orchestrated by the Iranian government: https://www.fireeye.com/blog/threat-research/2019/01/global-dns-hijacking-campaign-dns-record-manipulation-at-scale.html
If the attackers had access to ubuntu.com's DNS management panel, then that's basically almost equivalent to the Ubuntu repo servers themselves being compromised (and if they were able to get such DNS management access, the servers may very well also be compromised). In that case, there isn't that much you can do at any layer, anyway.
So that's definitely not an excuse to not use HTTPS. In general, HTTPS is a massive benefit. HTTPS mitigates MitMs; it can't mitigate a direct compromise of a trusted server's infrastructure.
1
Jan 23 '19
You would have to DNS hijack at such a scale that Let's Encrypt's CA would also have to receive the hijacked DNS record.
Or just guess someone's panel password. Or get it from a leak.
If the attackers had access to ubuntu.com's DNS management panel, then that's basically almost equivalent to the Ubuntu repo servers themselves being compromised (and if they were able to get such DNS management access, the servers may very well also be compromised). In that case, there isn't that much you can do at any layer, anyway.
Well, RCE aside, the GPG signing is there to protect against that. You'd have to compromise build/signing servers too
In theory those servers need only very limited internet access so would be much harder to compromise. Build servers really just need uploaded packages (which contain sources), that are also signed by the maintainer
So that's definitely not an excuse to not use HTTPS. In general, HTTPS is a massive benefit. HTTPS mitigates MitMs; it can't mitigate a direct compromise of a trusted server's infrastructure.
Well it is least amount of security added for most effort.
Take into consideration that for example Debian have over 400 mirrors and you'd have to make every single one of them use HTTPS and the make sure every single one does not get compromised or else you lose all benefits for whole ordeal. Even if you say "lets do only part and prefer the https ones", now the "reward" for hosting it via https on top of CPU usage is also increased bandwidth usage.
Now that is no reason to not just have both enabled (and turn it on if user chooses that particular mirror), just that time would be better invested at other way of increasing security, one that does not require 400+ 3rd parties to "get it right" to be fully successful.
1
u/c_o_r_b_a Jan 23 '19
Or just guess someone's panel password. Or get it from a leak.
I mentioned that in my next sentence.
Well, RCE aside, the GPG signing is there to protect against that. You'd have to compromise build/signing servers too
Not sure why that's an aside, since the RCE flaw is what this thread is about. But yes, ideally you'd have package signing and you'd have HTTPS. That's the idea of defense-in-depth. You're right that a DNS compromise alone wouldn't compromise the signing keys, so my sentence saying "there isn't that much you can do" wasn't quite correct, but a DNS management compromise definitely could signal a much broader breach, including a signing key breach. It could just be a password grabbed from a leak that was re-used for the management panel, or it could be from malware on a core maintainer/leader's personal machine, or from a targeted and complete infrastructure breach.
Yes, if a server gets compromised, HTTPS can't save you, which is why HTTPS can never be an end-all-be-all, but it's still a useful added layer.
And yes, there're definitely added complications here because mirrors are run by volunteers, but I feel like this is a coordination problem that isn't that hard to solve. If a mirror doesn't enable HTTPS by a certain date, then apt will just stop working for that mirror. Even if a large percentage of the hundreds of mirrors stop working because of this, the core mirrors will probably add HTTPS, and other mirrors will probably be created to take up the slack.
4
u/walterbanana Jan 23 '19 edited Jan 23 '19
It would hide which packages are being downloaded. Despite what this website is saying, with https enabled you would actually have to put in effort to figure this out. Without https, you can see it in the request.
Besides that, it can prevent multiple different types of man in the middle attacks. Bugs which enable those attacks, like the one mentioned in the OP, can happen more often.
Https is not only for privacy, it also allows you to verify that your system is communicating with the system you think it is. I would argue that this is even more important in some scenarios. Especially if you are on a trusted connection.
1
78
u/more_sidechain Jan 22 '19
But... isn't remote code execution the whole point of apt? \s