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

"errorMessage": "Invalid output\n" on Mail Responder #452

Closed
sheilapbi opened this issue Apr 5, 2019 · 4 comments
Closed

"errorMessage": "Invalid output\n" on Mail Responder #452

sheilapbi opened this issue Apr 5, 2019 · 4 comments

Comments

@sheilapbi
Copy link

Request Type

Bug

Work Environment

N/A

Description

I created a very simple Mail Responder for Cortex/TheHive that works when I execute it from my bash console but doesn't work when executed in TheHive. I get "errorMessage": "Invalid output\n"

The owner is set to cortex:cortex and permissions are set correctly, just the same as another responder that works.

Steps to Reproduce

Execution of the responder on bash, same server as the code for TheHive:

python thehive/responders/SendMail/sendmail.py <<< '{
    "dataType": "",
    "description": "Link to analysis",
    "tlp": 3,
    "tags": [
        "Phishing",
        "Montepio"
    ],
    "title": "Processed URL http://mon",
    "source": "w",
    "createdBy": "admin",
    "sourceRef": "82ca55",
    "artifacts": [
        {
            "data": "http://mon",
            "dataType": "url",
            "message": null,
            "tags": [
                "phishing"
            ],
            "tlp": 2
        }
    ],
    "lastSyncDate": 1552658595914,
    "customFields": {
        "client": {
            "order": 0,
            "string": "der"
        }
    },
    "type": "external",
    "follow": true,
    "caseTemplate": null,
    "date": 1552658595000,
    "createdAt": 1552658595913,
    "status": "New",
    "severity": 2,
    "_type": "alert",
    "_routing": "ff086cadf96ca22b67d18edc4f5fa3bd",
    "_parent": null,
    "_id": "ff086cadf96ca22b67d18edc4f5fa3bd",
    "_version": 1,
    "id": "ff086cadf96ca22b67d18edc4f5fa3bd"
}'

Mailer code:

#!/usr/bin/env python
# encoding: utf-8

import smtplib
from cortexutils.responder import Responder


class SendMail(Responder):

    def __init__(self):
        Responder.__init__(self)
        # self.smtp_host = self.get_param('config.smtp_host', 'localhost')
        # self.smtp_port = self.get_param('config.smtp_port', '25')
        # self.mail_from = self.get_param('config.from', None, 'Missing sender email address')
        self.mail_from = "[email protected]"
        self.password = "coolpassword"
        self.mail_to = "[email protected]"
        self.message = "HELLO"

    def run(self):
        print "TEST PRUEBA MAIL"
        Responder.run(self)
        server = smtplib.SMTP("smtp.whatever.com", 587)
        server.starttls()
        server.login(self.mail_from, self.password)
        server.sendmail(self.mail_from, self.mail_to , self.message)
        server.quit()
        self.report({'message': 'message sent'})

    def operations(self, raw):
        return [self.build_operation('AddTagToCase', tag='mail sent')]

if __name__ == '__main__':
    SendMail().run()

Config file:

{
  "name": "Send_Mail",
  "version": "1.0",
  "author": "author",
  "url": "https://github.com/TheHive-Project/Cortex-Analyzers",
  "license": "AGPL-V3",
  "description": "Send mail",
  "dataTypeList": ["thehive:alert"],
  "command": "SendMail/sendmail.py",
  "baseConfig": "sendmail",
  "configurationItems": [
  ]
}

Thanks in advanced!

@nadouani
Copy link
Contributor

nadouani commented Apr 5, 2019

is your .py file executable?

@sheilapbi
Copy link
Author

Yes, it is. :)

@nadouani
Copy link
Contributor

Remove the print statments, this make the output an invalid json.

@sheilapbi
Copy link
Author

Thank you so much!! It was exactly what was messing with the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants