Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed warnings with Python 3.12 #1695

Merged
merged 3 commits into from
Oct 24, 2024
Merged

Conversation

exploide
Copy link
Contributor

@exploide exploide commented Feb 3, 2024

  1. Python 3.12 is a bit more strict when it comes to backslashes in strings. If it isn't an actual escape sequence like \n then it should be either a raw string or the backslash should be escaped. Fixed a bunch of SyntaxWarning: invalid escape sequence.

  2. The function datetime.datetime.utcnow() has been deprecated, because timezone aware datetime objects should better be used instead. Replaced a lot of occurences of datetime.datetime.utcnow() in the codebase since this was spitting DeprecationWarning: datetime.datetime.utcnow() is deprecated everywhere.

@anadrianmanrique anadrianmanrique added the medium Medium priority item label Feb 6, 2024
@anadrianmanrique
Copy link
Contributor

Thanks for the PR with changes. Although we are not currently supporting officially 3.12, we will do it in the short term. This PR will be taken into account by then.

@exploide
Copy link
Contributor Author

exploide commented Feb 9, 2024

Great. Pushed another commit, because datetime.datetime.utcfromtimestamp() is deprecated likewise.

@exploide
Copy link
Contributor Author

Just rebased this PR to master and fixed further incarnations of the warnings introduced in owneredit.py and dacledit.py.

Now that impacket 0.12.0 is out, I think it's a good time to get rid of the annoying warnings when using Python 3.12.

@sec13b
Copy link

sec13b commented Oct 19, 2024

sudo apt update"
sudo apt install ntpsec-ntpdate -y

python3 --version
Python 3.12.6
Kali 2024.3

/usr/local/lib/python3.12/dist-packages/impacket-0.13.0.dev0

sudo git clone https://github.com/fortra/impacket /opt/impacket
sudo apt install python3-impacket

opt/impacket/examples/GetNPUsers.py:165: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).                                                      
  now = datetime.datetime.utcnow() + datetime.timedelta(days=1)     

/usr/bin/b4bloodV4:84: SyntaxWarning: invalid escape sequence '\ '
banner ="""
Line 84:

banner ="""
  __ )   |  |    __ )   |       _ \    _ \   __ \  
  __ \   |  |    __ \   |      |   |  |   |  |   | 
  |   | ___ __|  |   |  |      |   |  |   |  |   | 
 ____/     _|   ____/  _____| \___/  \___/  ____/  
"""

/usr/bin/b4bloodV4:235: SyntaxWarning: invalid escape sequence '\d'
reg=re.compile("\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")
Line 235:

reg=re.compile("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")

/usr/bin/b4bloodV4:382: SyntaxWarning: invalid escape sequence '|'
os.system("cat shares/anonymous_shares.txt | grep 'READ|Disk' | awk '{print $1}' > shares/shares_.txt")
Line 382:

os.system("cat shares/anonymous_shares.txt | grep 'READ\|Disk' | awk '{print $1}' > shares/shares_.txt")

/usr/bin/b4bloodV4:432: SyntaxWarning: invalid escape sequence '|'
os.system("cat ldapnull.txt | grep -i 'dn: uid|dn: cn=' | awk '{print $2}' | cut -d ',' -f1 | cut -d '=' -f2")

Line 432:

os.system("cat ldapnull.txt | grep -i 'dn: uid\|dn: cn=' | awk '{print $2}' | cut -d ',' -f1 | cut -d '=' -f2")

@exploide
Copy link
Contributor Author

@sec13b The only warning shown in your output which concerns impacket is the DeprecationWarning in GetNPUsers.py. This is already addressed in commit 770cce2 of this PR.

All other warnings you show belong to b4blood and have nothing to do with impacket.

By the way, this doesn't really make sense:

sudo git clone https://github.com/fortra/impacket /opt/impacket
sudo apt install python3-impacket

First you clone impacket from GitHub, then you install the impacket version shipped by the Kali repository. You need to decide whether you want to use the latest development version from GitHub or the package from the Kali repository.

And please consider wrapping your output in

```
Markdown code blocks
```

the next time, which makes the output easier to read.

@anadrianmanrique anadrianmanrique self-assigned this Oct 24, 2024
@anadrianmanrique
Copy link
Contributor

merging this one. Thanks @exploide for the PR!

@anadrianmanrique anadrianmanrique merged commit 835e175 into fortra:master Oct 24, 2024
8 checks passed
@exploide exploide deleted the warnings branch October 24, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium Medium priority item
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants