Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #!/usr/bin/python2
  2. import requests
  3. import json
  4.  
  5. MISPAPI='<misp apikey>'
  6. MISPURL='<misp url>'
  7. BASE='/var/www/iocs/' #files under this path need to be served by a web-server
  8. TYPES=['domain','ip-src','ip-dst','email-src','email-dst','email']
  9. WHITELIST = "<white list file containing iocs that won't be exported>"
  10.  
  11. for ioctype in TYPES:
  12. MISPQUERY='/attributes/restSearch/timestamp:1d/type:'+ioctype
  13. response = requests.get(MISPURL+MISPQUERY,headers={"Authorization":MISPAPI})
  14. whitelist = []
  15. try:
  16. with open(WHITELIST) as f:
  17. whitelist=list(set(f.read().splitlines()))
  18. except:
  19. print("Whitelist loading failure")
  20.  
  21. if response.status_code == 200:
  22. jresponse = response.json()
  23. if jresponse["response"] and jresponse["response"]["Attribute"]:
  24. with open(BASE+ioctype,"wa+")as f:
  25. rows={}
  26. for attribute in jresponse["response"]["Attribute"]:
  27. if attribute["value"] in whitelist:
  28. continue
  29. if not attribute["value"] in rows:
  30. rows[attribute["value"]]=attribute["id"]+" - "+attribute["Event"]["info"]
  31. else:
  32. rows[attribute["value"]]+=";"+attribute["id"]+" - "+attribute["Event"]["info"]
  33.  
  34. for row in rows:
  35. f.write("{},{} - {}\n".format(row,row,rows[row]))
  36. else:
  37. print("Status code:"+str(response.status_code))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement