Skip to content

Commit

Permalink
enip: convert to rust
Browse files Browse the repository at this point in the history
Ticket: 3958

- enip_command keyword accepts now string enumeration as values.
- transactions are now bidirectional
- there is a logger
- gap support is improved with probing for resync
- SEQUENCE_ADDR_ITEM value is fixed to 0x8002 instead of 0xB002
- frames support
- app-layer events
- add enip.status keyword
  • Loading branch information
catenacyber committed Nov 20, 2023
1 parent ea7e098 commit 42b5fac
Show file tree
Hide file tree
Showing 32 changed files with 2,262 additions and 2,669 deletions.
3 changes: 2 additions & 1 deletion doc/userguide/configuration/suricata-yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,8 @@ incompatible with ``decode-mime``. If both are enabled,
Maximum transactions
~~~~~~~~~~~~~~~~~~~~

MQTT, FTP, PostgreSQL, SMB, DCERPC and NFS have each a `max-tx` parameter that can be customized.
MQTT, FTP, PostgreSQL, SMB, DCERPC, ENIP and NFS have each a `max-tx`
parameter that can be customized.
`max-tx` refers to the maximum number of live transactions for each flow.
An app-layer event `protocol.too_many_transactions` is triggered when this value is reached.
The point of this parameter is to find a balance between the completeness of analysis
Expand Down
37 changes: 20 additions & 17 deletions doc/userguide/rules/enip-keyword.rst
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
ENIP/CIP Keywords
=================

The enip_command and cip_service keywords can be used for matching on various properties of
ENIP requests.
enip_command
------------

There are three ways of using this keyword:
For the ENIP command, we are matching against the command field found in the ENIP encapsulation.

Examples::

* matching on ENIP command with the setting "enip_command";
* matching on CIP Service with the setting "cip_service".
* matching both the ENIP command and the CIP Service with "enip_command" and "cip_service" together
enip_command:99;
enip_command:ListIdentity;


For the ENIP command, we are matching against the command field found in the ENIP encapsulation.
cip_service
-----------

For the CIP Service, we use a maximum of 3 comma separated values representing the Service, Class and Attribute.
These values are described in the CIP specification. CIP Classes are associated with their Service, and CIP Attributes
are associated with their Service. If you only need to match up until the Service, then only provide the Service value.
If you want to match to the CIP Attribute, then you must provide all 3 values.


Syntax::

enip_command:<value>
cip_service:<value(s)>
enip_command:<value>, cip_service:<value(s)>


Examples::

enip_command:99
cip_service:75
cip_service:16,246,6
enip_command:111, cip_service:5


(cf. http://read.pudn.com/downloads166/ebook/763211/EIP-CIP-V1-1.0.pdf)

Information on the protocol can be found here:
`<http://literature.rockwellautomation.com/idc/groups/literature/documents/wp/enet-wp001_-en-p.pdf>`_

enip.status
-----------

For the ENIP status, we are matching against the status field found in the ENIP encapsulation.
It uses a 32-bit unsigned integer as value.

Examples::

enip.status:100;
enip.status:>106;
69 changes: 69 additions & 0 deletions etc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,75 @@
},
"additionalProperties": false
},
"enip": {
"type": "object",
"properties": {
"request": {
"type": "object",
"properties": {
"command": {
"type": "string"
},
"status": {
"type": "string"
},
"length": {
"type": "integer"
}
},
"additionalProperties": false
},
"response": {
"type": "object",
"properties": {
"command": {
"type": "string"
},
"status": {
"type": "string"
},
"length": {
"type": "integer"
},
"identity": {
"type": "object",
"properties": {
"protocol_version": {
"type": "integer"
},
"revision": {
"type": "string"
},
"vendor_id": {
"type": "integer"
},
"device_type": {
"type": "integer"
},
"product_code": {
"type": "integer"
},
"status": {
"type": "integer"
},
"serial": {
"type": "integer"
},
"product_name": {
"type": "string"
},
"state": {
"type": "integer"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
"ether": {
"type": "object",
"properties": {
Expand Down
1 change: 1 addition & 0 deletions rules/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ decoder-events.rules \
dhcp-events.rules \
dnp3-events.rules \
dns-events.rules \
enip-events.rules \
files.rules \
ftp-events.rules \
http-events.rules \
Expand Down
8 changes: 8 additions & 0 deletions rules/enip-events.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ENIP app layer event rules
#
# SID's fall in the 2223000+ range. See https://redmine.openinfosecfoundation.org/projects/suricata/wiki/AppLayer
#
# These sigs fire at most once per connection.
#
alert enip any any -> any any (msg:"SURICATA ENIP too many transactions"; app-layer-event:enip.too_many_transactions; classtype:protocol-command-decode; sid:2233000; rev:1;)
alert enip any any -> any any (msg:"SURICATA ENIP invalid PDU"; app-layer-event:enip.invalid_pdu; classtype:protocol-command-decode; sid:2233001; rev:1;)
1 change: 1 addition & 0 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ extern {
pub fn AppLayerParserStateIssetFlag(state: *mut c_void, flag: u16) -> u16;
pub fn AppLayerParserSetStreamDepth(ipproto: u8, alproto: AppProto, stream_depth: u32);
pub fn AppLayerParserConfParserEnabled(ipproto: *const c_char, proto: *const c_char) -> c_int;
pub fn AppLayerParserRegisterParserAcceptableDataDirection(ipproto: u8, alproto: AppProto, dir: u8);
}

#[repr(C)]
Expand Down
Loading

0 comments on commit 42b5fac

Please sign in to comment.