-
Notifications
You must be signed in to change notification settings - Fork 222
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
mbusd - read only option #117
Comments
How should that work? The only "read only" modus i can image is a simple monitoring of the messages on the Bus/USB Adapter. Can you elaborate more what you expect? |
Hello, The use case: We have a network of around 20 frequency controllers behind an Modbus RTU to Modbus IP gateway running mbusd. We use Zabbix to monitor the values over the gateway with the use of ,,modbus_read" function. Obwiously it's a separated dedicated network, but still... example: modbus_read[192.168.1.10:502,20,1,4,uint16] But we are hardening our security and we would like to reject "write" commands coming to the IP side. So no Write command could be directed to RTU side from IP side. Hope i have explained it clearly -> the use case. Buf if there would be a function modbus_write[] this could bring security issues -> someone could turn ON or OFF devices, etc... we have seen such articles in the news :) |
@mStirner - Any thoughts on this? How to mitigate possible write command coming over IP to mbusd? |
afaik there is no build in method.
The second solution could be done in python or node, just a few lines of code: const { createConnection, Server } = require("net");
const server = new Server();
server.on("connection", (socket) => {
let connected = false;
// listen for incoming data once (from zabixx)
// if function code is valid, the client & mbusd streams are piped below
socket.once("data", (chunk) => {
// not sure which byte is function code in a Modbus IP packet
// chat gpt said byte 8
// example: 00 01 00 00 00 06 01 03 00 00 00 02
/*
- Transaction ID: 00 01 (2 Bytes)
- Protocol ID: 00 00 (2 Bytes)
- Length: 00 06 (6 Bytes folgen)
- Unit Identifier: 01 (1 Byte)
- Function Code: 03 (Read Holding Registers)
- Data: 00 00 00 02 (Startadresse 0x0000, 2 Register read)
*/
// check if byte 8 is either 1, 2 or 3
// and connect to mbusd + forward data
// TODO: not sure if need to hex formated (0x01) or plain int
if ([1, 2, 3].includes(chunk[7])) {
if (!connected) {
// connect to mbusd
// IMPPORTANT: configure mbusd to listen only on the loopback interface!!!!
let client = createConnection(502, "127.0.0.1", () => {
connected = true;
});
client.pipe(socket); // pipe data from mbusd to client
socket.pipe(client); // pipe data from client to mbusd
client.write(chunk); // write initial message chunk to mbusd
}
} else {
// wrong modbus function code
// drop connection
socket.end();
}
});
});
// "expose" our gateway instead of mbusd to the network
// mbusd should only listen on the loopback interface
server.listen(502, "192.168.1.123", (err) => {
console.log(err || "Modbus gateway listening on tcp://192.168.1.123:502");
}); Not tested, just put quickly together. |
With the Modbus read-only option should only pass modbus messages which contain function code 1 ... 4.(read coils / registers). Thanks |
Feel free to create a pull request if the approach above does not suit your needs. |
Creating pull request doesn't work for unknown reason.
|
@lacithehun Note that im not the maintainer of mbusd. |
Yes, please. |
I have seen you created a PR yesterday: #119 |
I got upset because I couldn't make a pull request.Then I found that a fork is needed first, so I forked.Made the changes, but only could make PRs file-by-file.Despite the system told that the branches will be merged automatically, it didn't happen.I neither have time, nor have help, so gave up and asked your assistance
|
Hello all, I like the idea as a whole, but still not sure about the implementation. Should mbusd in read-only mode ignore write function codes completely and trigger the timeout in Modbus TCP master, or send some exception code in the response? |
Is it not the case, that exceptions codes triggerd/apply/thrown only by the underlayiing modbus device? If currently mbusd does not send any modbus expections, i would personally prefer a tcp/ip based approach. EDIT: I just seen, that there is a "Gateway Error", I think that could work, as it differ clearly from other exepctions that may the modbus device could throw. |
The simplest (and) way is to ignore the write function (timeout method). For protection purposes the timeout method is sufficent, because normally the cyclical readings are passed to the serial devices, so it can be easily checked if the are up or not. |
Hello dear community, with the aspect of security, is there the possibility to allow only read operations through the gateway?
or could this feature be added with a context switch -ro ?
One could modify the code and build the app without write features, but this could be interesting.... to have a hardened security feature.
Thanks!
The text was updated successfully, but these errors were encountered: