login-securite / DonPAPI

Dumping DPAPI credz remotely
GNU General Public License v3.0
930 stars 110 forks source link

[bug] ImportError: cannot import name 'PrivateKeyTypes' from 'cryptography.hazmat.primitives.asymmetric.types' #57

Closed p0dalirius closed 1 month ago

p0dalirius commented 1 year ago

Hi,

Upon installation with the commands on the README.md, we get an error when starting DonPAPI

root@podaliriuslab:~/DonPAPI# git clone https://github.com/login-securite/DonPAPI.git
Cloning into 'DonPAPI'...
remote: Enumerating objects: 787, done.
remote: Counting objects: 100% (381/381), done.
remote: Compressing objects: 100% (255/255), done.
remote: Total 787 (delta 166), reused 306 (delta 123), pack-reused 406
Receiving objects: 100% (787/787), 3.22 MiB | 26.34 MiB/s, done.
Resolving deltas: 100% (316/316), done.
Processing /root/DonPAPI/DonPAPI
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: LnkParse3<2.0.0,>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from donpapi==1.1.0) (1.2.0)
Requirement already satisfied: M2Crypto<0.39.0,>=0.38.0 in /usr/local/lib/python3.11/dist-packages (from donpapi==1.1.0) (0.38.0)
Requirement already satisfied: impacket<0.10.0,>=0.9.23 in /usr/local/lib/python3.11/dist-packages (from donpapi==1.1.0) (0.9.24)
Requirement already satisfied: pyasn<2.0.0,>=1.6.1 in /usr/local/lib/python3.11/dist-packages (from donpapi==1.1.0) (1.6.1)
Requirement already satisfied: pycryptodome<4.0.0,>=3.11.0 in /usr/local/lib/python3.11/dist-packages (from donpapi==1.1.0) (3.18.0)
Requirement already satisfied: swig<5.0.0,>=4.1.1 in /usr/local/lib/python3.11/dist-packages (from donpapi==1.1.0) (4.1.1)
Requirement already satisfied: wheel<0.38.0,>=0.37.0 in /usr/local/lib/python3.11/dist-packages (from donpapi==1.1.0) (0.37.1)
Requirement already satisfied: chardet in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (5.1.0)
Requirement already satisfied: flask>=1.0 in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (2.2.2)
Requirement already satisfied: future in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (0.18.2)
Requirement already satisfied: ldap3!=2.5.0,!=2.5.2,!=2.6,>=2.5 in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (2.9.1)
Requirement already satisfied: ldapdomaindump>=0.9.0 in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (0.9.3)
Requirement already satisfied: pyOpenSSL>=0.16.2 in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (23.0.0)
Requirement already satisfied: pyasn1>=0.2.3 in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (0.4.8)
Requirement already satisfied: pycryptodomex in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (3.11.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from impacket<0.10.0,>=0.9.23->donpapi==1.1.0) (1.16.0)
Building wheels for collected packages: donpapi
  Building wheel for donpapi (pyproject.toml) ... done
  Created wheel for donpapi: filename=donpapi-1.1.0-py3-none-any.whl size=692882 sha256=b90fce1ca309727c68f25d3c073f6332b9934f6b2d02ebbb185fbe70961a93eb
  Stored in directory: /tmp/pip-ephem-wheel-cache-_fzseqmg/wheels/f5/5d/af/daefae7c43f57686945d3ccdef02147a13c26bf4f09d46030f
Successfully built donpapi
Installing collected packages: donpapi
  Attempting uninstall: donpapi
    Found existing installation: donpapi 1.1.0
    Uninstalling donpapi-1.1.0:
      Successfully uninstalled donpapi-1.1.0
Successfully installed donpapi-1.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

root@podaliriuslab:~/DonPAPI# cd DonPAPI; python3 -m pip install . ; DonPAPI
Traceback (most recent call last):
  File "/usr/local/bin/DonPAPI", line 5, in <module>
    from donpapi.entry import main
  File "/usr/local/lib/python3.11/dist-packages/donpapi/entry.py", line 26, in <module>
    from donpapi.myseatbelt import MySeatBelt
  File "/usr/local/lib/python3.11/dist-packages/donpapi/myseatbelt.py", line 11, in <module>
    from donpapi.lib.certificates import CertificatesTriage
  File "/usr/local/lib/python3.11/dist-packages/donpapi/lib/certificates.py", line 13, in <module>
    from cryptography.hazmat.primitives.asymmetric.types import PrivateKeyTypes
ImportError: cannot import name 'PrivateKeyTypes' from 'cryptography.hazmat.primitives.asymmetric.types' (/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/asymmetric/types.py)                                                                                                                                                                                    

After a bit of research, this is because [cryptography=3.4] has a circular import bug, to fix it you should update to [cryptography=3.4.1].

For anyone having the bug now, you can just do:

root@podaliriuslab:~/DonPAPI# python3 -m pip install cryptography --upgrade
Requirement already satisfied: cryptography in /usr/local/lib/python3.11/dist-packages (3.4.8)
Collecting cryptography
  Using cached cryptography-41.0.2-cp37-abi3-manylinux_2_28_x86_64.whl (4.3 MB)
Requirement already satisfied: cffi>=1.12 in /usr/local/lib/python3.11/dist-packages (from cryptography) (1.15.1)
Requirement already satisfied: pycparser in /usr/local/lib/python3.11/dist-packages (from cffi>=1.12->cryptography) (2.21)
Installing collected packages: cryptography
  Attempting uninstall: cryptography
    Found existing installation: cryptography 3.4.8
    Uninstalling cryptography-3.4.8:
      Successfully uninstalled cryptography-3.4.8
Successfully installed cryptography-41.0.2

More infos about the bug: https://cryptography.io/en/latest/changelog/#v3-4-1

7MinSec commented 1 year ago

Just wanted to chime in and THANK YOU for these notes and a fix. I desperately needed this tool on a pentest and your python -m pip install cryptography --upgrade did just the trick!

p0dalirius commented 1 year ago

Glad it helped!

zblurx commented 1 year ago

Thank you @p0dalirius , just merged your fix!

zblurx commented 1 year ago

It causes dependency problems so I revert the PR, gonna work on it

zblurx commented 1 year ago

Which python version are you using ? Did you installed DonPAPI on a separated virtualenv ?

p0dalirius commented 1 year ago

No I was working on a latest Kali without virtualenv. I'll give you more informations in a few days, I can't right now

p0dalirius commented 1 year ago

Here is the complete steps on a Kali machine:

I have installed DonPAPI like this: image

This results in a badass traceback: image image image image

If i reinstall it just after this traceback the error does not reappear:

But DonPAPI still fails with the circular import bug in cryptography image

That is why I tried to add a newer version of cryptography in order to skip the affected version.

Before running python3 -m pip install cryptography --upgrade I have the following packages and versions:

┌──(root㉿kali)-[/home/kali/Desktop/DonPAPI]
└─# python3 -m pip list
Package                      Version
---------------------------- --------------
aardwolf                     0.2.2
acme                         2.1.0
adblockparser                0.7
aesedb                       0.1.3
aiocmd                       0.1.2
aioconsole                   0.3.1
aiodns                       3.0.0
aiofiles                     23.1.0
aiohttp                      3.8.4
aiomultiprocess              0.9.0
aiosignal                    1.3.1
aiosmb                       0.4.4
aiosqlite                    0.17.0
aiowinreg                    0.0.7
ajpy                         0.0.4
altgraph                     0.17.3
aniso8601                    9.0.1
anyio                        3.6.2
appdirs                      1.4.4
arc4                         0.3.0
asciitree                    0.3.3
asgiref                      3.6.0
asn1crypto                   1.5.1
asn1tools                    0.164.0
asttokens                    2.2.1
asyauth                      0.0.9
async-timeout                4.0.2
asysocks                     0.2.2
attrs                        23.1.0
autocommand                  2.2.2
Automat                      22.10.0
awscli                       2.9.19
awscrt                       1.0.0.dev0
Babel                        2.10.3
backcall                     0.2.0
backoff                      2.2.1
bcrypt                       3.2.2
beautifulsoup4               4.11.2
beniget                      0.4.1
bidict                       0.22.1
binwalk                      2.3.3
bitstruct                    8.15.1
blinker                      1.5
bluepy                       1.3.0
boto                         2.49.0
Brlapi                       0.8.4
Brotli                       1.0.9
CacheControl                 0.12.14
censys                       2.1.9
certbot                      2.1.0
certifi                      2023.7.22
cffi                         1.15.1
chardet                      5.1.0
charset-normalizer           3.2.0
cheroot                      9.0.0+ds1
CherryPy                     18.8.0
cherrypy-cors                1.6
chrome-gnome-shell           0.0.0
cleo                         2.0.1
click                        8.1.3
click-plugins                1.1.1
cloud-init                   22.4.2
colorama                     0.4.6
ConfigArgParse               1.5.3
configobj                    5.0.8
constantly                   15.1.0
contourpy                    1.0.7
crackmapexec                 5.4.0
crashtest                    0.4.1
cryptography                 41.0.2
cryptography37               37.0.2
cupshelpers                  1.0
cycler                       0.11.0
dbus-python                  1.3.2
debtags                      2.1
decorator                    5.1.1
Deprecated                   1.2.13
dicttoxml                    1.7.15
diskcache                    5.4.0
distlib                      0.3.7
distro                       1.8.0
distro-info                  1.5
dnslib                       0.9.23
dnspython                    2.3.0
docopt                       0.6.2
docutils                     0.19
donpapi                      1.1.0
donut-shellcode              0.9.3
dropbox                      11.34.0
dsinternals                  1.2.4
dulwich                      0.20.50
et-xmlfile                   1.0.1
exceptiongroup               1.1.0
executing                    1.2.0
ExifRead                     3.0.0
fastapi                      0.92.0
fastimport                   0.9.14
fierce                       1.5.0
filelock                     3.12.2
flasgger                     0.9.5
Flask                        2.2.2
Flask-RESTful                0.3.9
Flask-SocketIO               5.3.2
fonttools                    4.38.0
frozenlist                   1.3.3
fs                           2.4.16
future                       0.18.2
gast                         0.5.2
GDAL                         3.6.2
gpg                          1.18.0
greenlet                     2.0.2
h11                          0.14.0
h2                           4.1.0
hashID                       3.1.4
hpack                        4.0.0
html5lib                     1.1
httpagentparser              1.9.1
httpcore                     0.16.3
httpx                        0.23.3
humanize                     0.0.0
hyperframe                   6.0.0
hyperlink                    21.0.0
idna                         3.4
impacket                     0.9.24
importlib-metadata           6.8.0
incremental                  21.3.0
inflect                      2.1.0
iniconfig                    1.1.1
invoke                       2.0.0
ipwhois                      1.2.0
IPy                          1.1
ipython                      8.5.0
itsdangerous                 2.1.2
jaraco.classes               3.3.0
jaraco.collections           3.8.0
jaraco.context               4.2.0
jaraco.functools             3.5.0
jaraco.text                  3.11.1
jdcal                        1.0
jedi                         0.18.2
jeepney                      0.8.0
Jinja2                       3.1.2
jmespath                     1.0.1
josepy                       1.13.0
jq                           1.2.1
jsonpatch                    1.32
jsonpointer                  2.3
jsonschema                   4.18.4
jsonschema-specifications    2023.7.1
kaitaistruct                 0.10
kali-tweaks                  2023.2.2
keyring                      23.13.1
KismetCaptureBtGeiger        2021.7.1
KismetCaptureFreaklabsZigbee 2018.7.0
KismetCaptureRtl433          2020.10.1
KismetCaptureRtladsb         2020.10.1
KismetCaptureRtlamr          2020.10.1
kiwisolver                   0.0.0
ldap3                        2.9.1
ldapdomaindump               0.9.3
libevdev                     0.5
lightdm-gtk-greeter-settings 1.2.2
limits                       2.8.0
LnkParse3                    1.2.0
lockfile                     0.12.2
louis                        3.24.0
lsassy                       3.1.6
lxml                         4.9.2
lz4                          4.0.2+dfsg
M2Crypto                     0.38.0
macholib                     1.16.2
Mako                         1.2.4.dev0
Markdown                     3.4.1
markdown-it-py               2.1.0
MarkupSafe                   2.1.2
masky                        0.1.1
matplotlib                   3.6.3
matplotlib-inline            0.1.6
mdurl                        0.1.2
mechanize                    0.4.8
minidump                     0.0.21
minikerberos                 0.4.0
mistune0                     0.8.4
mitmproxy                    9.0.1
more-itertools               9.1.0
mpmath                       0.0.0
msgpack                      1.0.5
msldap                       0.4.7
multidict                    6.0.4
mysqlclient                  1.4.6
nassl                        5.0.1
neo4j                        5.2.dev0
neobolt                      1.7.17
neotime                      1.7.4
netaddr                      0.8.0
netifaces                    0.11.0
networkx                     2.8.8
ntpsec                       1.2.2
numpy                        1.24.2
oauthlib                     3.2.2
olefile                      0.46
onboard                      1.4.1
openpyxl                     3.0.9
oscrypto                     1.3.0
packaging                    23.1
paramiko                     2.12.0
parsedatetime                2.6
parso                        0.8.3
passlib                      1.7.4
patator                      0.9
pcapy                        0.11.5.dev0
pefile                       2023.2.7
pexpect                      4.8.0
phonenumbers                 8.12.57
pickleshare                  0.7.5
Pillow                       9.4.0
pip                          23.0.1
pkginfo                      1.9.6
platformdirs                 2.6.2
pluggy                       1.0.0+repack
pluginbase                   1.0.1
ply                          3.11
poetry                       1.3.2
poetry-core                  1.4.0
poetry-plugin-export         1.3.1
portend                      3.1.0
prettytable                  3.6.0
prompt-toolkit               3.0.36
protobuf                     4.21.12
psycopg2                     2.9.5
ptyprocess                   0.7.0
publicsuffix2                2.20191221
publicsuffixlist             0.9.3
pure-eval                    0.0.0
py                           1.11.0
pyasn                        1.6.1
pyasn1                       0.4.8
pyasn1-modules               0.2.8
pycairo                      1.20.1
pycares                      4.3.0
pycparser                    2.21
pycryptodome                 3.18.0
pycryptodomex                3.11.0
pycups                       2.0.1
pycurl                       7.45.2
pydantic                     1.10.4
PyDispatcher                 2.0.5
pydot                        1.4.2
pyee                         9.0.4
pygame                       2.1.2
pygexf                       0.2.2
Pygments                     2.14.0
PyGObject                    3.42.2
pygraphviz                   1.7
PyHamcrest                   2.0.3
PyICU                        2.10.2
pyinotify                    0.9.6
PyInstaller                  3.5+498e6ee058
PyJWT                        2.6.0
pylev                        1.4.0
pylnk3                       0.4.2
pyminifier                   2.1
pymssql                      2.2.2
PyMySQL                      1.0.2
PyNaCl                       1.5.0
PyOpenGL                     3.1.6
pyOpenSSL                    23.0.0
pyparsing                    3.0.9
PyPDF2                       2.12.1
pyperclip                    1.8.2
pypng                        0.20220715.0
pyppeteer                    1.0.1
pypsrp                       0.8.1
pypykatz                     0.6.6
PyQt5                        5.15.9
PyQt5-sip                    12.11.1
PyQt6                        6.4.2
PyQt6-sip                    13.4.1
pyqtgraph                    0.13.1
pyRFC3339                    1.1
pyrsistent                   0.18.1
pyserial                     3.5
pysmbc                       1.0.23
pysmi                        0.3.2
pysnmp                       4.4.12
PySocks                      1.7.1
pyspnego                     0.8.0
pytest                       7.2.1
python-apt                   2.5.3
python-dateutil              2.8.2
python-debian                0.1.49
python-docx                  0.8.11
python-dotenv                0.21.0
python-engineio              4.3.4
python-magic                 0.4.26
python-multipart             0.0.5
python-pptx                  0.6.18
python-socketio              5.7.2
pythran                      0.11.0
pytz                         2022.7.1
pyudev                       0.24.0
pyVNC                        0.1
pywerview                    0.3.3
pyxdg                        0.28
PyYAML                       6.0
qrcode                       7.4.2
rapidfuzz                    2.15.1
redis                        4.3.4
referencing                  0.30.0
repoze.lru                   0.7
requests                     2.31.0
requests-toolbelt            0.10.1
retrying                     1.3.3
rfc3986                      1.5.0
rfc3987                      1.3.8
rich                         13.3.1
roman                        3.3
Routes                       2.5.1
rpds-py                      0.9.2
rq                           1.13.0
ruamel.yaml                  0.17.21
ruamel.yaml.clib             0.2.7
scapy                        2.5.0
scipy                        1.10.1
SecretStorage                3.3.3
secure                       0.3.0
service-identity             18.1.0
setuptools                   66.1.1
shellingham                  1.5.0.post1
shodan                       1.28.0
simplejson                   3.18.3
six                          1.16.0
slowapi                      0.1.4
sniffio                      1.2.0
sortedcontainers             2.4.0
soupsieve                    2.3.2
SQLAlchemy                   1.4.46
SQLAlchemy-Utc               0.14.0
sslyze                       5.1.3
stack-data                   0.6.2
starlette                    0.26.1
stone                        3.3.1
swig                         4.1.1
sympy                        1.11.1
tempora                      5.1.0
termcolor                    1.1.0
terminaltables               3.1.10
texttable                    1.6.7
theHarvester                 4.2.0
tls-parser                   1.2.2
tomli                        2.0.1
tomlkit                      0.11.8
tornado                      6.2
tqdm                         4.64.1
traitlets                    5.5.0
trove-classifiers            2023.7.6
Twisted                      22.4.0
typing_extensions            4.4.0
ufoLib2                      0.14.0
ujson                        5.7.0
unattended-upgrades          0.1
unicodecsv                   0.14.1
unicodedata2                 15.0.0
unicrypto                    0.0.10
uritemplate                  4.1.1
urllib3                      1.26.16
urwid                        2.1.2
uvicorn                      0.17.6
uvloop                       0.17.0
virtualenv                   20.21.1
wafw00f                      2.2.0
wcwidth                      0.2.5
webcolors                    1.11.1
webencodings                 0.5.1
WebOb                        1.8.6
websocket-client             1.2.3
websockets                   10.4
websockify                   0.10.0
Werkzeug                     2.2.2
wfuzz                        3.1.0
wheel                        0.37.1
whois                        0.8
wifite                       2.6.6
winacl                       0.1.7
wrapt                        1.14.1
wsproto                      1.2.0
xdg                          5
xlrd                         1.2.0
XlsxWriter                   3.0.2
xlutils                      2.0.0
xlwt                         1.3.0
xmltodict                    0.13.0
yara-python                  4.2.0
yarl                         1.8.2
zc.lockfile                  2.0
zipp                         3.16.2
zlib-wrapper                 0.1.3
zope.interface               5.5.2

I am now running the fix python3 -m pip install cryptography --upgrade

image

Now I have only the following difference:

image

This was with a local install of DonPAPI with python3 -m pip install .. Install using poetry also fails for another reason specified here #61

zblurx commented 1 year ago

I've just updated dependencies in the project. Can you recheck ? Also, please always install python tools in dedicated virtualenv, with pipx for example

zblurx commented 1 month ago

closing now. feel free to reopen if this appends again