-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit to mimic Siemens S7 communication
- Loading branch information
Matthias Niedermaier
committed
Feb 7, 2025
1 parent
971aff7
commit fd5a7f6
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3-slim | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
network-manager \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /CybICS | ||
COPY requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
COPY s7com.py ./ | ||
|
||
CMD [ "python", "./s7com.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-snap7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import snap7 | ||
import socket | ||
import time | ||
import ctypes | ||
import logging | ||
|
||
# Configure logging | ||
format="%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s" | ||
logging.basicConfig(format=format, level=logging.INFO, | ||
datefmt="%H:%M:%S") | ||
|
||
# Initialize Snap7 Server | ||
server = snap7.server.Server() | ||
|
||
def start_s7_fake_server(): | ||
""" | ||
Start a fake Siemens S7 PLC server that listens on TCP port 102. | ||
This allows detection by nmap with --script s7-info. | ||
""" | ||
try: | ||
size = 100 | ||
db_data: CDataArrayType = (snap7.WordLen.Byte.ctype * size)() | ||
|
||
# Register fake data block | ||
server.register_area(snap7.SrvArea.DB, 1, db_data) | ||
|
||
# Start server listening on all interfaces (port 102) | ||
server.start_to("0.0.0.0") | ||
logging.info("Fake Siemens S7 PLC started on port 102...") | ||
|
||
while True: | ||
time.sleep(1) # Keep the server running | ||
|
||
except KeyboardInterrupt: | ||
logging.info("Stopping fake S7 server...") | ||
server.stop() | ||
server.destroy() | ||
except Exception as e: | ||
logging.error(f"Error: {e}", exc_info=True) | ||
|
||
if __name__ == "__main__": | ||
start_s7_fake_server() |