Skip to content
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

Overall Code Additions and Modifications for scapy-cip-enip #1

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

m4tthew-d
Copy link

A description of changes is provided below. The test packets generated in both the enip_tcp.py and enip_udp.py files from your code have remained the same. However I did notice that when looking at the enip_tcp.py test packet in Wireshark, the packet was supposedly malformed. I wanted to make sure you were aware of this.

Added Files:
enip.py

  • Conglomeration of EtherNet/IP dissection classes from enip_tcp and enip_udp files
  • Dictionary of device profile IDs for EtherNet/IP devices

Modified Files:
cip.py

  • Added CIP_PortSegment class
  • Added CIP_LogicalSegment class
  • Added CIP_PathPadded class
  • More scapy_all.bind_layers() statements
  • Corrected issue in CIP_ConnectionParam class method do_build that caused malformed packet creation
  • Changed field types for some fields in CIP_ReqForwardOpen

enip_cpf.py

  • Changed CPF_Address_Item class into CPF_Item
  • Expanded Item ID numbers

enip_tcp.py

  • Added import from new file, enip.py
  • Moved most classes to enip.py
  • Updated appropriate code references to reflect relocation of classes to enip.py

enip_udp.py

  • Added import from enip_tcp.py
  • Moved most classes to enip.py
  • Updated appropriate code references to reflect relocation of classes to enip.py
  • Added more scapy_all.bind_layers() statements

plc.py

  • Updated references in code to reflect enip_tcp and enip_udp class relocations to enip.py

utils.py

Updated enip_tcp.py and moved portions to enip.py
Added field classes and function to merge dictionaries for use with ITEM_ID lists in cip.py file
Updated file references to take into account reorganization of some code to new or different files.
Added more CIP packet classes and more scapy_all.bind_layers() statements.
Corrected issue of malformed packet creation when communicating with PLC.
Modified field types in CIP_ReqForwardOpen for a more favorable display.
Expanded Item ID numbers and changed CPF_Address_Item into CPF_Item and created separate classes for Address and Data Items.
Also updated tests in '__main__' accordingly
Added more scapy_all.bind_layers() statements and altered code and '__main__' to reflect relocation.
Added dictionary of device profiles IDs for EtherNet/IP devices
Updated code reference to reflect relocation of code
@noleti
Copy link
Contributor

noleti commented Aug 10, 2016

Hi Matthew, thanks for the contribution. Let me check for compatibility issues with our existing private projects using this library. I will then pull this afterwards.

@francozappa
Copy link

Hi @m4tthew-d, first of all thank you for your contributions 👍

I'll review your list of commits and give you some feedback soon.

@francozappa
Copy link

Hi @m4tthew-d ,

I've tried to split the PR in several parts and this are my feedback:

Part 1: enip.py file

You placed all the enip dissection logic taken from enip_tcp and
enip_udp in a new enip.py file, changing ENIP_TCP into ENIP_PACKET and
he added also some dicts to it. I would ask you to revert back the changes
(eg: move back dissection logic to relevant files and rename back top
level classes such as ENIP_PACKET to ENIP_TCP)
because I think is better to keep the file structure as it was eg:
enip_tcp,py contains both the dissection logic and the test cases.

Furthermore, please check and add the relevant test cases to
the relevant enip_* file in case you added or changed any dissection
class value. Finally, please move what is left in enip.py to utils.py
or maybe in a new file and then import them where needed.

Part 2: cip.py

I saw that you added and modified several cip dissection classes but
I did not check if you added also the corresponding unit-test cases, indeed
please point us to the relevant tests if any or add them

Part 3: plc.py

Please rearrange the import statement according to Part 1 and 2

Thank you again !

@rajatkmehta
Copy link

rajatkmehta commented Jan 16, 2019

Hi @m4tthew-d, @noleti @francozappa
I am using scapy-cip-enip to communicate from our EIP enabled device. For explicit(Unconnected), i am getting proper response for almost all the objects.
But when i try for Implicit(Connected) messaging by sending forward_open request as function already defined.
Getting error as...
[ERROR] Failed to Forward Open CIP connection: <CIP_ResponseStatus status=Not enough data>

Please guide me on the actual 'CIP_REqForwardOpen parameters and path'which should be send as a request to get proper response. Thanks in advance.

def forward_close(self):
    """Send a forward close request"""
    cippkt = CIP(service=0x4e, path=CIP_Path(wordsize=2, path=b'\x20\x06\x24\x01'))
    cippkt /= CIP_ReqForwardClose(path_wordsize=3, path=b"\x01\x00\x20\x02\x24\x01")
    self.send_rr_cip(cippkt)
    if self.sock is None:
        return
    resppkt = self.recv_enippkt()
    cippkt = resppkt[CIP]
    if cippkt.status[0].status != 0:
        logger.error("Failed to Forward Close CIP connection: %r", cippkt.status[0])
        return False
    return True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants