Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Cross-Platform Build

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
architecture: [x64]
include:
- os: ubuntu-latest
architecture: x64
makefile: build/unix/x86_64_linux.mk
target: libsnap7.so
- os: windows-latest
architecture: x64
makefile: build/windows/MinGW64/Makefile
target: snap7.dll
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up build environment (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential

- name: Set up build environment (Windows)
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-binutils make

- name: Build (Linux)
if: runner.os == 'Linux'
working-directory: ${{ github.workspace }}
run: |
make -f ${{ matrix.makefile }}
ls -la build/bin/x86_64-linux/

- name: Build (Windows)
if: runner.os == 'Windows'
working-directory: ${{ github.workspace }}/build/windows/MinGW64
shell: msys2 {0}
run: |
make
ls -la ../../bin/Legacy/win64/

- name: Upload Linux artifact
if: runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: snap7-linux-x64
path: build/bin/x86_64-linux/libsnap7.so

- name: Upload Windows artifact
if: runner.os == 'Windows'
uses: actions/upload-artifact@v4
with:
name: snap7-windows-x64
path: build/bin/Legacy/win64/snap7.dll
37 changes: 37 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build projects with Make

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
architecture: [x64]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up build environment (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential

- name: Set up build environment (Windows)
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-binutils make

- name: Build
run: |
cd build
make
69 changes: 69 additions & 0 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Smoke Test

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
smoke-test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
architecture: [x64]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up build environment (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential

- name: Set up build environment (Windows)
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-binutils make

- name: Build library (Linux)
if: runner.os == 'Linux'
working-directory: ${{ github.workspace }}
run: make -f build/unix/x86_64_linux.mk

- name: Build library (Windows)
if: runner.os == 'Windows'
working-directory: ${{ github.workspace }}/build/windows/MinGW64
shell: msys2 {0}
run: make

- name: Build loopback test (Linux)
if: runner.os == 'Linux'
working-directory: ${{ github.workspace }}/examples/cpp/x86_64-linux
run: make loopback_test

- name: Build loopback test (Windows)
if: runner.os == 'Windows'
working-directory: ${{ github.workspace }}/examples/cpp/x86_64-linux
shell: msys2 {0}
run: make loopback_test

- name: Run Linux loopback test
if: runner.os == 'Linux'
working-directory: ${{ github.workspace }}/examples/cpp/x86_64-linux
run: |
# Start test in background and give it time to run
timeout 60 ./loopback_test

- name: Run Windows loopback test
if: runner.os == 'Windows'
working-directory: ${{ github.workspace }}/examples/cpp/x86_64-linux
shell: msys2 {0}
run: |
# Start test and give it time to run
timeout 60 ./loopback_test.exe
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,35 @@ For more details I refer to the commit history.
Please note that this fork is currently at version 1.4.0.

Cleanup, more fixes and documentation will follow.

## License

This repository includes the applicable license texts in the repository root:

- [GPL license text](gpl.txt)
- [LGPL v3.0 license text](lgpl-3.0.txt)

Please review the applicable license terms before using, modifying,
or redistributing this software.

## Fork Status

This repository is a community-maintained fork of
[SCADACS/snap7](https://github.com/SCADACS/snap7).

The original Snap7 project and its contributors retain credit for the
upstream codebase. This fork adds independently maintained documentation,
build, testing, security, and integration improvements.

See the repository history and license texts for applicable notices.

## Security

For security considerations when deploying Snap7 in industrial environments,
see [SECURITY.md](SECURITY.md), [docs/secure-deployment.md](docs/secure-deployment.md),
and [docs/industrial-networking.md](docs/industrial-networking.md).

## Continuous Integration

This project includes GitHub Actions workflows for cross-platform builds
and automated smoke tests on Linux and Windows.
13 changes: 13 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Security Policy

## Reporting a Vulnerability

Please avoid publishing suspected security vulnerabilities in public issue trackers before maintainers have had an opportunity to assess them.

When a private reporting channel is available, use that channel and include:

- A clear description of the issue
- Affected versions or commits
- Steps to reproduce the issue
- Potential impact
- Any proposed mitigation, if available
49 changes: 49 additions & 0 deletions docs/industrial-networking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Industrial Networking Guidance

This document provides guidance on network architecture and communication patterns when using Snap7 in industrial environments.

## Network Segmentation

Industrial control systems should be separated from enterprise IT networks using:

- **DMZ / Industrial DMZ**: A controlled boundary between IT and OT networks
- **Firewalls**: Stateful inspection firewalls with rules allowing only necessary protocols and ports
- **VLANs**: Logical separation of traffic types (e.g., HMI, historian, engineering, safety)
- **Unidirectional Gateways (Data Diodes)**: For high-security environments requiring data flow from OT to IT only

## Communication Protocols

Snap7 uses the Siemens S7 protocol over ISO-on-TCP (RFC 1006) typically on port 102. Consider:

- Restricting port 102 access to authorized engineering stations only
- Using non-standard ports where possible to reduce automated scanning
- Implementing port knocking or SPA (Single Packet Authorization) for additional obscurity

## Redundancy and Availability

- Design network paths with redundancy for critical communication
- Implement monitoring for communication loss and latency anomalies
- Consider PLC-side communication load when multiple clients connect
- Use Snap7's connection management features to handle reconnections gracefully

## Monitoring and Logging

- Log all connection attempts (successful and failed)
- Monitor for unusual traffic patterns or unexpected PLC commands
- Correlate network logs with PLC diagnostic buffers
- Set up alerts for communication failures on critical assets

## Remote Access

If remote access is required:

- Use a dedicated VPN with multi-factor authentication
- Implement jump hosts / bastion hosts for engineering access
- Record and audit all remote sessions
- Enforce time-limited access with automatic revocation

## References

- IEC 62443 Series - Industrial communication network security
- NIST SP 800-82 - Guide to Industrial Control Systems Security
- ISA/IEC 62443-3-3 - System security requirements and security levels
29 changes: 29 additions & 0 deletions docs/secure-deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Secure Deployment Guide

This guide provides security-focused deployment recommendations for systems using Snap7 to communicate with Siemens S7 PLCs.

## Network Architecture

- PLCs should not be exposed directly to the internet.
- Use network segmentation and firewall rules to isolate OT networks from IT networks.
- Use VPN or controlled remote-access mechanisms for remote engineering access.
- Limit access to authorized engineering and service networks only.
- Use least-privilege access where supported by the PLC and network infrastructure.

## Operational Security

- Treat PLC write operations as high-risk actions.
- Separate development/test devices from production assets.
- Log, monitor, and review communication failures and unexpected commands.
- Implement change management procedures for any modifications to PLC programs or configuration.

## Important Limitations

Snap7 is not a substitute for OT network architecture and operational security controls. It provides communication capabilities but does not implement:

- Network-level authentication or encryption (relies on underlying transport)
- Industrial firewall or intrusion detection
- Safety system functions
- Compliance with specific industrial security standards (e.g., IEC 62443)

These controls must be implemented at the network and system architecture level.
Loading