The Snap7 Server (server.exe from the provided examples) is crashing when the ItemCount field of the ReadVariable, ReadVariableMultiple, WriteVariable or WriteVariableMultiple is provided with unexpected values.
For example the value of 0x76 provided to the WriteVariable function will lead to the following exception:
Similarly, providing unexpected value to the ReadVariable function will lead to: "caused access violation when attempting to read from 0x00000000".
What is the reason for those exceptions? The memory address is aways 0x00000000, which is within the Null pointer assignment partition, therefore it sounds like a NullPointer exception.
Last edit: Martin T 2017-05-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using a packet manupulator called Scapy as a client. It create custom packets, which I then excute towards the Snap7 server. Only seen this happen for ItemCount.
Here is a sample Scapy script, which will crash the server. I run the script from a remote Lubuntu machine, while the Snap7 server is running on 192.168.0.9 under Windows 10.
You can repoduce this by installing Scapy and running the script (adjust the IP accordingly):
#!/usr/local/bin/pythonfromscapy.allimport*mysocket=socket.socket()mysocket.connect(("192.168.0.9",102))mystream=StreamSocket(mysocket)print"TPKT/COTP Connect confirm"mystream.send(Raw('\x03\x00\x00\x16\x11\xe0\x00\x00\x00\x01\x00\xc0\x01\x0a\xc1\x02\x01\x00\xc2\x02\x01\x02'))print"TPKT/COTP/S7 setup communication"mystream.send(Raw('\x03\x00\x00\x19\x02\xf0\x80\x32\x01\x00\x00\x00\x00\x00\x08\x00\x00\xf0\x00\x00\x01\x00\x01\x01\xe0'))whileTrue:print"TPKT/COTP/S7 Write Variable with \x76, instead of \x01 as ItemCount"mystream.send(Raw('\x03\x00\x00\x24\x02\xf0\x80\x32\x01\x00\x00\x05\x00\x00\x0e\x00\x05\x05\x76\x12\x0a\x10\x02\x00\x01\x00\x01\x84\x00\x00\x00\x00\x04\x00\x08\x00'))mysocket.close()
Martin,
TS7Worker::PerformFunctionRead() and TS7Worker::PerformFunctionWrite() check that ItemCount is not greater than MaxVars (20).
After that it expects "ItemCount" well formatted records from which get info about the variables that must be read or write.
Checking that the following memory contains valid data or rubbish is not so simple.
Snap7Server is meant to be used with "standard" partners (commercial HMI, OPC...).
If you need that your application must be shielded against selfmade packets you can introduce further checks (but, i repeat, is very hard to do with the structure of S7Protocol) into TS7Worker::PerformFunctionRead() and TS7Worker::PerformFunctionWrite().
You can find them into s7_server.cpp.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
OS: Windows 10 32bit
Snap7 version: 1.4.1
The Snap7 Server (server.exe from the provided examples) is crashing when the ItemCount field of the ReadVariable, ReadVariableMultiple, WriteVariable or WriteVariableMultiple is provided with unexpected values.
For example the value of 0x76 provided to the WriteVariable function will lead to the following exception:
Similarly, providing unexpected value to the ReadVariable function will lead to: "caused access violation when attempting to read from 0x00000000".
What is the reason for those exceptions? The memory address is aways 0x00000000, which is within the Null pointer assignment partition, therefore it sounds like a NullPointer exception.
Last edit: Martin T 2017-05-13
Hi,
could you provide an example so I can reproduce the problem ?
Are you using Snap7 as client too ?
This happens only for Itemcount ?
I am using a packet manupulator called Scapy as a client. It create custom packets, which I then excute towards the Snap7 server. Only seen this happen for ItemCount.
Here is a sample Scapy script, which will crash the server. I run the script from a remote Lubuntu machine, while the Snap7 server is running on 192.168.0.9 under Windows 10.
You can repoduce this by installing Scapy and running the script (adjust the IP accordingly):
Scapy script:
Last edit: Martin T 2017-05-14
Martin,
TS7Worker::PerformFunctionRead() and TS7Worker::PerformFunctionWrite() check that ItemCount is not greater than MaxVars (20).
After that it expects "ItemCount" well formatted records from which get info about the variables that must be read or write.
Checking that the following memory contains valid data or rubbish is not so simple.
Snap7Server is meant to be used with "standard" partners (commercial HMI, OPC...).
If you need that your application must be shielded against selfmade packets you can introduce further checks (but, i repeat, is very hard to do with the structure of S7Protocol) into TS7Worker::PerformFunctionRead() and TS7Worker::PerformFunctionWrite().
You can find them into s7_server.cpp.