使用一个可用的库scapy-cip-enip尝试到EIP设备的EIP隐式消息传递

时间:2019-01-17 11:38:57

标签: python python-3.x scapy

我得到的异常:

  

[错误]无法转发打开的CIP连接:

我知道我遇到的问题是我在发送正确的转发请求参数(包括连接参数和路径大小格式)时遗漏了一些东西。但不知道确切的解决方案。

发送forward_open请求:

    def forward_open(self):
    """Send a forward open request"""
    cippkt = CIP(service=0x54, path=CIP_Path(wordsize=2, path=b'\x20\x06\x24\x01'))
    cippkt /= test_CIP_ReqForwardOpen(path_wordsize=3, path=b'\x01\x00\x20\x02\x24\x01')
    print("****", self.send_rr_cip(cippkt))
    resppkt = self.recv_enippkt()
    print("*** packet response", resppkt)
    if self.sock is None:
        return
    cippkt = resppkt[CIP]
    print("*** cippkt", cippkt)
    if cippkt.status[0].status != 0:
        logger.error("Failed to Forward Open CIP connection: %r", cippkt.status[0])
        return False
    assert isinstance(cippkt.payload, CIP_RespForwardOpen)
    self.enip_connid = cippkt.payload.OT_network_connection_id
    return True

其他参考类

class test_CIP_ConnectionParam(CIP_ConnectionParam):
name = "test_CIP_ConnectionParam"
fields_desc = [
    scapy_all.BitEnumField("owner", 0, 0, {0: "exclusive", 1: "multiple"}),
    scapy_all.BitEnumField("connection_type", 2, 1,
                           {0: "null", 1: "multicast", 2: "point-to-point", 3: "reserved"}),
    scapy_all.BitField("reserved", 0, 1),
    scapy_all.BitEnumField("priority", 2, 2, {0: "low", 1: "high", 2: "scheduled", 3: "urgent"}),
    scapy_all.BitEnumField("connection_size_type", 0, 0, {0: "fixed", 1: "variable"}),
    scapy_all.BitField("connection_size", 8, 4),
]

其他参考类

class test_CIP_ReqForwardOpen(CIP_ReqForwardOpen):
"""Forward Open request"""
name = "test_CIP_ReqForwardOpen"
priority = 0
tick_time = 10
timeout_ticks = 240
OT_network_connection_id = 0x06c2939d
TO_network_connection_id = 0x06c2939c
connection_serial_number = 0x939e
vendor_id = 0x00aa
originator_serial_number = 0x504d4153
connection_timeout_multiplier = 2
reserved = 0
OT_rpi = 0x000186A0
OT_connection_param = test_CIP_ConnectionParam(), test_CIP_ConnectionParam
TO_rpi = 0x000186A0
TO_connection_param = test_CIP_ConnectionParam(), test_CIP_ConnectionParam
transport_type = 0xa3
path_wordsize = None
CIP_PathField("path", None, length_from=lambda p: 2 * p.path_wordsize)

Scapy GitHub enter image description here 鲨鱼捕获图像1。 enter image description here 鲨鱼捕获图像1

0 个答案:

没有答案