mirror of https://github.com/MISP/misp-modules
- added wand requirement
- fixed missing return png byte-stream - move module import to handler to catch and report errorzpull/199/head
parent
7885017981
commit
60a3fbe282
|
@ -14,6 +14,7 @@ git+https://github.com/MISP/PyMISP.git#egg=pymisp
|
||||||
git+https://github.com/sebdraven/pyonyphe#egg=pyonyphe
|
git+https://github.com/sebdraven/pyonyphe#egg=pyonyphe
|
||||||
pillow
|
pillow
|
||||||
pytesseract
|
pytesseract
|
||||||
|
wand
|
||||||
SPARQLWrapper
|
SPARQLWrapper
|
||||||
domaintools_api
|
domaintools_api
|
||||||
pygeoip
|
pygeoip
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
import magic
|
|
||||||
|
|
||||||
from PIL import Image
|
|
||||||
|
|
||||||
from wand.image import Image as WImage
|
|
||||||
|
|
||||||
from pytesseract import image_to_string
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
misperrors = {'error': 'Error'}
|
misperrors = {'error': 'Error'}
|
||||||
userConfig = { };
|
userConfig = { };
|
||||||
|
@ -21,6 +14,32 @@ moduleconfig = []
|
||||||
|
|
||||||
|
|
||||||
def handler(q=False):
|
def handler(q=False):
|
||||||
|
# try to import modules and return errors if module not found
|
||||||
|
try:
|
||||||
|
import magic
|
||||||
|
except ImportError:
|
||||||
|
misperrors['error'] = "Please pip(3) install magic"
|
||||||
|
return misperrors
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
except ImportError:
|
||||||
|
misperrors['error'] = "Please pip(3) install pillow"
|
||||||
|
return misperrors
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Official ImageMagick module
|
||||||
|
from wand.image import Image as WImage
|
||||||
|
except ImportError:
|
||||||
|
misperrors['error'] = "Please pip(3) install wand"
|
||||||
|
return misperrors
|
||||||
|
|
||||||
|
try:
|
||||||
|
from pytesseract import image_to_string
|
||||||
|
except ImportError:
|
||||||
|
misperrors['error'] = "Please pip(3) install pytesseract"
|
||||||
|
return misperrors
|
||||||
|
|
||||||
if q is False:
|
if q is False:
|
||||||
return False
|
return False
|
||||||
r = {'results': []}
|
r = {'results': []}
|
||||||
|
@ -32,14 +51,16 @@ def handler(q=False):
|
||||||
pages=len(pdf.sequence)
|
pages=len(pdf.sequence)
|
||||||
img = WImage(width=pdf.width, height=pdf.height * pages)
|
img = WImage(width=pdf.width, height=pdf.height * pages)
|
||||||
for p in range(pages):
|
for p in range(pages):
|
||||||
img.composite(pdf.sequence[p], top=pdf.height * p, left=0)
|
image = img.composite(pdf.sequence[p], top=pdf.height * p, left=0)
|
||||||
image = document
|
image = img.make_blob('png')
|
||||||
|
else:
|
||||||
|
image = document
|
||||||
|
|
||||||
image_file = BytesIO(image)
|
image_file = BytesIO(image)
|
||||||
image_file.seek(0)
|
image_file.seek(0)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
im = WImage(blob=image_file)
|
im = Image.open(image_file)
|
||||||
except IOError:
|
except IOError:
|
||||||
misperrors['error'] = "Corrupt or not an image file."
|
misperrors['error'] = "Corrupt or not an image file."
|
||||||
return misperrors
|
return misperrors
|
||||||
|
|
Loading…
Reference in New Issue