Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding Github workflows #21

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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
15 changes: 15 additions & 0 deletions .github/workflows/auto-assign-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# .github/workflows/auto-author-assign.yml
name: 'Auto Author Assign'

on:
pull_request_target:
types: [opened, reopened]

permissions:
pull-requests: write

jobs:
assign-author:
runs-on: ubuntu-latest
steps:
- uses: toshimaru/[email protected]
37 changes: 37 additions & 0 deletions .github/workflows/pre-commit-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: precommit-actions
run-name: ${{ github.actor }} is running precommit actions.
on:
push:
branches-ignore: [main]
pull_request:
branches: [main]
jobs:
build:
name: Lint
runs-on: ubuntu-latest
Patterbear marked this conversation as resolved.
Show resolved Hide resolved

permissions:
contents: read
packages: read
# To report GitHub Actions status checks
statuses: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# super-linter needs the full git history to get the
# list of files that changed across commits
fetch-depth: 0

- name: Super-linter
uses: super-linter/[email protected] # x-release-please-version
env:
DEFAULT_BRANCH: main
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IGNORE_GITIGNORED_FILES: true
VALIDATE_ALL_CODEBASE: true
VALIDATE_PYTHON_FLAKE8: true
VALIDATE_HTML: true
FILTER_REGEX_EXCLUDE: '^tests/test_files/'
32 changes: 32 additions & 0 deletions .github/workflows/semantic-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Semantic PRs"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# first type as the one from https://github.com/commitizen/conventional-commit-types/blob/master/index.json
# l10n (localization) is for translations updates
types: |
feat
fix
docs
style
refactor
test
build
ci
chore
revert
l10n
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
rothoma2 marked this conversation as resolved.
Show resolved Hide resolved
#.idea/
.idea/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

A command-line tool designed to detect and purge any and all macros and dynamic content from commonly used office document formats (including MS Office Files, PDFs, etc.).

[![Super-Linter](https://github.com/Anti-Malware-Alliance/ms-office-macro-bleach/actions/workflows/pre-commit-actions.yml/badge.svg)](https://github.com/marketplace/actions/super-linter)
Patterbear marked this conversation as resolved.
Show resolved Hide resolved

## Supported formats

### Word
Expand Down
20 changes: 12 additions & 8 deletions docubleach/bleach.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
"""This module is designed to purge any and all macros and dynamic content from commonly used office formats.

VBA and OLE content in MS Office files can, and have sometimes been made to, act as vehicles for malware delivery.
VBA and OLE content in MS Office files can, and have sometimes been made to,
act as vehicles for malware delivery.

Microsoft has previously attempted to protect users from macros by disabling them by default.
Microsoft has previously attempted to protect users from macros by disabling
them by default.

However, anybody is able to enable macros in an MS Office file before sending them on to a potential victim.
However, anybody is able to enable macros in an MS Office file before sending
them on to a potential victim.

This module enables users to simply and safely remove any and all macros/dynamic content from MS Office files.
This module enables users to simply and safely remove any and all
macros/dynamic content from MS Office files.

It is part of a suite of programs developed by the AntiMalware Alliance.

Visit https://github.com/Anti-Malware-Alliance for more details about our organisation and projects.
Visit https://github.com/Anti-Malware-Alliance for more details
about our organisation and projects.
"""
from argparse import ArgumentParser
from os import rename, path, remove
Expand All @@ -19,7 +24,6 @@
from shutil import make_archive, rmtree
from olefile import OleFileIO


ooxml_formats = [
"docx",
"docm",
Expand All @@ -46,7 +50,6 @@

bff_formats = [
"doc",
#"ppt",
"xls",
]

Expand Down Expand Up @@ -151,7 +154,8 @@ def validate_file(file):
def main():
parser = ArgumentParser()
parser.add_argument("file", help="file to be bleached")
parser.add_argument("-c", help="notify if macros or potentially dangerous content is found", action="store_true")
parser.add_argument("-c", help="notify if macros or potentially dangerous "
"content is found", action="store_true")
args = parser.parse_args()

if validate_file(args.file):
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ docubleach = "docubleach.bleach:main"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.flake8]
max-line-length = 95
48 changes: 32 additions & 16 deletions tests/test_ooxml_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def test_word_document():
def test_word_document_with_macros():
copyfile("test_files/word_document_with_macros.docm", "test_files/word_document_with_macros.docm.bak")

output = check_output(f"python {program_dir}bleach.py test_files/word_document_with_macros.docm -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/word_document_with_macros.docm -c",
encoding='utf-8')

remove("test_files/word_document_with_macros.docm")
rename("test_files/word_document_with_macros.docm.bak", "test_files/word_document_with_macros.docm")
Expand All @@ -42,7 +43,8 @@ def test_word_template():
def test_word_template_with_macros():
copyfile("test_files/word_template_with_macros.dotm", "test_files/word_template_with_macros.dotm.bak")

output = check_output(f"python {program_dir}bleach.py test_files/word_template_with_macros.dotm -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/word_template_with_macros.dotm -c",
encoding='utf-8')

remove("test_files/word_template_with_macros.dotm")
rename("test_files/word_template_with_macros.dotm.bak", "test_files/word_template_with_macros.dotm")
Expand All @@ -51,49 +53,59 @@ def test_word_template_with_macros():


def test_powerpoint_presentation():
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_presentation.pptx -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_presentation.pptx -c",
encoding='utf-8')

assert output == ""


def test_powerpoint_presentation_with_macros():
copyfile("test_files/powerpoint_presentation_with_macros.pptm", "test_files/powerpoint_presentation_with_macros.pptm.bak")
copyfile("test_files/powerpoint_presentation_with_macros.pptm",
"test_files/powerpoint_presentation_with_macros.pptm.bak")

output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_presentation_with_macros.pptm -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_presentation_with_macros.pptm -c",
encoding='utf-8')

remove("test_files/powerpoint_presentation_with_macros.pptm")
rename("test_files/powerpoint_presentation_with_macros.pptm.bak", "test_files/powerpoint_presentation_with_macros.pptm")
rename("test_files/powerpoint_presentation_with_macros.pptm.bak",
"test_files/powerpoint_presentation_with_macros.pptm")

assert output == "Macros detected and removed.\n"


def test_powerpoint_template():
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_template.potx -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_template.potx -c",
encoding='utf-8')

assert output == ""


def test_powerpoint_template_with_macros():
copyfile("test_files/powerpoint_template_with_macros.potm", "test_files/powerpoint_template_with_macros.potm.bak")
copyfile("test_files/powerpoint_template_with_macros.potm",
"test_files/powerpoint_template_with_macros.potm.bak")

output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_template_with_macros.potm -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_template_with_macros.potm -c",
encoding='utf-8')

remove("test_files/powerpoint_template_with_macros.potm")
rename("test_files/powerpoint_template_with_macros.potm.bak", "test_files/powerpoint_template_with_macros.potm")
rename("test_files/powerpoint_template_with_macros.potm.bak",
"test_files/powerpoint_template_with_macros.potm")

assert output == "Macros detected and removed.\n"


def test_powerpoint_show():
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_show.ppsx -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_show.ppsx -c",
encoding='utf-8')

assert output == ""


def test_powerpoint_show_with_macros():
copyfile("test_files/powerpoint_show_with_macros.ppsm", "test_files/powerpoint_show_with_macros.ppsm.bak")

output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_show_with_macros.ppsm -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/powerpoint_show_with_macros.ppsm -c",
encoding='utf-8')

remove("test_files/powerpoint_show_with_macros.ppsm")
rename("test_files/powerpoint_show_with_macros.ppsm.bak", "test_files/powerpoint_show_with_macros.ppsm")
Expand All @@ -102,15 +114,18 @@ def test_powerpoint_show_with_macros():


def test_excel_spreadsheet():
output = check_output(f"python {program_dir}bleach.py test_files/excel_spreadsheet.xlsx -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/excel_spreadsheet.xlsx -c",
encoding='utf-8')

assert output == ""


def test_excel_spreadsheet_with_macros():
copyfile("test_files/excel_spreadsheet_with_macros.xlsm", "test_files/excel_spreadsheet_with_macros.xlsm.bak")
copyfile("test_files/excel_spreadsheet_with_macros.xlsm",
"test_files/excel_spreadsheet_with_macros.xlsm.bak")

output = check_output(f"python {program_dir}bleach.py test_files/excel_spreadsheet_with_macros.xlsm -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/excel_spreadsheet_with_macros.xlsm -c",
encoding='utf-8')

remove("test_files/excel_spreadsheet_with_macros.xlsm")
rename("test_files/excel_spreadsheet_with_macros.xlsm.bak", "test_files/excel_spreadsheet_with_macros.xlsm")
Expand All @@ -127,7 +142,8 @@ def test_excel_template():
def test_excel_template_with_macros():
copyfile("test_files/excel_template_with_macros.xltm", "test_files/excel_template_with_macros.xltm.bak")

output = check_output(f"python {program_dir}bleach.py test_files/excel_template_with_macros.xltm -c", encoding='utf-8')
output = check_output(f"python {program_dir}bleach.py test_files/excel_template_with_macros.xltm -c",
encoding='utf-8')

remove("test_files/excel_template_with_macros.xltm")
rename("test_files/excel_template_with_macros.xltm.bak", "test_files/excel_template_with_macros.xltm")
Expand Down