Skip to content

Commit

Permalink
Merge pull request #6 from sterrasec/support-eicar
Browse files Browse the repository at this point in the history
Support EICAR
  • Loading branch information
tkmru authored May 29, 2024
2 parents 3d3d5a6 + bf9315f commit deec095
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Generator of static files for testing file upload functionality.

Supported file types:
- EICAR test file
- For checking if the antivirus software works
- csv
- For checking if the worksheet function works
- jpeg
Expand Down Expand Up @@ -51,22 +53,29 @@ To specify bytes, you can use B, KB, MB, or GB as a unit.
$ dummy -t abc -b 1MB test.png
```

To generate an EICAR test file, include `eicar` as part of the file name.

```bash
$ dummy eicar.com
```

You can check your options at any time by checking help.

```bash
$ dummy -h
usage: dummy [-h] [-t TEXT] [-b BYTES] file_path
usage: dummy [-h] [-t TEXT] [-b BYTES] [-v] file_path

Create a dummy file for testing.

positional arguments:
file_path Path to the generated file(.csv .jpeg, .png, .pdf)
file_path Path to the generated file(.csv .jpeg, .png, .pdf, EICAR)

options:
-h, --help show this help message and exit
-t TEXT, --text TEXT Text to be written in the file(Disabled in csv)
-b BYTES, --bytes BYTES
Bytes of file(.png, .csv)
-v, --version Print version
```

## License
Expand Down
1 change: 1 addition & 0 deletions dummy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.2.1'
21 changes: 18 additions & 3 deletions dummy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

import argparse
import binascii
import codecs
import colorama
import io
import os
import platform

from dummy import __version__
from colorama import Fore
from PIL import Image, ImageDraw, ImageFont
from reportlab.pdfgen import canvas
Expand Down Expand Up @@ -35,6 +37,14 @@ def make_csv(file_path, byte_size):
f.write('0\n')
return True

def make_eicar(file_path):
# Avoid scanners will detect the EICAR test file as a virus
rot13_eicar_bytes = 'K5B!C%@NC[4\\CMK54(C^)7PP)7}$RVPNE-FGNAQNEQ-NAGVIVEHF-GRFG-SVYR!$U+U*'
with open(file_path, 'w') as f:
f.write(codecs.encode(rot13_eicar_bytes, "rot_13"))

return True

def make_jpeg(file_path, text):
image = Image.new('RGB', (729, 516), (255, 255, 255)) # B5, White
draw = ImageDraw.Draw(image)
Expand Down Expand Up @@ -127,9 +137,10 @@ def parse_bytes(byte_str):
def parse_args():
colorama.init(autoreset=True)
parser = argparse.ArgumentParser(description='Create a dummy file for testing.')
parser.add_argument('file_path', help='Path to the generated file(.csv .jpeg, .png, .pdf)')
parser.add_argument('file_path', help='Path to the generated file(.csv .jpeg, .png, .pdf, EICAR)')
parser.add_argument('-t', '--text', help='Text to be written in the file(Disabled in csv)', default='dummy file')
parser.add_argument('-b', '--bytes', help='Bytes of file(.png, .csv)')
parser.add_argument('-v', '--version', help='Print version', action='version', version=__version__)

args = parser.parse_args()
if args.bytes is not None and not args.file_path.endswith('.png') and not args.file_path.endswith('.csv'):
Expand All @@ -142,8 +153,12 @@ def parse_args():
if not os.path.exists(dir_path):
print(Fore.RED + 'Error: The specified directory does not exist.')
return

if args.file_path.endswith('.csv'):

if 'eicar' in args.file_path or 'EICAR' in args.file_path:
make_eicar(args.file_path)
print(Fore.GREEN + 'Successfully generated: ' + args.file_path)

elif args.file_path.endswith('.csv'):
make_csv(args.file_path, parse_bytes(args.bytes))
print(Fore.GREEN + 'Successfully generated: ' + args.file_path)

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# coding: UTF-8

from setuptools import setup
from dummy import __version__

setup(
name='dummy',
version='0.2.0',
version=__version__,
description='Create a dummy file for testing.',
author='Taichi Kotake',
packages=['dummy'],
Expand Down

0 comments on commit deec095

Please sign in to comment.