· 8 years ago · Jan 24, 2018, 04:24 PM
1import os
2from datetime import datetime, date, timedelta
3import subprocess
4import pyjq
5import pandas as pd
6
7# Initializes the variables for the directories
8HomeDir = "Users/kiya/Downloads/"
9ScriptDir = HomeDir + "pan-python-0.12.0 2"
10ResultDir = HomeDir + "techscroll/"
11
12# Create the dates
13ToDay = datetime.now().strftime('%Y%m%d')
14# checkDATE = (date.today() - timedelta(1)).strfttime('%Y%m%d')
15ResultFile = "Test"
16CheckDATE = "Test"
17NOWDATE = "TEST"
18
19# Run the panafpi
20subprocess.check_output('python ' + ScriptDir + '/bin/panafapi.py -K secretkey --samples -j -r "{"query":{"operator":"all","children":[{"field":"alias.ip_address","operator":"contains","value":"' + ResultFile + '"},{"operator":"any","children":[{"field":"sample.update_date","operator":"is in the range","value":["' + CheckDATE + 'T00:00:00","$' + NOWDATE + 'T23:59:59"]},{"field":"sample.create_date","operator":"is in the range","value":["' + CheckDATE + 'T00:00:00","' + NOWDATE + 'T23:59:59"]},{"operator":"any","children":[{"field":"sample.malware","operator":"is","value":1},{"field":"sample.malware","operator":"is","value":4}]}]}]},"scope":"global","size":1,"from":0,"sort":{"create_date":{"order":"desc"}}}" > ' + ResultDir + 'srciplist-' + ToDay + '.json', shell=True)
21
22# Using pyjq to filter
23filteredResultData = pyjq.all('.hits[]._source | .create_date + "," + .sha256')
24
25# Save the JSON file to comma-separated file
26pd.to_csv(ResultDir + "/srciplist-" + ToDay + ".csv", sep=",")
27
28
29
30error:
31
32/bin/sh: Users/kiya/Downloads/techscroll/srciplist-20180125.json: No such file or directory
33Traceback (most recent call last):
34 File "/Users/mani/Downloads/tester (1).py", line 22, in <module>
35 subprocess.check_output('python ' + ScriptDir + '/bin/panafapi.py -K secretkey --samples -j -r "{"query":{"operator":"all","children":[{"field":"alias.ip_address","operator":"contains","value":"' + ResultFile + '"},{"operator":"any","children":[{"field":"sample.update_date","operator":"is in the range","value":["' + CheckDATE + 'T00:00:00","$' + NOWDATE + 'T23:59:59"]},{"field":"sample.create_date","operator":"is in the range","value":["' + CheckDATE + 'T00:00:00","' + NOWDATE + 'T23:59:59"]},{"operator":"any","children":[{"field":"sample.malware","operator":"is","value":1},{"field":"sample.malware","operator":"is","value":4}]}]}]},"scope":"global","size":1,"from":0,"sort":{"create_date":{"order":"desc"}}}" > ' + ResultDir + 'srciplist-' + ToDay + '.json', shell=True)
36 File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 336, in check_output
37 **kwargs).stdout
38 File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 418, in run
39 output=stdout, stderr=stderr)
40subprocess.CalledProcessError: Command 'python Users/kiya/Downloads/pan-python-0.12.0 2/bin/panafapi.py -K secret key --samples -j -r "{"query":{"operator":"all","children":[{"field":"alias.ip_address","operator":"contains","value":"Test"},{"operator":"any","children":[{"field":"sample.update_date","operator":"is in the range","value":["TestT00:00:00","$TESTT23:59:59"]},{"field":"sample.create_date","operator":"is in the range","value":["TestT00:00:00","TESTT23:59:59"]},{"operator":"any","children":[{"field":"sample.malware","operator":"is","value":1},{"field":"sample.malware","operator":"is","value":4}]}]}]},"scope":"global","size":1,"from":0,"sort":{"create_date":{"order":"desc"}}}" > Users/kiya/Downloads/techscroll/srciplist-20180125.json' returned non-zero exit status 1.