Advertisement
Guest User

Untitled

a guest
May 26th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import smbc
  4. import sys
  5. import os
  6.  
  7. # WORKGROUP = "WORKGROUP"
  8. # USERNAME = "username"
  9. # PASSWORD = "password"
  10.  
  11. def get_shares(server):
  12. shares = []
  13. for share in ctx.opendir("smb://" + server).getdents():
  14. if share.smbc_type == 3: # 3 = File Share
  15. shares.append(share.name)
  16. return shares
  17.  
  18. def get_share_content(server, share):
  19. contents = []
  20. try:
  21. for content in ctx.opendir("smb://" + server + "/" + share).getdents():
  22. contents.append(content.name)
  23. except:
  24. pass
  25. return contents
  26.  
  27. def try_write_file(server, share, path):
  28. writable = []
  29. try:
  30. filewrite = ctx.open("smb://" + server + "/" + share + "/" + path + "/testfile", os.O_CREAT | os.O_WRONLY)
  31. writable.append(path)
  32. except:
  33. pass
  34. return writable
  35.  
  36. ctx = smbc.Context()
  37. def main():
  38. serverlist = sys.argv[1]
  39.  
  40. print("[*] Serverlist: " + serverlist)
  41. with open(serverlist) as file:
  42. for server in file.read().splitlines():
  43. print("[*] Shares for server " + server + ":")
  44.  
  45. try:
  46. shares = get_shares(server)
  47. except:
  48. print("Cannot connect!")
  49. continue
  50.  
  51. for share in shares:
  52. print("[*] Share: //" + server + "/" + share)
  53.  
  54. for share in shares:
  55. #print("[*] Content of //" + server + "/" + share + ":")
  56. contents = get_share_content(server, share)
  57. for content in contents:
  58. print("[*] Content: //" + server + "/" + share + "/" + content)
  59. if try_write_file(server, share, content):
  60. print("[!] It's possible two write to: " + server + "/" + share + "/" + content)
  61.  
  62. if __name__ == '__main__':
  63. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement