Guest User

Untitled

a guest
Feb 7th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import argparse
  2. import getpass
  3.  
  4. import splunk.entity as entity
  5. import splunk.auth
  6.  
  7. ap = argparse.ArgumentParser()
  8. ap.add_argument("--username", required=True)
  9. ap.add_argument("--password", required=False)
  10. ap.add_argument("--app")
  11. args = ap.parse_args()
  12.  
  13. if not args.password:
  14. args.password = getpass.getpass("Password: ")
  15.  
  16. sessionKey = splunk.auth.getSessionKey(args.username, args.password)
  17.  
  18. try:
  19. # list all credentials
  20. entities = entity.getEntities(
  21. ["storage", "passwords"],
  22. namespace="-",
  23. owner="nobody",
  24. sessionKey=sessionKey
  25. )
  26. except Exception as e:
  27. raise Exception("Could not get credentials from splunk. Error: %s" % str(e))
  28.  
  29. data = {}
  30. for cred in entities.values():
  31. app_name = cred["eai:acl"]["app"]
  32. if args.app and app_name != args.app:
  33. continue
  34. if app_name not in data:
  35. data[app_name] = []
  36. data[app_name].append({k: cred[k] for k in ("username", "realm", "clear_password")})
  37.  
  38. for app in sorted(data.keys()):
  39. print("[+] App: %s" % app)
  40. for cred in sorted(data[app], key=lambda x: x["username"]):
  41. print(" [+] Username: %s, Realm: %s, Password: %s" % (
  42. cred["username"],
  43. cred["realm"],
  44. cred["clear_password"]
  45. ))
Add Comment
Please, Sign In to add comment