-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: missing integrity checks let attacker forge arbitrary message content using a known plaintext attack and replaying messages even when PSK is not known #4030
Comments
If implementing AEAD is not possible, a correct MAC (which include both message content, PSK and use a cryptographically secure hashing algorithm) is also acceptable, this historically created Side-Channel-Attacks in TLS1.2 which required TLS1.2 implementations to add mitigations and TLS1.3 removed all non AEAD support. Even in the worst correct case MAC with SCA is way better than the current state of things. |
Actually I over-complicated padding. |
16 bytes is ideal, but shorter authentication tags can be used for AES-GCM/AES-CCM. 12 bytes would still be fine, and depending on the situation, even 8 bytes can be used. The slow rate at which messages can be sent could justify using shorter tags. |
If the fundamental protocol will change, given issues like this have been so extant, I would propose finding existing cryptographic solutions and systems to use as much as possible, so as to share work in maintaining them with others. There is AI-driven attack research now. |
This issue has been mentioned on Meshtastic. There might be relevant details there: https://meshtastic.discourse.group/t/meshtastic-encryption-implementation-flaw-corrected-yet/13539/2 |
This issue has been mentioned on Meshtastic. There might be relevant details there: https://meshtastic.discourse.group/t/meshtastic-encryption-implementation-flaw-corrected-yet/13539/6 |
#2610 is possibly relevant. As I understand it, MACs are not subject to the birthday paradox (Reference: https://crypto.stackexchange.com/questions/50085/are-macs-vulnerable-to-birthday-attacks). An 8-byte MAC, at 500 messages per second, would take hundreds of thousands of years to get one fake message through, if I understand the math: 2^63÷(500×3600×24×365) A four-byte MAC at a still unrealistically high 10 messages per second would take 6 years. But, you could lock out for a few seconds if you get too many incorrect MACs, so it would be more like hundreds of years. I think a more relevant attack would be replay attacks. Not likely for the admin channel, but very likely in some use cases. I've mentioned this before in other threads, but rather than an 8-byte MAC, what about a 4-6 byte MAC, with a timestamp? Setting the time could be done with a dedicated time sync packet, itself authenticated. If you don't get a time update in a few months, fall back to ignoring time. The timestamp could actually just be implicit, you could make the MAC key a hash of (Timestamp+actual key). Then you only need the four extra bytes. The timestamp would just have to only be precise to a few minutes, and you'd have to try decrypting with both possible keys, if you're right on the edge of a time boundary. Or, you could have an explicit timestamp, in the plaintext associated data, which would incidentally also serve as a time sync packet, that any other node could also read, just without the authentication. For replay attacks within few minute time window, a simple one byte message counter counter be used, that resets at the start of a time window. Just keep track of the time you last got each of the possible values. It breaks down if you have multiple senders to one receiver within a time window, but that's fine for admin channel, and most home automation tasks, and could be disabled for the rest. If nodes randomize their starting counter values it would mostly work with multiple nodes anyway. With a tiny bit more memory you could also just keep track of all messages you got in the last few minute. Security is such a big topic right now, and people like to black hat hack things just because they can. 4-6 bytes for some peace of mind and universal applicability in hypothetical stuff like garage door openers seems very much worth it. |
Ok so I was implementing CCM-optin and rweather/arduinolibs#52 is a blocker for linux-native and rp2040 targets. Chances are I'll fix this upstream. |
Hi @Jorropo . In 2.5.0 we've re-done the admin channel with some PKI , which should fix this issue. |
I'm a bit confused why this issue is reported only for the admin channel, and (as it appears currently) only addressed for the admin channel. Any private channel would be affected by this in the same way. Of course, the admin channel is the most tempting as it allows re-configuring a node, but even on other channels it would be an issue. I could spin up a repeater that always flips a few bits before forwarding a message. Any receivers who got the message via this repeater won't be able to determine that the message was manipulated (unless it corrupts the protobuf structure, but I can probably guess where the actual meaningful part is). As repeaters are invisible, I think it wouldn't even be possible for the nodes around me to ignore all messages from my repeater. Is this correct or am I missing something? |
@xnyhps this has nothing to do with admin channel and affects everything as you correctly pointed out. The idea I had is that if you randomly flipped bits there would presumably be a carbon based intelligence that would understand a glitchy hopefully not valid UTF8 message to be something wrong while a silicon based intelligence wouldn't. |
I've tried fixing it by adding an AEAD channel mode option but changing the architecture of the C++ code to integrate an extra option, do it correctly on all targets, was not fun so I gave up. |
Category
Other
Hardware
Not Applicable
Firmware Version
all ¿ (fundamental protocol issue)
Description
This was discussed with @caveman99 in
#contributor-lounge
he gave me the go ahead to post it here.Here is pseudo code targeting the admin module, this would let an attacker observe an admin packet, modify it and change more or less any settings at will on all the nodes using this admin PSK:
The fix I recommend is to use AEAD.
I have prior experience with AES-GCM it is AES-CTR (what we are currently using) with a bit of extra math, this adds a 16 bytes hash after the message, it is accelerated on ESP32 and the extra math is not extremely expensive.
The main drawbacks:
This is not a very hard engineering problem, protobuf isn't that efficient and I guess we could find a way to gain a few bytes.
This can be solved by making this optional when configuring your channel, most channels like
AQ==
would gain nothing but we could enforce this foradmin
. So users would be able to toggle if they want integrity protectionESP32 chips also support AES-CCM acceleration.
So AES-CCM should be a good alternative, drawback 1 and 2 still apply.
AES-CCM is often what is used in WPA3.
AES-GCM is used in an overwhelming of TLS1.3 connections (altho Chacha20-Poly1305 is also often implemented as a fallback for CPUs who lack AES hardware acceleration), updated TLS1.2 clients also often prefer AES-GCM based suites. You are extremely likely to be using AES-GCM to view this very same issue.
This would not solve all the issue present in meshtastic's encryption, this only solve Integrity but not Perfect-Forward-Secrecy or Authentication.
Relevant log output
Is it dangerous to use the admin module ?
Probably not:
The admin module is most useful on unattended nodes where a physical attack is significantly easier and faster to perform.
This require to first capture a valid packet sent on the admin channel which is unlikely because how often do you change configuration settings ?
The attacker then need to identify which packet were sent on the admin channel, this is easier said than done, packets do not publicly indicate which channel they are a part of, there is no easy way to differentiate a packet on the admin channel to any random encrypted packet.
Then the attacker must correctly guess some bits in the admin message, in general each bit guessed correctly can be changed to attacker's value of choice. Admin messages a fair bit complex.
Examples of things that are "easy":
This is because a huge portion of the message is identical and the device role is broadcasted in nodeinfo making guessing easier.
Changing the target of an admin message that clearly reflect changes in public info is also "easy".
For example you have two nodes using the same admin channel, you update some configs on node A, an attacker can then send the same configuration to node B. The problem with this is that the attacker does not know which nodes share the same admin channel.
Tl;Dr: the vast majority of attacks are harder and it take significantly more time than gaining physical access to your node.
Most impacts of such attack would be making the mesh unreliable, using the same hardware this can be done by setting HOP_LIMIT=7, override the duty cycle checks and configure the node to spam random messages every second completely hogging the spectrum.
Workarounds:
The text was updated successfully, but these errors were encountered: