Skip to content

Commit

Permalink
Starting with 0.2.x branch for Python 3 (#53)
Browse files Browse the repository at this point in the history
- Bumping Cryptography to 3.3.2
- Moved to scapy 2.4.5
- Fixed unit test module names
- Added pytest to test requirements
- Basic 2 to 3 syntax fixes
- Moved pysapcompress module to Python 3
- Simplifying unit test modules
- Added Tox config
- Arranged GitHub actions to run tox with gh-actions
  • Loading branch information
martingalloar committed Mar 20, 2023
1 parent a6c80e5 commit caaaf6a
Show file tree
Hide file tree
Showing 30 changed files with 194 additions and 251 deletions.
89 changes: 46 additions & 43 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,70 @@ on: [push, pull_request]
jobs:
health:
name: Check code health
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: [2.7]
runs-on: ubuntu-latest
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository

steps:
- name: Checkout pysap
uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}

- name: Setup Python 3.10
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
python-version: "3.10"

- name: Install Python dependencies
run: |
python -m pip install flake8
- name: Check syntax errors
run: |
python2 -m pip install --upgrade pip wheel
python2 -m pip install flake8 six
python2 -m pip install -r requirements.txt
- name: Run flake8 tests
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Check PEP8 warnings
run: |
flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
flake8 . --count --ignore=E501 --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --ignore=E1,E2,E3,E501,W291,W293 --exit-zero --max-complexity=65 --max-line-length=127 --statistics
test:
name: Run unit tests and build wheel
needs: health
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository

strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, macos-latest]
python-version: [2.7]
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
experimental: [false]
include:
- os: windows-latest
python-version: 2.7
experimental: true
continue-on-error: ${{ matrix.experimental }}

steps:
- name: Checkout pysap
uses: actions/checkout@v2

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install macOS dependencies
if: runner.os == 'macOS'
run: |
brew install openssl libdnet libpcap
- name: Install Windows dependencies
if: runner.os == 'Windows'
run: |
choco install vcredist2008 -f -y
choco install dotnet3.5 -f -y
(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")
msiexec.exe /i VCForPython27.msi ALLUSERS=1 /qn /norestart
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip wheel
python -m pip install -r requirements.txt
python -m pip install tox tox-gh-actions -r requirements.txt -r requirements-test.txt
- name: Run unit tests
run: |
python setup.py test
tox
- name: Build wheel artifact
run: |
python setup.py bdist_wheel
- name: Upload wheel artifact
uses: actions/upload-artifact@v2
with:
Expand All @@ -83,38 +80,44 @@ jobs:

docs:
name: Build documentation and source package
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7]
python-version: ["3.10"]

steps:
- name: Checkout pysap
uses: actions/checkout@v2

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Linux dependencies
run: |
sudo apt-get install pandoc texlive-latex-base ghostscript
- name: Install Python dependencies
run: |
python2 -m pip install --upgrade pip wheel
python2 -m pip install -r requirements-docs.txt
python -m pip install --upgrade pip wheel
python -m pip install -r requirements-docs.txt
- name: Install the library
run: |
python2 setup.py install
python setup.py install
- name: Pre-run documentation notebooks
run: |
python2 setup.py notebooks
python setup.py notebooks
- name: Build source artifact
run: |
python2 setup.py sdist
python setup.py sdist
- name: Build documentation
run: |
python2 setup.py doc
python setup.py doc
- name: Upload source artifact
uses: actions/upload-artifact@v2
Expand All @@ -124,7 +127,7 @@ jobs:

release:
name: Release
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
needs: [test, docs]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion examples/diag_login_brute_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def is_duplicate_login(response):
for item in response[SAPDiag].get_item("APPL4", "DYNT", "DYNT_ATOM"):
if item.item_value:
for atom in item.item_value.items:
if atom.dlg_flag_1 is 0 and atom.dlg_flag_2 is 0 and atom.field2_text:
if atom.dlg_flag_1 == 0 and atom.dlg_flag_2 == 0 and atom.field2_text:
if "is already logged on in" in atom.field2_text:
return True, atom.field2_text
return False, ""
Expand Down
50 changes: 25 additions & 25 deletions examples/diag_rogue_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,35 @@ def make_login_screen(self):
SAPDiagItem(item_value='SAPMSYST ', item_type=16, item_id=6, item_sid=13),
SAPDiagItem(item_value='0020 ', item_type=16, item_id=6, item_sid=16),
SAPDiagItem(item_value='0020', item_type=16, item_id=6, item_sid=14),
SAPDiagItem(item_value=SAPDiagMenuEntries(entries=[SAPDiagMenuEntry(accelerator='D', text=self.session_title, position_1=1, flag_TERM_VKEY=1L, return_code_1=1, flag_TERM_SEL=1L, length=24 + len(self.session_title)),
SAPDiagItem(item_value=SAPDiagMenuEntries(entries=[SAPDiagMenuEntry(accelerator='D', text=self.session_title, position_1=1, flag_TERM_VKEY=1, return_code_1=1, flag_TERM_SEL=1, length=24 + len(self.session_title)),
]), item_type=18, item_id=11, item_sid=1),
SAPDiagItem(item_value=SAPDiagMenuEntries(entries=[SAPDiagMenuEntry(accelerator='', text='New password', virtual_key=5, return_code_1=5, info='New password', flag_TERM_SEL=1L, length=47),
SAPDiagItem(item_value=SAPDiagMenuEntries(entries=[SAPDiagMenuEntry(accelerator='', text='New password', virtual_key=5, return_code_1=5, info='New password', flag_TERM_SEL=1, length=47),
]), item_type=18, item_id=11, item_sid=3),
SAPDiagItem(item_value=SAPDiagMenuEntries(entries=[SAPDiagMenuEntry(accelerator='', text='New password', virtual_key=5, position_1=1, flag_TERM_SEL=1L, length=35),
SAPDiagMenuEntry(accelerator='', text='Log off', virtual_key=15, position_1=2, return_code_1=1, flag_TERM_SEL=1L, length=30)
SAPDiagItem(item_value=SAPDiagMenuEntries(entries=[SAPDiagMenuEntry(accelerator='', text='New password', virtual_key=5, position_1=1, flag_TERM_SEL=1, length=35),
SAPDiagMenuEntry(accelerator='', text='Log off', virtual_key=15, position_1=2, return_code_1=1, flag_TERM_SEL=1, length=30)
]), item_type=18, item_id=11, item_sid=4),
SAPDiagItem(item_value=self.session_title, item_type=16, item_id=12, item_sid=9),
SAPDiagItem(item_value=SAPDiagDyntAtom(items=[SAPDiagDyntAtomItem(field2_text='Client ', field2_maxnrchars=18, dlg_flag_2=2, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1L, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(dlg_flag_2=2, atom_length=24, name_text='RSYST-MANDT', etype=114, attr_DIAG_BSD_PROTECTED=1L, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(field2_text=self.client, attr_DIAG_BSD_YES3D=1L, field2_maxnrchars=3, atom_length=22, etype=130, field2_mlen=3, field2_dlen=3, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1L, atom_length=24, name_text='RSYST-MANDT', etype=114, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1L, atom_length=79, xmlprop_text='<Propertybag><DefaultTooltip>Client</DefaultTooltip></Propertybag>', etype=120, block=1, col=20),
SAPDiagDyntAtomItem(field2_text='User ', field2_maxnrchars=18, row=2, dlg_flag_2=3, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1L, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(row=2, dlg_flag_2=3, atom_length=24, name_text='RSYST-BNAME', etype=114, attr_DIAG_BSD_PROTECTED=1L, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(field2_text='? ', attr_DIAG_BSD_YES3D=1L, field2_maxnrchars=12, row=2, dlg_flag_2=1, atom_length=31, etype=130, field2_mlen=12, field2_dlen=12, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1L, row=2, dlg_flag_2=1, atom_length=24, name_text='RSYST-BNAME', etype=114, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1L, row=2, dlg_flag_2=1, atom_length=82, xmlprop_text='<Propertybag><DefaultTooltip>User name</DefaultTooltip></Propertybag>', etype=120, block=1, col=20),
SAPDiagDyntAtomItem(field2_text='@\\QUp to 40 Chars (Case-Sens.)@Password ', field2_maxnrchars=52, row=3, dlg_flag_2=3, dlg_flag_1=4, atom_length=71, etype=132, attr_DIAG_BSD_PROTECTED=1L, field2_mlen=18, field2_dlen=52, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(row=3, dlg_flag_2=3, dlg_flag_1=4, atom_length=24, name_text='RSYST-BCODE', etype=114, attr_DIAG_BSD_PROTECTED=1L, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(field2_text='? ', attr_DIAG_BSD_YES3D=1L, field2_maxnrchars=40, row=3, dlg_flag_2=1, dlg_flag_1=4, atom_length=59, etype=130, attr_DIAG_BSD_INVISIBLE=1L, field2_mlen=12, field2_dlen=40, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1L, row=3, dlg_flag_2=1, dlg_flag_1=4, atom_length=24, name_text='RSYST-BCODE', etype=114, attr_DIAG_BSD_INVISIBLE=1L, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1L, row=3, dlg_flag_2=1, dlg_flag_1=4, atom_length=86, xmlprop_text='<Propertybag><DefaultTooltip>User password</DefaultTooltip></Propertybag>', etype=120, attr_DIAG_BSD_INVISIBLE=1L, block=1, col=20),
SAPDiagDyntAtomItem(field2_text='Language ', field2_maxnrchars=18, row=5, dlg_flag_2=2, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1L, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(row=5, dlg_flag_2=2, atom_length=24, name_text='RSYST-LANGU', etype=114, attr_DIAG_BSD_PROTECTED=1L, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagDyntAtomItem(field2_text=' ', attr_DIAG_BSD_YES3D=1L, field2_maxnrchars=2, row=5, atom_length=21, etype=130, field2_mlen=2, field2_dlen=2, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1L, row=5, atom_length=24, name_text='RSYST-LANGU', etype=114, block=1, col=20),
SAPDiagDyntAtomItem(atom_length=81, attr_DIAG_BSD_YES3D=1L, xmlprop_text='<Propertybag><DefaultTooltip>Language</DefaultTooltip></Propertybag>', etype=120, col=20, block=1, row=5),
SAPDiagDyntAtomItem(field2_text=self.session_title, field2_maxnrchars=18, row=7, dlg_flag_2=2, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1L, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1L, block=1, col=1),
SAPDiagItem(item_value=SAPDiagDyntAtom(items=[SAPDiagDyntAtomItem(field2_text='Client ', field2_maxnrchars=18, dlg_flag_2=2, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(dlg_flag_2=2, atom_length=24, name_text='RSYST-MANDT', etype=114, attr_DIAG_BSD_PROTECTED=1, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(field2_text=self.client, attr_DIAG_BSD_YES3D=1, field2_maxnrchars=3, atom_length=22, etype=130, field2_mlen=3, field2_dlen=3, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1, atom_length=24, name_text='RSYST-MANDT', etype=114, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1, atom_length=79, xmlprop_text='<Propertybag><DefaultTooltip>Client</DefaultTooltip></Propertybag>', etype=120, block=1, col=20),
SAPDiagDyntAtomItem(field2_text='User ', field2_maxnrchars=18, row=2, dlg_flag_2=3, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(row=2, dlg_flag_2=3, atom_length=24, name_text='RSYST-BNAME', etype=114, attr_DIAG_BSD_PROTECTED=1, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(field2_text='? ', attr_DIAG_BSD_YES3D=1, field2_maxnrchars=12, row=2, dlg_flag_2=1, atom_length=31, etype=130, field2_mlen=12, field2_dlen=12, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1, row=2, dlg_flag_2=1, atom_length=24, name_text='RSYST-BNAME', etype=114, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1, row=2, dlg_flag_2=1, atom_length=82, xmlprop_text='<Propertybag><DefaultTooltip>User name</DefaultTooltip></Propertybag>', etype=120, block=1, col=20),
SAPDiagDyntAtomItem(field2_text='@\\QUp to 40 Chars (Case-Sens.)@Password ', field2_maxnrchars=52, row=3, dlg_flag_2=3, dlg_flag_1=4, atom_length=71, etype=132, attr_DIAG_BSD_PROTECTED=1, field2_mlen=18, field2_dlen=52, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(row=3, dlg_flag_2=3, dlg_flag_1=4, atom_length=24, name_text='RSYST-BCODE', etype=114, attr_DIAG_BSD_PROTECTED=1, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(field2_text='? ', attr_DIAG_BSD_YES3D=1, field2_maxnrchars=40, row=3, dlg_flag_2=1, dlg_flag_1=4, atom_length=59, etype=130, attr_DIAG_BSD_INVISIBLE=1, field2_mlen=12, field2_dlen=40, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1, row=3, dlg_flag_2=1, dlg_flag_1=4, atom_length=24, name_text='RSYST-BCODE', etype=114, attr_DIAG_BSD_INVISIBLE=1, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1, row=3, dlg_flag_2=1, dlg_flag_1=4, atom_length=86, xmlprop_text='<Propertybag><DefaultTooltip>User password</DefaultTooltip></Propertybag>', etype=120, attr_DIAG_BSD_INVISIBLE=1, block=1, col=20),
SAPDiagDyntAtomItem(field2_text='Language ', field2_maxnrchars=18, row=5, dlg_flag_2=2, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(row=5, dlg_flag_2=2, atom_length=24, name_text='RSYST-LANGU', etype=114, attr_DIAG_BSD_PROTECTED=1, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
SAPDiagDyntAtomItem(field2_text=' ', attr_DIAG_BSD_YES3D=1, field2_maxnrchars=2, row=5, atom_length=21, etype=130, field2_mlen=2, field2_dlen=2, block=1, col=20),
SAPDiagDyntAtomItem(attr_DIAG_BSD_YES3D=1, row=5, atom_length=24, name_text='RSYST-LANGU', etype=114, block=1, col=20),
SAPDiagDyntAtomItem(atom_length=81, attr_DIAG_BSD_YES3D=1, xmlprop_text='<Propertybag><DefaultTooltip>Language</DefaultTooltip></Propertybag>', etype=120, col=20, block=1, row=5),
SAPDiagDyntAtomItem(field2_text=self.session_title, field2_maxnrchars=18, row=7, dlg_flag_2=2, atom_length=37, etype=132, attr_DIAG_BSD_PROTECTED=1, field2_mlen=18, field2_dlen=18, attr_DIAG_BSD_PROPFONT=1, block=1, col=1),
]), item_type=18, item_id=9, item_sid=2),
]

Expand Down
2 changes: 1 addition & 1 deletion examples/dlmanager_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def parse_config_file(filename, decrypt=False, serial_number=None):
print("[*] Read %d config values from config file" % len(data))
for item in data:
value = ""
if isinstance(data[item], basestring):
if isinstance(data[item], str):
value = data[item]
elif "value" in data[item]:
value = data[item]["value"]
Expand Down
8 changes: 4 additions & 4 deletions pysap/SAPCAR.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from struct import pack
from datetime import datetime
from os import stat as os_stat
from cStringIO import StringIO
from io import StringIO
# External imports
from scapy.packet import Packet
from scapy.fields import (ByteField, ByteEnumField, LEIntField, FieldLenField,
Expand Down Expand Up @@ -674,7 +674,7 @@ def __init__(self, fil, mode="rb+", version=SAPCAR_VERSION_201):
if "b" not in mode:
mode += "b"

if isinstance(fil, (basestring, unicode)):
if isinstance(fil, str):
self.filename = fil
self.fd = open(fil, mode)
else:
Expand Down Expand Up @@ -707,7 +707,7 @@ def files_names(self):
:return: list of file names
:rtype: L{list} of L{string}
"""
return self.files.keys()
return list(self.files.keys())

@property
def version(self):
Expand All @@ -731,7 +731,7 @@ def version(self, version):
# If version is different, we should convert each file
if version != self._sapcar.version:
fils = []
for fil in self.files.values():
for fil in list(self.files.values()):
new_file = SAPCARArchiveFile.from_archive_file(fil, version=version)
fils.append(new_file._file_format)
self._files.remove(fil._file_format)
Expand Down

0 comments on commit caaaf6a

Please sign in to comment.