Closed massimiliano-dalcero closed 5 months ago
You cannot delete an enumerable object directly. You should call DeleteInstance() function of wbemservices and specify your instance path, as shown below:
from impacket.dcerpc.v5.dcomrt import DCOMConnection
from impacket.dcerpc.v5.dcom import wmi
from impacket.dcerpc.v5.dtypes import NULL
dcom = DCOMConnection(address, username, password, domain, lmhash, nthash, aesKey, oxidResolver=True, doKerberos=k, kdcHost=dc_ip)
Interface = dcom.CoCreateInstanceEx(wmi.CLSID_WbemLevel1Login, wmi.IID_IWbemLevel1Login)
iWbemLevel1Login = wmi.IWbemLevel1Login(Interface)
iWbemServices = iWbemLevel1Login.NTLMLogin('//./root/cimv2', NULL, NULL)
iWbemServices.DeleteInstance("CIM_DataFile.Name='C:\\\\Users\\\\pippo\\\\ciao.txt'")
dcom.disconnect()
Thanks 🙏 wirks perfectly 😊
Only (and last) question: Where could I have found documentation related to this aspect? I have searched extensively around the web, but without success.
Hello
no, that's not what I meant 😊
I meant in packet documentation or code examples.
Using the Microsoft documentation and powershell I had found the solution but it didn't work with impacket 😉
Hello, I'm trying to delete a file on remote host using WMI, but when I invoke the Delete() method nothing happens. No errors come back, everything seems to have gone well, but it doesn't delete the file.
Below I report the core of the code that I simplified to a minimum for testing
Replicating the code above in powershell on a remote machine on the network and connecting remotly to the target host , everything works fine:
Following the impacket version installed via pip:
Best regards :)