Guest User

Untitled

a guest
May 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import json
  2. import boto3
  3. from pprint import pprint # Pretty-print for displaying the JSON nicely.
  4.  
  5. #pprint(listOfFindings)
  6.  
  7. def lambda_handler(event, context):
  8. client = boto3.client('guardduty') # Creating the client.
  9. Det_ID = '5ab1b6808e98faaabd947a01af9ed970' # Setting the Detect ID for GD.
  10. response = client.list_findings(DetectorId=Det_ID) # Gathering all findings... Need to filter.
  11. findings = json.dumps(response) # Dumping the JSON findings
  12. listOfFindings = json.loads(findings) # Making them into a readable format for Python.
  13. # print("Here's the IDs!",listOfFindings['FindingIds'],"nnn") # Printing all Finding IDs.
  14.  
  15. idPosition=0
  16. idList = []
  17. for id in listOfFindings['FindingIds']: # Looping through all the Finding IDs.
  18. #print("nnnNumber", x, listOfFindings['FindingIds'][x]) # Prints all the Finding Ids separated.
  19. idList.append(listOfFindings['FindingIds'][idPosition])
  20. idPosition+=1
  21.  
  22. # print("TEST") - Debugging.
  23. # print(idList) - Debugging.
  24.  
  25. findingsList = []
  26. position = 0
  27. for ids in idList:
  28. # print(idList[position])
  29. stringFindingId = str(idList[position])
  30. #stringFindingId = idList[position]
  31. allFindings = client.get_findings(
  32. DetectorId=Det_ID,
  33. FindingIds=[
  34. stringFindingId,])
  35. dumpFindings = json.dumps(allFindings)
  36. loadFindings = json.loads(dumpFindings)
  37. # findingsList.append(loadFindings)
  38. print(loadFindings['Findings']['Resource']['NetworkInterfaces']['PublicIp']) # BROKEN HERE
  39. position += 1
  40.  
  41. dumpFindings = json.dumps(allFindings)
  42. loadFindings = json.loads(dumpFindings)
Add Comment
Please, Sign In to add comment