|
72 | 72 | DirectTCP, |
73 | 73 | FileAllInformation, |
74 | 74 | FileIdBothDirectoryInformation, |
75 | | - SMB_DIALECTS, |
| 75 | + SECURITY_DESCRIPTOR, |
| 76 | + SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2, |
| 77 | + SMB2_CREATE_REQUEST_LEASE, |
| 78 | + SMB2_CREATE_REQUEST_LEASE_V2, |
76 | 79 | SMB2_Change_Notify_Request, |
77 | 80 | SMB2_Change_Notify_Response, |
78 | 81 | SMB2_Close_Request, |
79 | 82 | SMB2_Close_Response, |
80 | 83 | SMB2_Create_Context, |
81 | | - SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2, |
82 | | - SMB2_CREATE_REQUEST_LEASE_V2, |
83 | | - SMB2_CREATE_REQUEST_LEASE, |
84 | 84 | SMB2_Create_Request, |
85 | 85 | SMB2_Create_Response, |
86 | 86 | SMB2_ENCRYPTION_CIPHERS, |
|
111 | 111 | SMB2_Write_Request, |
112 | 112 | SMB2_Write_Response, |
113 | 113 | SMBStreamSocket, |
| 114 | + SMB_DIALECTS, |
114 | 115 | SRVSVC_SHARE_TYPES, |
115 | 116 | STATUS_ERREF, |
116 | 117 | ) |
@@ -1822,6 +1823,96 @@ def backup(self): |
1822 | 1823 | print("Backup Intent: On") |
1823 | 1824 | self.extra_create_options.append("FILE_OPEN_FOR_BACKUP_INTENT") |
1824 | 1825 |
|
| 1826 | + @CLIUtil.addcommand(spaces=True) |
| 1827 | + def watch(self, folder): |
| 1828 | + """ |
| 1829 | + Watch file changes in folder (recursively) |
| 1830 | + """ |
| 1831 | + if self._require_share(): |
| 1832 | + return |
| 1833 | + # Get pwd of the ls |
| 1834 | + fpath = self.pwd / folder |
| 1835 | + self.smbsock.set_TID(self.current_tree) |
| 1836 | + # Open file |
| 1837 | + fileId = self.smbsock.create_request( |
| 1838 | + self.normalize_path(fpath), |
| 1839 | + type="folder", |
| 1840 | + extra_create_options=self.extra_create_options, |
| 1841 | + ) |
| 1842 | + print("Watching '%s'" % fpath) |
| 1843 | + # Watch for changes |
| 1844 | + try: |
| 1845 | + while True: |
| 1846 | + changes = self.smbsock.changenotify(fileId) |
| 1847 | + for chg in changes: |
| 1848 | + print(chg.sprintf("%.time%: %Action% %FileName%")) |
| 1849 | + except KeyboardInterrupt: |
| 1850 | + pass |
| 1851 | + # Close the file |
| 1852 | + self.smbsock.close_request(fileId) |
| 1853 | + print("Cancelled.") |
| 1854 | + |
| 1855 | + @CLIUtil.addcommand(spaces=True) |
| 1856 | + def getsd(self, file): |
| 1857 | + """ |
| 1858 | + Get the Security Descriptor |
| 1859 | + """ |
| 1860 | + if self._require_share(): |
| 1861 | + return |
| 1862 | + fpath = self.pwd / file |
| 1863 | + self.smbsock.set_TID(self.current_tree) |
| 1864 | + # Open file |
| 1865 | + fileId = self.smbsock.create_request( |
| 1866 | + self.normalize_path(fpath), |
| 1867 | + type="", |
| 1868 | + mode="", |
| 1869 | + extra_desired_access=["READ_CONTROL", "ACCESS_SYSTEM_SECURITY"], |
| 1870 | + ) |
| 1871 | + # Get the file size |
| 1872 | + info = self.smbsock.query_info( |
| 1873 | + FileId=fileId, |
| 1874 | + InfoType="SMB2_0_INFO_SECURITY", |
| 1875 | + FileInfoClass=0, |
| 1876 | + AdditionalInformation=( |
| 1877 | + 0x00000001 |
| 1878 | + | 0x00000002 |
| 1879 | + | 0x00000004 |
| 1880 | + | 0x00000008 |
| 1881 | + | 0x00000010 |
| 1882 | + | 0x00000020 |
| 1883 | + | 0x00000040 |
| 1884 | + | 0x00010000 |
| 1885 | + ), |
| 1886 | + ) |
| 1887 | + self.smbsock.close_request(fileId) |
| 1888 | + return info |
| 1889 | + |
| 1890 | + @CLIUtil.addcomplete(getsd) |
| 1891 | + def getsd_complete(self, file): |
| 1892 | + """ |
| 1893 | + Auto-complete getsd |
| 1894 | + """ |
| 1895 | + if self._require_share(silent=True): |
| 1896 | + return [] |
| 1897 | + return self._fs_complete(file) |
| 1898 | + |
| 1899 | + @CLIUtil.addoutput(getsd) |
| 1900 | + def getsd_output(self, results): |
| 1901 | + """ |
| 1902 | + Print the output of 'getsd' |
| 1903 | + """ |
| 1904 | + sd = SECURITY_DESCRIPTOR(results) |
| 1905 | + print("Owner:", sd.OwnerSid.summary()) |
| 1906 | + print("Group:", sd.GroupSid.summary()) |
| 1907 | + if getattr(sd, "DACL", None): |
| 1908 | + print("DACL:") |
| 1909 | + for ace in sd.DACL.Aces: |
| 1910 | + print(" - ", ace.toSDDL()) |
| 1911 | + if getattr(sd, "SACL", None): |
| 1912 | + print("SACL:") |
| 1913 | + for ace in sd.SACL.Aces: |
| 1914 | + print(" - ", ace.toSDDL()) |
| 1915 | + |
1825 | 1916 |
|
1826 | 1917 | if __name__ == "__main__": |
1827 | 1918 | from scapy.utils import AutoArgparse |
|
0 commit comments