0

I need to determine the last modification date of a file obtained via the SMB Protocol. I am using a machine running RHEL 7.5, Python 2.7.5, and SMB Protocol version 1.5.1.

I tried the following, but it says that the attribute 'query_information' does not exist.

current_file_open = Open(tree, full_file_path)
current_file_open.create(
 desired_access=FilePipePrinterAccessMask.GENERIC_READ,
 file_attributes=0x80, # FILE_ATTRIBUTE_NORMAL
 share_access=1,
 create_disposition=CreateDisposition.FILE_OPEN,
 create_options=0,
 impersonation_level=2
)
 
file_details = current_file_open.query_information()
asked Mar 26, 2025 at 11:44
1
  • Open() is not a Python function, so it's unclear what you're doing. Please extract a minimal reproducible example from your code and provide that here. That said, why are you using a Python version that is obsolete? Looking at the code, it reminds me a bit of the Windows API, which is additionally confusing. Commented Mar 26, 2025 at 18:24

1 Answer 1

0

The problem is that the query_information() method doesn't exist in the SMB implementation you're using. You need to use the correct query method based on your SMB library.

Looking at your code, I'm guessing you're using Impacket. Here's how to fix it:

from impacket.smb3structs import FILE_BASIC_INFORMATION
current_file_open = Open(tree, full_file_path)
current_file_open.create(
 desired_access=FilePipePrinterAccessMask.GENERIC_READ,
 file_attributes=0x80, # FILE_ATTRIBUTE_NORMAL
 share_access=1,
 create_disposition=CreateDisposition.FILE_OPEN,
 create_options=0,
 impersonation_level=2
)
# Replace query_information() with query_info()
file_info = current_file_open.query_info(FILE_BASIC_INFORMATION)
last_write_time = file_info['LastWriteTime']
# To convert to a readable datetime
from datetime import datetime
from impacket.dcerpc.v5.dtypes import FileTime
timestamp = FileTime(last_write_time).get_datetime()
print(timestamp)

I ran into this same issue a while back. The key is that Impacket requires you to specify what kind of information you want with an information class like FILE_BASIC_INFORMATION.

If this doesn't work, let me know which specific SMB library you're importing from - there are several implementations with slightly different APIs.

Edit: If you're getting import errors with the above, make sure you have the full Impacket package installed. Try pip install impacket to get the latest version.

answered Apr 7, 2025 at 11:22
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.