Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
nfc2mqtt reads NFC tags with nfcpy and push them to MQTT.
nfc2mqtt stores all data in encrypted form on NFC tag. Because of that, nfcpy
should be able to write NDEF on used tags.
For more information about tag payload please see nfc2mqtt tag payload.
nfc2mqtt is NOT "simple" bridge between NFC and MQTT. It is not suposed to scan tag ID and send it to MQTT. It stores encrypted payload on tag/card, and send this payload to MQTT after reading (if valid).
nfc2mqtt dosen't store list of valid tags, tag is valid when encrypted content is valid (can be decrypted and its not expired).
Because of that, scan process is longer (~1-2s) (we need not only to sense
nfc tag, we also need to read tag data).
Python3 and pip3 should be installed and working.
$ pip3 install nfc2mqtt
There is ready nfc2mqtt docker image. Just pull ghcr.io/bkupidura/nfc2mqtt:latest
.
$ nfc2mqtt -c /etc/nfc2mqtt.yaml
You will need to discover NFC reader usb path, and probably blacklist some kernel modules (sudo modprobe -r pn533_usb
).
$ docker run --rm -d --name nfc2mqtt -v /data/config.yaml:/config.yaml --device /dev/bus/usb/003/009 ghcr.io/bkupidura/nfc2mqtt:latest
All data written by nfc2mqtt
on tag is encrypted. Its stored as NDEF TextRecord
.
NFC tag ID can't be trusted. nfc2mqtt will NOT use ID to identify tags.
As nfc2mqtt stores everything in encrypted form, plenty of tag user bytes are wasted for encryption. Ex. simple payload AnGP7 0
({"id": "AnGP7", "valid_till": 0}
) which without encryption is 7 bytes long, after encryption is 100 bytes long.
Encryption of tags CAN'T be disabled.
tag_id valid_till [data]
Its "random" string generated during writing tag.
By default it contains [a-zA-Z0-9]
and it is 5
character long.
Stores time since epoch
(UTC) (not valid after).
By default its set to 0
, tag is valid always (don't expire).
To generate valid_till
from linux box use date -d '2020-12-27T23:59:59' +%s
Data can be used to store any user/application data. By default it is not set.
Expect empty
message or JSON message.
If empty
message is received, next tag connected to NFC reader will be written with default payload. (random tag_id
, 0 as valid_till
).
If JSON message is received, next tag conneccted to NFC reader will be written as described in JSON. Supported JSON properties:
tag_id
, if missing tag_id
will be auto generated.valid_till
, if missing valid_till
will be set to 0
data
nfc2mqtt
.Generate new tag with default values:
$ mosquitto_pub ... -t 'nfc2mqtt/write_tag' -m ''
.
Generate new tag with known id:
$ mosquitto_pub ... -t 'nfc2mqtt/write_tag' -m '{"id": "example"}'
Generate new tag with valid_till:
$ mosquitto_pub ... -t 'nfc2mqtt/write_tag' -m '{"valid_till": 1599947426}'
Generate new tag with string data:
$ mosquitto_pub ... -t 'nfc2mqtt/write_tag' -m '{"data": "string}'
Generate new tag with JSON data:
$ mosquitto_pub ... -t 'nfc2mqtt/write_tag' -m '{"data": {"json": true}}'
Generate new tag with multiple fields:
$ mosquitto_pub ... -t 'nfc2mqtt/write_tag' -m '{"id": "example", "valid_till": 1700000000, "data": {"field1": "value1", "field2": 1}}'
Expect empty
message.
When message is received, next tag connected to NFC reader will be formated. For more information please check nfcpy.
$ mosquitto_pub ... -t 'nfc2mqtt/wipe_tag' -m ''
When valid tag is scanned, new message will be publish to nfc2mqtt/tag/<tag_id>
.
nfc2mqtt/tag/AnGP7
-> {"status": 1, "id": "AnGP7", "valid_till": 0, "tag": {"product": "NXP NTAG213", "type": "Type2Tag", "id": "049962228b5f80"}}
nfc2mqtt/tag/Dj3dV
-> {"status": 1, "id": "Dj3dV", "valid_till": 0, "data": {"custom": "value"}, "tag": {"product": "NXP NTAG213", "type": "Type2Tag", "id": "049962228b5f80"}}
nfc2mqtt/tag/h89u9
-> {"status": 1, "id": "h89u9", "valid_till": 1700000000, "data": "string data", "valid_till_dt_utc": "2023-11-14 22:13:20", "tag": {"product": "NXP NTAG213", "type": "Type2Tag", "id": "049962228b5f80"}}
Valid
- 1
, tag is valid and can be trustedInvalid
- 2
, tag is invalid (unable to decrypt content)UnknownPayloadType
- 3
, tag was readed (and decrypted) - but contains unknown payloadExpired
- 4
, tag already expiredScanError
- 5
, nfc2mqtt was not able to scan this tag (ex. too fast removed from reader, or wrong authentication password)NoNdef
- 6
, tag dosen't contains NDEF
field used to store content (probably not formatted by nfc2mqtt, or not supporting NDEF
)nfc2mqtt will use MQTT last will/birth message.
When it connects to MQTT broker, it will publish 1
to nfc2mqtt/online
.
When nfc2mqtt will be disconnected, nfc2mqtt/online
will be set to 0
.
I own one NFC reader (ACR122U
), so all development is done on it.
Tags NOT supported by nfc2mqtt:
Tags supported by nfc2mqtt:
Before first run you should change authenticate_password
and encrypt_key
. New keys can be generated with fernet token.
Ensure that encrypt_key
is different than authenticate_password
.
nfc:
reader: usb
authenticate_password: pa2SB6ZC8NUFzX1IXBbA7OF9xj5cTrdAImkx3t9i0Fw=
encrypt_key: Wv_o4fUMFrPFZv0Es02f361nW_kdpFLdXdTo7e7jo0c=
id_length: 5
mqtt:
server: localhost
port: 1883
keepalive: 30
username: nfc2mqtt
password: password
topic: nfc2mqtt
logging:
level: info
nfcpy
readder pathauthenticate
and protect
. If you change that, you will need to rewrite ALL tags. For write_tag
MQTT endpoint please provide old authenticate_password
. It can be generated with fernet token.encrypt_key
. You will need to rewrite ALL tags. This can be helpfull if you lost tag with valid_till: 0
. It can be generated with fernet token.All tags "created" by nfc2mqtt are protected from reading on NFC tag level. authenticate_password
is used for that.
Tag probably still can be cloned and readed, but all data stored physicaly on tag is encrypted with symmetric cipher and secure.
You should assume that any tag lost or passed to stranger can be cloned and used in malicious way.
Attacker will not be able to read decrypted content of yours NFC tag (tag_id
, valid_till
, data
). Also attacker will not be able to change NFC tag content (he would need to know encrypt_key
).
So if you give yours petsitter NFC tag, with valid_till
set to ex. utcnow()
+ 1 week
, this tag will work only for 1 week
, not longer.
If you lost NFC tag with valid_till: 0
, you should change encrypt_key
in nfc2mqtt and rewrite all trusted tags with new encrypt_key
.
Tags should be treated as physcial lock keys. If you lost tag for 2h (in the wild, not in yours apartment), you should assume that tag is copromised, and you should change encrypt_key
.
$ python3 -c 'from cryptography.fernet import Fernet;print(Fernet.generate_key().decode())'
FAQs
nfc2mqtt reads NFC tags with nfcpy and push them to MQTT
We found that nfc2mqtt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.