Example #1
0
 def submit(self):
     """TODO: Validate sha256 from file
     """
     file = request.files['artifact']
     filename = secure_filename(file.filename)
     file.save(os.path.join(app.config['TMP_UPLOAD_FOLDER'], filename))
     if os.path.isfile(
             os.path.join(app.config['BIN_UPLOAD_FOLDER'], filename)):
         return jsonify(ecode=302,
                        msg="Asset already analysed",
                        goto=url_for("MalwareView:info",
                                     hash=filename,
                                     type=type))
     ## Celery
     obj = {"path": os.path.join(app.config['TMP_UPLOAD_FOLDER'], filename)}
     reader = geoip2.database.Reader(app.config['MAXMAIN_DB_CITIES'])
     try:
         response = reader.city(request.remote_addr)
     except (AddressNotFoundError):
         obj["ipMeta"] = [{
             "city": "unknown",
             "ip": request.remote_addr,
             "country": "unknown",
             "iso_code": "unknown",
             "date": datetime.utcnow(),
             "geo": [0.0, 0.0]
         }]
     else:
         obj["ipMeta"] = [{
             "city":
             response.city.name,
             "ip":
             request.remote_addr,
             "country":
             response.country.name,
             "iso_code":
             response.country.iso_code,
             "date":
             datetime.utcnow(),
             "geo":
             [response.location.longitude, response.location.latitude]
         }]
     # Celery task
     task_id = analysis.delay(memt_dumps(obj))
     return jsonify(ecode=200,
                    msg="Analysis has been lanch in background",
                    goto=url_for("MalwareView:info",
                                 hash=filename,
                                 type=type),
                    task_id=task_id.id)
Example #2
0
def submit():
    form = UploadForm()
    if form.validate_on_submit():
        filename = secure_filename(form.malware.data.filename)
        form.malware.data.save(os.path.join(app.config['TMP_UPLOAD_FOLDER'], filename))
        with open(os.path.join(app.config['TMP_UPLOAD_FOLDER'], filename), 'rb') as malware:
            data = malware.read()
            sha256 = hashlib.sha256(data).hexdigest()
            if os.path.isfile(os.path.join(app.config['BIN_UPLOAD_FOLDER'],sha256)):
                return redirect(url_for("detail.index", hash=sha256))
        ## Celery
        obj = {
            "path": os.path.join(app.config['TMP_UPLOAD_FOLDER'], filename),
            "sha256": sha256
        }
        reader = geoip2.database.Reader(app.config['MAXMAIN_DB_CITIES'])
        try:
            response = reader.city(request.remote_addr)
        except (AddressNotFoundError):
            obj["ipMeta"] = [{
                                "city": "unknown",
                                "ip": request.remote_addr,
                                "country": "unknown",
                                "iso_code": "unknown",
                                "date": datetime.utcnow(),
                                "geo": [0.0, 0.0]
                            }]
        else:
            obj["ipMeta"] = [{
                                "city": response.city.name,
                                "ip": request.remote_addr,
                                "country": response.country.name,
                                "iso_code": response.country.iso_code,
                                "date": datetime.utcnow(),
                                "geo": [response.location.longitude, response.location.latitude]
                            }]
        # Celery task
        task_id = analysis.delay(memt_dumps(obj))
        return redirect(url_for('upload.landing', hash=sha256, task_id=task_id.id))
    return redirect(url_for("index.index"))
Example #3
0
 def submit(self):
     """TODO: Validate sha256 from file
     """
     file = request.files['artifact']
     filename = secure_filename(file.filename)
     file.save(os.path.join(app.config['TMP_UPLOAD_FOLDER'], filename))
     if os.path.isfile(os.path.join(app.config['BIN_UPLOAD_FOLDER'], filename)):
         return jsonify(ecode=302, msg="Asset already analysed", goto=url_for("MalwareView:info", hash=filename, type=type))
     ## Celery
     obj = {
         "path": os.path.join(app.config['TMP_UPLOAD_FOLDER'], filename)
     }
     reader = geoip2.database.Reader(app.config['MAXMAIN_DB_CITIES'])
     try:
         response = reader.city(request.remote_addr)
     except (AddressNotFoundError):
         obj["ipMeta"] = [{
                             "city": "unknown",
                             "ip": request.remote_addr,
                             "country": "unknown",
                             "iso_code": "unknown",
                             "date": datetime.utcnow(),
                             "geo": [0.0, 0.0]
                         }]
     else:
         obj["ipMeta"] = [{
                             "city": response.city.name,
                             "ip": request.remote_addr,
                             "country": response.country.name,
                             "iso_code": response.country.iso_code,
                             "date": datetime.utcnow(),
                             "geo": [response.location.longitude, response.location.latitude]
                         }]
     # Celery task
     task_id = analysis.delay(memt_dumps(obj))
     return jsonify(ecode=200, msg="Analysis has been lanch in background", goto=url_for("MalwareView:info", hash=filename, type=type), task_id=task_id.id)