|
27 | 27 | from impacket.dcerpc.v5.dtypes import NULL |
28 | 28 | from impacket.dcerpc.v5.dcomrt import DCOMConnection |
29 | 29 | from impacket.dcerpc.v5.dcom.wmi import CLSID_WbemLevel1Login, IID_IWbemLevel1Login, IWbemLevel1Login |
| 30 | +from impacket.smb3structs import FILE_SHARE_WRITE, FILE_SHARE_DELETE |
30 | 31 |
|
31 | 32 | from nxc.config import process_secret, host_info_colors |
32 | 33 | from nxc.connection import connection, sem, requires_admin, dcom_FirewallChecker |
@@ -774,6 +775,7 @@ def ps_execute(self, payload=None, get_output=False, methods=None, force_ps32=Fa |
774 | 775 |
|
775 | 776 | def shares(self): |
776 | 777 | temp_dir = ntpath.normpath("\\" + gen_random_string()) |
| 778 | + temp_file = ntpath.normpath("\\" + gen_random_string()+ ".txt") |
777 | 779 | permissions = [] |
778 | 780 |
|
779 | 781 | try: |
@@ -825,16 +827,35 @@ def shares(self): |
825 | 827 | self.conn.createDirectory(share_name, temp_dir) |
826 | 828 | write = True |
827 | 829 | share_info["access"].append("WRITE") |
| 830 | + try: |
| 831 | + self.conn.deleteDirectory(share_name, temp_dir) |
| 832 | + except SessionError as e: |
| 833 | + error = get_error_string(e) |
| 834 | + if error == 'STATUS_OBJECT_NAME_NOT_FOUND': |
| 835 | + pass |
| 836 | + else: |
| 837 | + self.logger.debug(f"Error DELETING created temp dir {temp_dir} on share {share_name}: {error}") |
828 | 838 | except SessionError as e: |
829 | 839 | error = get_error_string(e) |
830 | 840 | self.logger.debug(f"Error checking WRITE access on share {share_name}: {error}") |
831 | 841 |
|
832 | | - if write: |
| 842 | + try: |
| 843 | + tid = self.conn.connectTree(share_name) |
| 844 | + fid = self.conn.createFile(tid, temp_file, desiredAccess=FILE_SHARE_WRITE, shareMode=FILE_SHARE_DELETE) |
| 845 | + self.conn.closeFile(tid, fid) |
| 846 | + write = True |
| 847 | + share_info["access"].append("WRITE") |
833 | 848 | try: |
834 | | - self.conn.deleteDirectory(share_name, temp_dir) |
| 849 | + self.conn.deleteFile(share_name, temp_file) |
835 | 850 | except SessionError as e: |
836 | 851 | error = get_error_string(e) |
837 | | - self.logger.debug(f"Error DELETING created temp dir {temp_dir} on share {share_name}: {error}") |
| 852 | + if error == 'STATUS_OBJECT_NAME_NOT_FOUND': |
| 853 | + pass |
| 854 | + else: |
| 855 | + self.logger.debug(f"Error DELETING created temp file {temp_file} on share {share_name}") |
| 856 | + except SessionError as e: |
| 857 | + error = get_error_string(e) |
| 858 | + self.logger.debug(f"Error checking WRITE access with file on share {share_name}: {error}") |
838 | 859 |
|
839 | 860 | permissions.append(share_info) |
840 | 861 |
|
|
0 commit comments