Merge upstream/dev (1 commit: sec patch) [upstream-sync]
Changelog: Repeater, room server, sensor: an admin's CLI reply captured over the air can no longer be sent back to the node as a command (upstream security fix) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
22700192bd
15 files changed
+151
-12
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "MyMesh.h"
|
||||
#include <algorithm>
|
||||
#include <helpers/sensors/LPPDataHelpers.h>
|
||||
#include <helpers/UTF8Helpers.h>
|
||||
|
||||
/* ------------------------------ Config -------------------------------- */
|
||||
|
||||
@@ -404,7 +405,6 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
|
||||
}
|
||||
MESH_DEBUG_PRINTLN("Login success!");
|
||||
client->last_timestamp = sender_timestamp;
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
client->permissions &= ~0x03;
|
||||
client->permissions |= perms;
|
||||
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): admin only, so after the role
|
||||
@@ -414,6 +414,7 @@ uint8_t MyMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t* secr
|
||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||
}
|
||||
}
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
|
||||
if (is_flood) {
|
||||
client->out_path_len = OUT_PATH_UNKNOWN; // need to rediscover out_path
|
||||
@@ -1252,12 +1253,12 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
uint32_t timestamp;
|
||||
memcpy(×tamp, data, 4);
|
||||
|
||||
if (timestamp > client->last_timestamp) { // prevent replay attacks
|
||||
if (timestamp > client->last_req_timestamp) { // prevent replay attacks
|
||||
acl.persistTimestamp(client, timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
|
||||
int reply_len = handleRequest(client, timestamp, &data[4], len - 4);
|
||||
if (reply_len == 0) return; // invalid command
|
||||
|
||||
client->last_timestamp = timestamp;
|
||||
client->last_req_timestamp = timestamp;
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
|
||||
if (packet->isRouteFlood()) {
|
||||
@@ -1286,6 +1287,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
|
||||
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: unsupported text type received: flags=%02x", (uint32_t)flags);
|
||||
} else if (!mesh::isValidUtf8TextAndPadding(&data[5], len - 5)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: invalid text payload! (id prefix: %02X:%02X)", client->id.pub_key[0], client->id.pub_key[1]);
|
||||
_err_flags |= ERR_EVENT_DIAG1; // report in next Get Stats
|
||||
} else if (_reply_echo.matches(data, 5 + strnlen((const char *)&data[5], len - 5))) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: text is our own CLI reply");
|
||||
} else if (sender_timestamp >= client->last_timestamp) { // prevent replay attacks
|
||||
bool is_retry = (sender_timestamp == client->last_timestamp);
|
||||
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
|
||||
@@ -1329,6 +1335,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
}
|
||||
memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique
|
||||
temp[4] = (TXT_TYPE_CLI_DATA << 2); // NOTE: legacy was: TXT_TYPE_PLAIN
|
||||
_reply_echo.note(temp, 5 + text_len);
|
||||
|
||||
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
|
||||
if (reply) {
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <helpers/ArduinoHelpers.h>
|
||||
#include <helpers/ClientACL.h>
|
||||
#include <helpers/LoginGuard.h> // CUSTOM (TeTeHacko)
|
||||
#include <helpers/ReplyEchoGuard.h>
|
||||
#include <helpers/CommonCLI.h>
|
||||
#include <helpers/IdentityStore.h>
|
||||
#include <helpers/SimpleMeshTables.h>
|
||||
@@ -197,6 +198,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
NodePrefs _prefs;
|
||||
ClientACL acl;
|
||||
LoginGuard login_guard; // CUSTOM (TeTeHacko)
|
||||
ReplyEchoGuard _reply_echo;
|
||||
CommonCLI _cli;
|
||||
uint8_t reply_data[MAX_PACKET_PAYLOAD];
|
||||
uint8_t reply_path[MAX_PATH_SIZE];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "MyMesh.h"
|
||||
#include <helpers/UTF8Helpers.h>
|
||||
#include <algorithm>
|
||||
|
||||
#define REPLY_DELAY_MILLIS 1500
|
||||
@@ -390,7 +391,6 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
|
||||
client->extra.room.pending_ack = 0;
|
||||
client->extra.room.push_failures = 0;
|
||||
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
client->permissions &= ~0x03;
|
||||
client->permissions |= perm;
|
||||
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): admin only, so after the role
|
||||
@@ -398,6 +398,7 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
|
||||
|
||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||
}
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
|
||||
if (packet->isRouteFlood()) {
|
||||
client->out_path_len = OUT_PATH_UNKNOWN; // need to rediscover out_path
|
||||
@@ -469,6 +470,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
|
||||
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: unsupported command flags received: flags=%02x", (uint32_t)flags);
|
||||
} else if (!mesh::isValidUtf8TextAndPadding(&data[5], len - 5)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: invalid text payload! (id prefix: %02X:%02X)", client->id.pub_key[0], client->id.pub_key[1]);
|
||||
_err_flags |= ERR_EVENT_DIAG1; // report in next Get Stats
|
||||
} else if (_reply_echo.matches(data, 5 + strnlen((const char *)&data[5], len - 5))) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: text is our own CLI reply");
|
||||
} else if (sender_timestamp >= client->last_timestamp) { // prevent replay attacks, but send Acks for retries
|
||||
bool is_retry = (sender_timestamp == client->last_timestamp);
|
||||
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
|
||||
@@ -544,6 +550,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
now++;
|
||||
}
|
||||
memcpy(temp, &now, 4); // mostly an extra blob to help make packet_hash unique
|
||||
_reply_echo.note(temp, 5 + text_len);
|
||||
|
||||
// calc expected ACK reply
|
||||
// mesh::Utils::sha256((uint8_t *)&expected_ack_crc, 4, temp, 5 + text_len, self_id.pub_key,
|
||||
@@ -564,11 +571,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
} else if (type == PAYLOAD_TYPE_REQ && len >= 5) {
|
||||
uint32_t sender_timestamp;
|
||||
memcpy(&sender_timestamp, data, 4); // timestamp (by sender's RTC clock - which could be wrong)
|
||||
if (sender_timestamp < client->last_timestamp) { // prevent replay attacks
|
||||
if (sender_timestamp < client->last_req_timestamp) { // prevent replay attacks
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: possible replay attack detected");
|
||||
} else {
|
||||
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
|
||||
client->last_timestamp = sender_timestamp;
|
||||
client->last_req_timestamp = sender_timestamp;
|
||||
|
||||
uint32_t now = getRTCClock()->getCurrentTime();
|
||||
client->last_activity = now; // <-- THIS will keep client connection alive
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <helpers/StatsFormatHelper.h>
|
||||
#include <helpers/ClientACL.h>
|
||||
#include <helpers/LoginGuard.h> // CUSTOM (TeTeHacko)
|
||||
#include <helpers/ReplyEchoGuard.h>
|
||||
#include <helpers/RegionMap.h>
|
||||
#include <helpers/RoutingPolicy.h>
|
||||
#include <RTClib.h>
|
||||
@@ -100,6 +101,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
RegionMap region_map, temp_map;
|
||||
ClientACL acl;
|
||||
LoginGuard login_guard; // CUSTOM (TeTeHacko)
|
||||
ReplyEchoGuard _reply_echo;
|
||||
CommonCLI _cli;
|
||||
unsigned long dirty_contacts_expiry;
|
||||
uint8_t reply_data[MAX_PACKET_PAYLOAD];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "SensorMesh.h"
|
||||
#include <helpers/RoutingPolicy.h>
|
||||
#include <helpers/sensors/LPPDataHelpers.h>
|
||||
#include <helpers/UTF8Helpers.h>
|
||||
|
||||
/* ------------------------------ Config -------------------------------- */
|
||||
|
||||
@@ -438,13 +439,13 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
|
||||
}
|
||||
MESH_DEBUG_PRINTLN("Login success!");
|
||||
client->last_timestamp = sender_timestamp;
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
client->permissions |= PERM_ACL_ADMIN;
|
||||
acl.persistTimestamp(client, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): admin only, so after the role
|
||||
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
|
||||
|
||||
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
|
||||
}
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
|
||||
if (is_flood) {
|
||||
client->out_path_len = OUT_PATH_UNKNOWN; // need to rediscover out_path
|
||||
@@ -698,7 +699,12 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
||||
memcpy(&sender_timestamp, data, 4); // timestamp (by sender's RTC clock - which could be wrong)
|
||||
uint8_t flags = (data[4] >> 2); // message attempt number, and other flags
|
||||
|
||||
if (sender_timestamp > from->last_timestamp) { // prevent replay attacks
|
||||
if (!mesh::isValidUtf8TextAndPadding(&data[5], len - 5)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: invalid text payload! (id prefix: %02X:%02X)", from->id.pub_key[0], from->id.pub_key[1]);
|
||||
_err_flags |= ERR_EVENT_DIAG1; // report in next Get Stats
|
||||
} else if (_reply_echo.matches(data, 5 + strnlen((const char *)&data[5], len - 5))) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: text is our own CLI reply");
|
||||
} else if (sender_timestamp > from->last_timestamp) { // prevent replay attacks
|
||||
acl.persistTimestamp(from, sender_timestamp, getRTCClock()->getCurrentTime()); // CUSTOM (TeTeHacko): before acting
|
||||
if (flags == TXT_TYPE_PLAIN) {
|
||||
bool handled = handleIncomingMsg(*from, sender_timestamp, &data[5], flags, len - 5);
|
||||
@@ -737,6 +743,7 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
||||
}
|
||||
memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique
|
||||
temp[4] = (TXT_TYPE_CLI_DATA << 2);
|
||||
_reply_echo.note(temp, 5 + text_len);
|
||||
|
||||
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, from->id, secret, temp, 5 + text_len);
|
||||
if (reply) {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <helpers/StatsFormatHelper.h>
|
||||
#include <helpers/ClientACL.h>
|
||||
#include <helpers/LoginGuard.h> // CUSTOM (TeTeHacko)
|
||||
#include <helpers/ReplyEchoGuard.h>
|
||||
#include <helpers/RegionMap.h>
|
||||
#include <RTClib.h>
|
||||
#include <target.h>
|
||||
@@ -149,6 +150,7 @@ private:
|
||||
NodePrefs _prefs;
|
||||
ClientACL acl;
|
||||
LoginGuard login_guard; // CUSTOM (TeTeHacko)
|
||||
ReplyEchoGuard _reply_echo;
|
||||
CommonCLI _cli;
|
||||
uint8_t reply_data[MAX_PACKET_PAYLOAD];
|
||||
unsigned long dirty_contacts_expiry;
|
||||
|
||||
Reference in new issue
Block a user