fortra / impacket

Impacket is a collection of Python classes for working with network protocols.
https://www.coresecurity.com
Other
13.53k stars 3.58k forks source link

File broken after editing with MS Excel on Mac #1330

Open igorkostyrko opened 2 years ago

igorkostyrko commented 2 years ago

Configuration

impacket version: 0.9.24 Python version: 3.6.8 Target OS: CentOS

Description

If open XLSX file with MS Excel, edit it and save it then file will be broken. I tested it with MacOS Big Sur and MacOS Monterey. Behavior is the same.

How I tested it

  1. start SMB server on Linux (CentOS)
  2. start Finder on Mac
  3. connect to SMB server with a Finder. Do in the Finder: -- menu Go => Connect to server -- enter: smb://IP_ADDRESS/SHARED_FOLDER_NAME -- enter credentials
  4. create new XLSX file with MS Excel and save on local disk
  5. copy the XLSX file from local disk to the SMB server via the Finder
  6. open the XLSX file from the SMB server via the Finder
  7. edit the file in MS Excel
  8. try to save the file in MS Excel. It fails with error: "The document was saved successfully, but Excel cannot re-open it because of a sharing violation. Please close the document and try to open it again."
  9. if close the document and try to open it again then it fails with error: "We found a problem with some content in 'FILENAME.xlsx'. Do you want us to recover as much as we can?"
  10. if repair the XLSX file with MS Excel and try to save it with a new name in SMB server then MS Excel hangs and SMB server shows the error: "Unknown level for set file info! 0x13"
martingalloar commented 2 years ago

I think this is related to the SMBServer (yet) not implementing all the info levels supported by the protocol. We've been adding some of those in latest PRs (see #1303 or #1147), but some others might be still missing.

  1. Does this happens with SMB1 or SMB2?
  2. Do you think you can provide a traffic capture to get the info level that's being requested by the client and missing on the server side?
igorkostyrko commented 2 years ago

I loaded latest changes from master and tested it again. Behavior is the same. But, now there is no error message on 10th step: "Unknown level for set file info! 0x13"

This happens with SMB2. I created a traffic capture of 6th, 7th and 8th steps of my test: https://storagemadeeasy.com/files/e2310f455facb6386679547a6da35961.pcap

gabrielg5 commented 1 month ago

Hello, Just for the sake of documentation, I've run this test from a Windows system (instead than a Mac) and it worked fine.

Will try to test from a Mac.. also if you can, can you retest, please @igorkostyrko? Let me know how that goes if you do it.

Thanks!