|
60 | 60 |
|
61 | 61 | from pywerview.cli.helpers import get_localdisks, get_netsession, get_netgroupmember, get_netgroup, get_netcomputer, get_netloggedon, get_netlocalgroup |
62 | 62 |
|
63 | | -from time import time |
| 63 | +from time import time, ctime |
64 | 64 | from datetime import datetime |
65 | 65 | from functools import wraps |
66 | 66 | from traceback import format_exc |
@@ -903,6 +903,65 @@ def shares(self): |
903 | 903 | self.logger.highlight(f"{name:<15} {','.join(perms):<15} {remark}") |
904 | 904 | return permissions |
905 | 905 |
|
| 906 | + |
| 907 | + def enum_shares(self): |
| 908 | + try: |
| 909 | + shares = self.conn.listShares() |
| 910 | + self.logger.info(f"Shares returned: {shares}") |
| 911 | + except SessionError as e: |
| 912 | + error = get_error_string(e) |
| 913 | + self.logger.fail( |
| 914 | + f"Error enumerating shares: {error}", |
| 915 | + color="magenta" if error in smb_error_status else "red", |
| 916 | + ) |
| 917 | + return |
| 918 | + except Exception as e: |
| 919 | + error = get_error_string(e) |
| 920 | + self.logger.fail( |
| 921 | + f"Error enumerating shares: {error}", |
| 922 | + color="magenta" if error in smb_error_status else "red", |
| 923 | + ) |
| 924 | + return |
| 925 | + |
| 926 | + self.logger.display("Enumerating SMB Shares Directories") |
| 927 | + for share in shares: |
| 928 | + share_name = share["shi1_netname"][:-1] |
| 929 | + depth = 1 |
| 930 | + contents = self.conn.listPath(share_name, "*") |
| 931 | + |
| 932 | + self.logger.success(share_name) |
| 933 | + |
| 934 | + if contents and depth == 1: |
| 935 | + self.logger.highlight(f"{'Perms':<9}{'File Size':<15}{'Date':<30}{'File Path':<45}") |
| 936 | + self.logger.highlight(f"{'-----':<9}{'---------':<15}{'----':<30}{'---------':<45}") |
| 937 | + self.list_share(share_name, "") |
| 938 | + |
| 939 | + |
| 940 | + def list_share(self, share_name, path_dir, depth=1): |
| 941 | + search_path = ntpath.join(path_dir, "*") |
| 942 | + |
| 943 | + try: |
| 944 | + contents = self.conn.listPath(share_name, search_path) |
| 945 | + except SessionError as e: |
| 946 | + error = get_error_string(e) |
| 947 | + self.logger.fail( |
| 948 | + f"Error enumerating '{search_path}': {error}", |
| 949 | + color="magenta" if error in smb_error_status else "red", |
| 950 | + ) |
| 951 | + return |
| 952 | + |
| 953 | + for content in contents: |
| 954 | + path_name = content.get_longname() |
| 955 | + full_path = ntpath.join(path_dir, path_name) |
| 956 | + |
| 957 | + if path_name in [".", ".."]: |
| 958 | + continue |
| 959 | + |
| 960 | + if path_name != path_dir: |
| 961 | + self.logger.highlight(f"{'d' if content.is_directory() else 'f'}{'rw-' if content.is_readonly() > 0 else 'r--':<8}{content.get_filesize():<15}{ctime(float(content.get_mtime_epoch())):<30}{full_path:<45}") |
| 962 | + if content.is_directory() and depth < self.args.enum_shares and path_name not in [ ".", ".."]: |
| 963 | + self.list_share(share_name, full_path, depth+1) |
| 964 | + |
906 | 965 | @requires_admin |
907 | 966 | def interfaces(self): |
908 | 967 | """ |
|
0 commit comments