No.
Your variant:
alert tcp any any → any any (ipv4.hdr; byte_extract: 1, 0, extracted_val, relative;byte_math: bytes 1, offset 1, oper -, rvalue extracted_val, result var;byte_test: 1, <, var, 9;msg:\ “Byte extract and byte math with byte test verification\ “;sid:1;)
My variant:
alert tcp any 102 → any any (msg:” s7comm Response Error”; flow:established,to_client; byte_math:bytes 1, offset 4, oper +, rvalue 14, result 1st_math; byte_extract:2,4,1st_extract,relative; byte_math: bytes 1st_math, offset 0, oper +, rvalue 1st_extract, result 2nd_math , relative; content:“|0a|”; offset: 2nd_math; depth:1; sid:1;)
Do you see? I want choice variable frome byte_extract for byte_math and count TWO VARIABLES.
my question is:
In documentation says, that i can choice for
num of bytes variable name by byte_extract.
In your example you choice variable in byte_math for
rvalue,
NOT for
num of bytes.
please download pcap ICS-pcap/S7/4-S7comm-Download-DB1-with-password-request at master · automayt/ICS-pcap · GitHub
i need detect error in frame 49 byte |0a|
i wrote rule with byte_math with two variable count:
alert tcp any 102 → any any (msg:“s7comm Error”;
flow:established,to_client;
byte_math:bytes 1,offset 4,oper +,rvalue 15,result offset_parameter_length;
byte_math:bytes 1,offset 4,oper +,rvalue 5,result offset_math;
content:“|32 07|”; offset:offset_math; depth:2; fast_pattern;
byte_extract:2,4,result_extract,relative;
byte_math: bytes offset_parameter_length, offset 0, oper +, rvalue result_extract, result offset_error;
content:“|0a|”; offset:offset_error;
sid:7002938; classtype:protocol-command-decode; rev:1;)
Syntaxis of this rule is correct and suricata accept it. But it does not work.
i need catch byte |0a| in offset 39.
byte_math:bytes 1,offset 4,oper +,rvalue 15,result offset_parameter_length; - it’s 17
byte_extract:2,4,result_extract,relative; - it’s 12
byte_math: bytes offset_parameter_length, offset 0, oper +, rvalue result_extract, result offset_error; - must be 39, but if i play this rule? it does not work. I have checked first byte_math whose save var “offset_parameter_length” and have checked byte_extract whose save var “result_extract”. The values of their variables are the same as what I calculated (17 and 12 accordingly). But when i calculate their in second byte_math, whose save var “offset_error”, i don’t get the 39 value.
I apologize if I’m not asking the questions correctly enough. Thank you so much for your answers!