[流量分析]Modbus流量分析

常见Modbus功能码
国家标准常见功能码

个人理解就是对应写入到不同寄存器里不同的数据的查看

读:
功能码 01 为读内部比特量输出状态;如告警、变位、故障、异常等。
功能码 02 为读外部开关量输入状态;如光耦输入、继电器输入等。
功能码 03 为读内部输出量的寄存器;如一些配置参数、定值的读取等。
功能码 04 为读外部输入量的寄存器;如外部电压电流模拟量,温湿度等。
写:
功能码 05 为写内部单个开关量状态;如光耦输出、继电器输出等。
功能码 06 为写内部单个寄存器的值;如更改配置参数、定值等。
功能码 15 为写内部多个开关量状态;如同 05。
功能码 16 为写内部多个寄存器的值;如同 06;对时是写多寄存器,用此功能码。

俩个脚本,应该还有很多用处,先留下了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import pyshark #下载这个包有点问题,最好科学上网一下,Python3.5版本以上,wireshark版本尽量最新,最好组件都下好,反正流量分析没准都用得到
def get_code():
captures = pyshark.FileCapture("modbus1.pcap") #设置Modbus流量包路径
func_codes = {}
for c in captures:
for pkt in c:
if pkt.layer_name == "modbus":
func_code = int(pkt.func_code)
if func_code in func_codes:
func_codes[func_code] += 1
else:
func_codes[func_code] = 1
print(func_codes)
if __name__ == '__main__':
get_code()
#这个脚本大概就是分析不同功能码写入的值的情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pyshark
def find_flag():
cap = pyshark.FileCapture("modbus1.pcap") #设置Modbus流量包路径
idx = 1
for c in cap:
for pkt in c:
if pkt.layer_name == "modbus":
func_code = int(pkt.func_code)
if func_code == 16: #查看对应功能码寄存器下写入的值
payload = str(c["TCP"].payload).replace(":", "")
print(hex_to_ascii(payload))
print("{0} *".format(idx))
idx += 1
def hex_to_ascii(payload):
data = payload
flags = []
for d in data:
_ord = ord(d)
if (_ord > 0) and (_ord < 128):
flags.append(chr(_ord))
return ''.join(flags)
if __name__ == '__main__':
find_flag()

有问题,欢迎指正,毕竟初学
参考链接:
https://xz.aliyun.com/t/5960
[https://wenku.baidu.com/view/8e6cc5f9b4daa58da1114a20.html](https://wenku.baidu.com/view/8e6cc5f9b4daa58da1114a20.html)

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2020 Tyrant-K
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信