31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from logging import log
|
|
import logging
|
|
from flask import Blueprint, request, jsonify, abort
|
|
from os import path
|
|
import config
|
|
|
|
capa_bp = Blueprint('capa', __name__)
|
|
|
|
@capa_bp.route('/analyze', methods=['GET'])
|
|
def analyze_mraptor():
|
|
file = request.args.get('file', '')
|
|
if file == '':
|
|
abort(400)
|
|
filepath = path.join(config.Config.FILE_DIRECTORY, file)
|
|
# Analyze with olevba
|
|
vbaparser = olevba.VBA_Parser(filepath)
|
|
if vbaparser.detect_vba_macros():
|
|
vba_code = ''
|
|
try:
|
|
vba_code = vbaparser.get_vba_code_all_modules()
|
|
except Exception as e:
|
|
logging.error(e)
|
|
abort(500)
|
|
raptor = mraptor.MacroRaptor(vba_code)
|
|
raptor.scan()
|
|
if raptor.suspicious:
|
|
return jsonify({'filename': file, 'result': mraptor.Result_Suspicious, 'flags': raptor.get_flags(), 'matches': raptor.matches})
|
|
else:
|
|
return jsonify({'filename': file, 'result': mraptor.Result_MacroOK, 'flags': raptor.get_flags(), 'matches': raptor.matches})
|
|
else:
|
|
return jsonify({'filename': file, 'result': mraptor.Result_NoMacro})
|