Skip to content
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

Security Bug in esp now without encryption check (IDFGH-6957) #8577

Closed
justjustjustus opened this issue Mar 15, 2022 · 14 comments
Closed

Security Bug in esp now without encryption check (IDFGH-6957) #8577

justjustjustus opened this issue Mar 15, 2022 · 14 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@justjustjustus
Copy link

Environment

  • Module or chip used: ESP32-WROVER
  • IDF version: v4.3.1

Problem Description

Below description is for esp now communication.
Enable esp now encryption on one device A, but do not enable encryption on device B.
If sending an unencrypted message from device B to device A, it is still accepted and handled as it is encrypted, so it is delivered to the application, without notice about that the message was not encrypted.

Additionally, the device A does always receive an ack from device B, even if the message can't be decrypted and given to the application on device B, which may false-flag a sent message as received.

Expected Behavior

If an unencrypted message was sent from device B to device A, i would assume it is dropped as device A should only accept and decrypt encrypted messages, as it is added to the peer list with peer.encrypt = true.

Actual Behavior

The unencrypted message from device B to device A gets delivered to the application like an encrypted message.

Steps to reproduce

  1. Init WiFi & ESP NOW on device A and device B
  2. Add an encrypted peer to device A with mac of device B
  3. Add an unencrypted peer to device B with mac of device A
  4. Send (unencrypted) esp now message from device B to device A
  5. See the delivery at device B

Code to reproduce this issue

Code GIST

Debug Logs

Device A

I (1613249) MAIN: Send Message: 12:34:56:78:90:02 - 8 bytes:    5b6a9d9acb717b59
I (1613250) MAIN: Send to 12:34:56:78:90:02 done: success
I (1613517) MAIN: Received Message: 12:34:56:78:90:02 - 11 bytes:       a3413444ef4092c03ef44a

Device B

I (1613222) MAIN: Send Message: 12:34:56:78:90:01 - 11 bytes:   a3413444ef4092c03ef44a
I (1613223) MAIN: Send to 12:34:56:78:90:01 done: success

References

This is related to the feature request #8574 and might have already a possible solution.

@justjustjustus
Copy link
Author

Reference: espressif/ESP8266_NONOS_SDK#311

@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 15, 2022
@github-actions github-actions bot changed the title Security Bug in esp now without encryption check Security Bug in esp now without encryption check (IDFGH-6957) Mar 15, 2022
@jack0c
Copy link
Collaborator

jack0c commented Mar 16, 2022

Yes, it looks like an issue. We need to research how to fix this issue. @zhangyanjiaoesp PTAL

@zhangyanjiaoesp
Copy link
Collaborator

@justjustjustus
Thanks for reporting this bug, we will solve the encrypted device can receive unencrypted packets issue as soon as possible.
As for this:

Additionally, the device A does always receive an ack from device B, even if the message can't be decrypted and given to the application on device B, which may false-flag a sent message as received.

The ack from device B is MAC ack, you can check whether device B receive the packets in the API layer.

@justjustjustus
Copy link
Author

Thank you really much.

The ack from device B is MAC ack, you can check whether device B receive the packets in the API layer.

I already thought this is the case, but still wanted to mention it. Thanks for clarifying.

@zhangyanjiaoesp Please also have a look at #8574 too, as this might still enable this security issue to be exploited as soon as a broadcast peer is added to the peer list.

@negativekelvin
Copy link
Contributor

I have seen this issue mentioned multiple times in different places in the past so good it is getting fixed now

@zhangyanjiaoesp
Copy link
Collaborator

OK, I will look into #8574 also.

@RutgerOlsbergs
Copy link

Has anything happened with this issue? Just noticed the same behaviour today and it's a major security concern.

@justjustjustus
Copy link
Author

@zhangyanjiaoesp Are there any updates regarding the fix for this issue?

@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new Resolution: NA Issue resolution is unavailable labels Apr 24, 2022
@zhangyanjiaoesp
Copy link
Collaborator

Please use 63af85f branch to test.

@justjustjustus
Copy link
Author

justjustjustus commented Apr 27, 2022

@zhangyanjiaoesp thank you. I looked at the docs/esp_now.h, but could't find a change, only the precompiled library has changed. Is there now a different callback for encrypted/unencrypted or broadcasted/direct messages or an additional parameter to check for encryption? Or are broadcasted and encrypted direct message treated equally still (like described in #8574)?

@zhangyanjiaoesp
Copy link
Collaborator

@justjustjustus We use additional parameter to check the encrypted packets in the wifi lib.

@justjustjustus
Copy link
Author

@zhangyanjiaoesp yes, but the general security issue still persists. As soon as you add a broadcast peer, all messages can be received by the application layer. If i have two notes with same software-defined mac, one with encryption and the other one without but as broadcast, both notes would be able to send messages to a third one, without the third one knowing which of the both sent the message and if it was encrypted or broadcasted. I described this in #8574. An Attacker could just send broadcasted messages with same mac as the attacked device and so, circumventing the whole encryption, making it useless.

Without a change of the esp_now.h and its functions (e.g. new function for broadcast or encrypted-flag in callback function) this is not fixable.

@negativekelvin
Copy link
Contributor

negativekelvin commented Apr 28, 2022

Yes, esp-now API is too simple, too much information is disappeared in wifi lib. There should be new api with all frame information passed to callback including destination address, flags, rssi, errors -- esp_now_register_verbose_recv_cb. Send call back should give number of retries before packet is acked.

I want application layer to decide whether to drop unencrypted packets or broadcast packets from encrypted peer, not wifi lib.

@zhangyanjiaoesp
Copy link
Collaborator

@negativekelvin @justjustjustus OK, we will try to pass more information to the callback, maybe a new API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

6 participants