Skip to content

Commit

Permalink
Initial commit to mimic Siemens S7 communication
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Niedermaier committed Feb 7, 2025
1 parent 971aff7 commit fd5a7f6
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .devcontainer/virtual/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ services:
depends_on:
- openplc

s7com:
image: mniedermaier1337/cybicss7comlatest
build:
context: ../../software/s7com
dockerfile: Dockerfile
restart: always
ports:
- 102:102
depends_on:
- openplc

fuxa:
image: mniedermaier1337/cybicsfuxa:latest
build:
Expand Down
1 change: 1 addition & 0 deletions software/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ docker buildx inspect --bootstrap
docker buildx build --platform linux/arm64 -t 172.17.0.1:5000/cybics-hwio-raspberry:latest --push ./hwio-raspberry
docker buildx build --platform linux/arm64 -t 172.17.0.1:5000/cybics-openplc:latest --push ./OpenPLC
docker buildx build --platform linux/arm64 -t 172.17.0.1:5000/cybics-opcua:latest --push ./opcua
docker buildx build --platform linux/arm64 -t 172.17.0.1:5000/cybics-s7com:latest --push ./s7com
docker buildx build --platform linux/arm64 -t 172.17.0.1:5000/cybics-fuxa:latest --push ./FUXA
docker buildx build --platform linux/arm64 -t 172.17.0.1:5000/cybics-stm32:latest --push ./stm32
10 changes: 10 additions & 0 deletions software/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ services:
networks:
- br-cybics

s7com:
image: localhost:5000/cybics-s7com:latest
depends_on:
- openplc
restart: always
ports:
- 102:102
networks:
- br-cybics

openplc:
image: localhost:5000/cybics-openplc:latest
restart: always
Expand Down
12 changes: 12 additions & 0 deletions software/s7com/Dockerfile
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" ]
1 change: 1 addition & 0 deletions software/s7com/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-snap7
42 changes: 42 additions & 0 deletions software/s7com/s7com.py
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()

0 comments on commit fd5a7f6

Please sign in to comment.