domainaware / parsedmarc

A Python package and CLI for parsing aggregate and forensic DMARC reports
https://domainaware.github.io/parsedmarc/
Apache License 2.0
966 stars 210 forks source link

Problem with temp files #355

Open rainer-tammer opened 1 year ago

rainer-tammer commented 1 year ago

Hello, I do have a problem with temp files/sending emails.

parsedmarc: 8.3.1 python: 3.9 eMail via SMTP port 25 (w/o authentication/TSL)

INFO:cli.py:777:Starting parsedmarc

... DEBUG:cli.py:889:Skipping IMAP certificate verification DEBUG:init.py:1087:Found 42 messages in INBOX DEBUG:init.py:1095:Processing 42 messages DEBUG:init.py:1099:Processing message 1 of 42: UID 47 ... DEBUG:init.py:1430:Emailing report to: foo@acme.com ERROR:cli.py:988:[Errno 2] No such file or directory: '/tmp/tmpkjdly6mg/aggregate.json'

Config:

[general]

Save aggregate and forensic reports to Elasticsearch

save_aggregate = True save_forensic = True output = /tmp/parsedmarc nameservers = ....cut... verbose = True debug = True log_file = /var/log/parsedmarc.log ip_db_path = /var/lib/GeoIP/GeoLite2-Country.mmdb

[smtp]

For sending email (internal smtp relay)

host = mail.schuler.de

host = ....cut... port = 25 ssl = False user = None password = None from = foo@acme.com smtp_skip_certificate_verification = False

On the smtp server I see:

Sep 22 07:40:08 ACME sendmail[9084]: 28M5e6QZ009084: dmarc01.acme.com [1.2.3.4] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA

I can connect to the smtp server via "telnet 1.2.3.4 25 without any issues and I can send mails manually via this telnet connection.

Any ideas???

Bye Rainer

TafkaMax commented 1 year ago

You have to create the files manually i have found out.

forensic.json forensic.csv aggregate.csv aggregate.json

ansible helps me with that.

smtp problems I havent encountered.

rainer-tammer commented 1 year ago

Hello, I tried that, but the script will still delete files in a random directory:

ERROR:cli.py:988:[Errno 2] No such file or directory: '/tmp/tmpkjdly6mg/aggregate.json'

So the output = /tmp/parsedmarc is probably not homered for all files?

Bye Rainer

rainer-tammer commented 1 year ago

Hello, I also get the following error:

ERROR:cli.py:183:Forensic report missing required field: 'feedback_type'

Bye Rainer

binadamu-isiyoonekana commented 1 year ago

Hi all. First of all, thanks for such a great projet. Same issue as @rainer-tammer. After creating manually all files, including 'aggregate.json', in the 'output = /var/dmarc' folder, then a new 'aggregate.json' file is created again in an other temporary output folder with the following error:

ERROR:cli.py:988:[Errno 2] No such file or directory: '/tmp/tmp8u71wacs/aggregate.json'

Thank you. Ciao

rainer-tammer commented 1 year ago

Hello, I am no Phyton expert, but this could have to-do with:

https://github.com/domainaware/parsedmarc/commit/4e8c74599bb0b4f2a32740aaf6145d34fed3d92a

Bye Rainer

rainer-tammer commented 1 year ago

Hello, The problem is, that in email_results() -> get_report_zip() a random output directory is selected:

.... snip ...
    storage = BytesIO()
    tmp_dir = tempfile.mkdtemp() <---- this will collide with the output option and even without the output 
                                                            option set you will end up with different directories
.... snip ...

Quick fix (with option output set):

cli.py

call to email_results()
<                           subject=opts.smtp_subject, output=opts.output)    <--- add the output directory
---
>                           subject=opts.smtp_subject)

__init__.py

get_report_zip()

< def get_report_zip(results, output):  <---- add the output directory
---
> def get_report_zip(results):

... cut ...

     # tmp_dir = tempfile.mkdtemp()
     tmp_dir = output

email_results()

<                   attachment_filename=None, message=None, output=None):
---
>                   attachment_filename=None, message=None):

... cut ...

<     zip_bytes = get_report_zip(results, output)
---
>     zip_bytes = get_report_zip(results)

And in append_json() and append_csv) the file open/create must be adjusted.

Note: This is not in patch format, because I have several debug statements in the code. Note: The code does not check for a missing (unset) output option.

CAUTION: This is only a extremely dirty hack which will probably work as long as the output option is set and the directory is present (with rw perms for the process owner).

With that change the whole thing did run.

Bye Rainer

Pascal76 commented 1 year ago

hello, will this bug be fixed ? it is broken since nearly 2 months :(

rainer-tammer commented 1 year ago

Any news?

Pascal76 commented 1 year ago

up

rainer-tammer commented 1 year ago

Hello, Any news about this problem? Does anyone have a better fix? I only posted a quick and dirty fix to allow the tool to run....

Bye Rainer

rainer-tammer commented 11 months ago

Hello, Any news?

Bye Rainer