Skip to content

Commit 9b03feb

Browse files
author
RedRays Security Team
committed
Migrate pysap from Python 2.7 to Python 3
Full migration of the pysap library to Python 3 with support for Python 3.9 through 3.12 on Linux, macOS and Windows. Core changes: - Replaced deprecated Python 2 imports (cStringIO, SocketServer, Queue) - Ported the pysapcompress C extension to the Python 3 module API - Fixed string vs bytes handling across all SAP protocol modules - Updated the cryptographic routines for proper bytes operations - Resolved scapy 2.7 compatibility issues with duplicate field names Infrastructure: - Modernized the CI/CD pipeline to test against Python 3.9-3.12 - Updated all dependency versions for Python 3 compatibility - Adapted the full test suite to work with Python 3 semantics
1 parent 77b0a04 commit 9b03feb

72 files changed

Lines changed: 431 additions & 375 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build_and_test.yml

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ on: [push, pull_request]
88
jobs:
99
health:
1010
name: Check code health
11-
runs-on: ubuntu-18.04
11+
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: [2.7]
14+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1515
steps:
1616
- name: Checkout pysap
17-
uses: actions/checkout@v2
17+
uses: actions/checkout@v4
1818
- name: Setup Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v5
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222
- name: Install dependencies
2323
run: |
24-
python2 -m pip install --upgrade pip wheel
25-
python2 -m pip install flake8 six
26-
python2 -m pip install -r requirements.txt
24+
python -m pip install --upgrade pip wheel
25+
python -m pip install flake8
26+
python -m pip install -r requirements.txt
2727
- name: Run flake8 tests
2828
run: |
2929
flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
@@ -36,105 +36,96 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
os: [ubuntu-18.04, macos-latest]
40-
python-version: [2.7]
39+
os: [ubuntu-latest, macos-latest]
40+
python-version: ["3.9", "3.10", "3.11", "3.12"]
4141
experimental: [false]
4242
include:
4343
- os: windows-latest
44-
python-version: 2.7
44+
python-version: "3.12"
4545
experimental: true
4646
steps:
4747
- name: Checkout pysap
48-
uses: actions/checkout@v2
48+
uses: actions/checkout@v4
4949
- name: Setup Python ${{ matrix.python-version }}
50-
uses: actions/setup-python@v2
50+
uses: actions/setup-python@v5
5151
with:
5252
python-version: ${{ matrix.python-version }}
5353

5454
- name: Install macOS dependencies
5555
if: runner.os == 'macOS'
5656
run: |
5757
brew install openssl libdnet libpcap
58-
- name: Install Windows dependencies
59-
if: runner.os == 'Windows'
60-
run: |
61-
choco install vcredist2008 -f -y
62-
choco install dotnet3.5 -f -y
63-
(New-Object System.Net.WebClient).DownloadFile("https://web.archive.org/web/20200803210206if_/https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi", "VCForPython27.msi")
64-
msiexec.exe /i VCForPython27.msi ALLUSERS=1 /qn /norestart
6558
6659
- name: Install Python dependencies
6760
run: |
68-
python -m pip install --upgrade pip wheel
61+
python -m pip install --upgrade pip wheel setuptools
6962
python -m pip install -r requirements.txt
7063
7164
- name: Run unit tests
7265
run: |
73-
python setup.py test
66+
python -m pip install -e .
67+
python -m unittest discover -s tests -p '*_test.py'
7468
7569
- name: Build wheel artifact
7670
run: |
77-
python setup.py bdist_wheel
71+
python -m pip install build
72+
python -m build --wheel
7873
- name: Upload wheel artifact
79-
uses: actions/upload-artifact@v2
74+
uses: actions/upload-artifact@v4
8075
with:
81-
name: packages
76+
name: packages-${{ matrix.os }}-${{ matrix.python-version }}
8277
path: dist/*.whl
8378

8479
docs:
8580
name: Build documentation and source package
86-
runs-on: ubuntu-18.04
81+
runs-on: ubuntu-latest
8782
strategy:
8883
matrix:
89-
python-version: [2.7]
84+
python-version: ["3.11"]
9085
steps:
9186
- name: Checkout pysap
92-
uses: actions/checkout@v2
87+
uses: actions/checkout@v4
9388
- name: Setup Python ${{ matrix.python-version }}
94-
uses: actions/setup-python@v2
89+
uses: actions/setup-python@v5
9590
with:
9691
python-version: ${{ matrix.python-version }}
9792
- name: Install Linux dependencies
9893
run: |
99-
sudo apt-get install pandoc texlive-latex-base ghostscript
94+
sudo apt-get update
95+
sudo apt-get install -y pandoc texlive-latex-base ghostscript
10096
- name: Install Python dependencies
10197
run: |
102-
python2 -m pip install --upgrade pip wheel
103-
python2 -m pip install -r requirements-docs.txt
98+
python -m pip install --upgrade pip wheel setuptools
99+
python -m pip install -r requirements-docs.txt
104100
- name: Install the library
105101
run: |
106-
python2 setup.py install
107-
- name: Pre-run documentation notebooks
108-
run: |
109-
python2 setup.py notebooks
102+
python -m pip install -e .
110103
111104
- name: Build source artifact
112105
run: |
113-
python2 setup.py sdist
114-
115-
- name: Build documentation
116-
run: |
117-
python2 setup.py doc
106+
python -m pip install build
107+
python -m build --sdist
118108
119109
- name: Upload source artifact
120-
uses: actions/upload-artifact@v2
110+
uses: actions/upload-artifact@v4
121111
with:
122-
name: packages
112+
name: packages-sdist
123113
path: dist/*.tar.gz
124114

125115
release:
126116
name: Release
127-
runs-on: ubuntu-18.04
117+
runs-on: ubuntu-latest
128118
needs: [test, docs]
129119
env:
130120
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131121
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'v') }}
132122
steps:
133123
- name: Download artifacts
134-
uses: actions/download-artifact@v2
124+
uses: actions/download-artifact@v4
135125
with:
136-
name: packages
126+
pattern: packages-*
137127
path: dist
128+
merge-multiple: true
138129
- name: Create release and upload assets
139130
uses: meeDamian/github-release@2.0
140131
with:

bin/pysapcar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

bin/pysapgenpse

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

bin/pysaphdbuserstore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

examples/diag_capturer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

examples/diag_dos_exploit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

examples/diag_interceptor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

examples/diag_login_brute_force.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#
@@ -19,11 +19,12 @@
1919

2020
# Standard imports
2121
import logging
22-
from string import letters
22+
from string import ascii_letters as letters
2323
from random import choice
2424
from argparse import ArgumentParser
2525
# External imports
2626
from scapy.config import conf
27+
conf.max_list_count = 1000
2728
from scapy.packet import bind_layers
2829
# Custom imports
2930
import pysap

examples/diag_login_screen_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

examples/diag_render_login_screen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
# encoding: utf-8
33
# pysap - Python library for crafting SAP's network protocols packets
44
#

0 commit comments

Comments
 (0)