fortra / impacket

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

crypto.py error : new() takes at least 2 arguments (1 given) #349

Closed ThePirateWhoSmellsOfSunflowers closed 6 years ago

ThePirateWhoSmellsOfSunflowers commented 6 years ago

Hi @asolino!

An error is raised when I use impacket on Debian 9.2 fully patched (but not on Kali). The error seems to be raised by the pycrypto lib. Thanks !

:sunflower:

Versions

Both impacket's versions are from a fresh git clone

Debian

$ pip show pycrypto
Name: pycrypto
Version: 2.6.1
Summary: Cryptographic modules for Python.
Home-page: http://www.pycrypto.org/
Author: Dwayne C. Litzenberger
Author-email: dlitz@dlitz.net
License: UNKNOWN
Location: /usr/lib/python2.7/dist-packages
Requires: 

$ dpkg -l | grep python-crypto
ii  python-crypto      2.6.1-7   amd64        cryptographic algorithms...

$ python --version
Python 2.7.13

$ python
Python 2.7.13 (default, Jan 19 2017, 14:48:08) 
[GCC 6.3.0 20170118] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Crypto.Cipher import DES, AES, ARC4
>>> AES_128 = AES.new('AAAAAAAAAAAAAAAA')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: new() takes at least 2 arguments (1 given)
>>>

Kali

# pip show pycrypto
Name: pycrypto
Version: 2.6.1
Summary: Cryptographic modules for Python.
Home-page: http://www.pycrypto.org/
Author: Dwayne C. Litzenberger
Author-email: dlitz@dlitz.net
License: UNKNOWN
Location: /usr/lib/python2.7/dist-packages
Requires: 

# dpkg -l | grep python-crypto
ii  python-crypto      2.6.1-8       amd64        cryptographic algor.....

# python --version
Python 2.7.14

# python
Python 2.7.14 (default, Sep 17 2017, 18:50:44) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Crypto.Cipher import DES, AES, ARC4
>>> AES_128 = AES.new('AAAAAAAAAAAAAAAA')
>>> 

Stack traces (Debian)

$ secretsdump.py -just-dc-ntlm domain/admin@192.168.1.1  -user-status -outputfile domain -debug
Impacket v0.9.16-dev - Copyright 2002-2017 Core Security Technologies

Password:
[+] Exiting NTDSHashes.dump() because new() takes at least 2 arguments (1 given)
[*] Cleaning up... 
Traceback (most recent call last):
  File "/usr/local/bin/secretsdump.py", line 212, in dump
    self.cleanup()
  File "/usr/local/bin/secretsdump.py", line 243, in cleanup
    self.__remoteOps.finish()
  File "/usr/local/lib/python2.7/dist-packages/impacket/examples/secretsdump.py", line 674, in finish
    self.__samr.disconnect()
  File "/usr/local/lib/python2.7/dist-packages/impacket/dcerpc/v5/rpcrt.py", line 804, in disconnect
    return self._transport.disconnect()
  File "/usr/local/lib/python2.7/dist-packages/impacket/dcerpc/v5/transport.py", line 399, in disconnect
    self.__smb_connection.disconnectTree(self.__tid)
  File "/usr/local/lib/python2.7/dist-packages/impacket/smbconnection.py", line 384, in disconnectTree
    raise SessionError(e.get_error_code(), e.get_error_packet())
SessionError: SMB SessionError: STATUS_INVALID_PARAMETER(An invalid parameter was passed to a service or function.)
None
[-] SMB SessionError: STATUS_INVALID_PARAMETER(An invalid parameter was passed to a service or function.)
[*] Cleaning up... 

$ ./pywerview.py get-netsite -u user -p 'password' -w domain -t 192.168.1.2
Traceback (most recent call last):
  File "./pywerview.py", line 24, in <module>
    main()
  File "/home/xxx/tools/pywerview/pywerview/cli/main.py", line 456, in main
    results = args.func(**parsed_args)
  File "/home/xxx/tools/pywerview/pywerview/cli/helpers.py", line 108, in get_netsite
    ads_path=ads_path, full_data=full_data)
  File "/home/xxx/tools/pywerview/pywerview/requester.py", line 139, in wrapper
    ads_path=ads_path, ads_prefix=ads_prefix)
  File "/home/xxx/tools/pywerview/pywerview/requester.py", line 62, in _create_ldap_connection
    queried_domain = self._get_netfqdn()
  File "/home/xxx/tools/pywerview/pywerview/requester.py", line 52, in _get_netfqdn
    smb.logoff()
  File "/usr/local/lib/python2.7/dist-packages/impacket/smbconnection.py", line 362, in logoff
    return self._SMBConnection.logoff()
  File "/usr/local/lib/python2.7/dist-packages/impacket/smb3.py", line 1292, in logoff
    packetID = self.sendSMB(packet)
  File "/usr/local/lib/python2.7/dist-packages/impacket/smb3.py", line 353, in sendSMB
    self.signSMB(packet)
  File "/usr/local/lib/python2.7/dist-packages/impacket/smb3.py", line 319, in signSMB
    signature = crypto.AES_CMAC(self._Session['SigningKey'], p, len(p))
  File "/usr/local/lib/python2.7/dist-packages/impacket/crypto.py", line 141, in AES_CMAC
    AES_128= AES.new(K)
TypeError: new() takes at least 2 arguments (1 given)
asolino commented 6 years ago

Hey @ThePirateWhoSmellsOfSunflowers ... I had that error when trying to use pycryptodome that writes over Crypto.Cipher package.

Can you check that pycryptodome is not installed there?

Also, please output

Crypto.__doc__
Crypto.__version__
Crypto.Cipher.__doc__
ThePirateWhoSmellsOfSunflowers commented 6 years ago

Yes, good catch!

After pip uninstall pycryptodome, everything is working fine.

With pycryptodome :

>>> import Crypto
>>> Crypto.__doc__
>>> Crypto.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'
>>> Crypto.Cipher.__doc__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Cipher'

Without :

>>> import Crypto
>>> Crypto.__doc__
'Python Cryptography Toolkit\n\nA collection of cryptographic modules implementing various algorithms\nand protocols.\n\nSubpackages:\n\nCrypto.Cipher\n Secret-key (AES, DES, ARC4) and public-key encryption (RSA PKCS#1) algorithms\nCrypto.Hash\n Hashing algorithms (MD5, SHA, HMAC)\nCrypto.Protocol\n Cryptographic protocols (Chaffing, all-or-nothing transform, key derivation\n functions). This package does not contain any network protocols.\nCrypto.PublicKey\n Public-key encryption and signature algorithms (RSA, DSA)\nCrypto.Signature\n Public-key signature algorithms (RSA PKCS#1) \nCrypto.Util\n Various useful modules and functions (long-to-string conversion, random number\n generation, number theoretic functions)\n'
>>> Crypto.__version__
'2.6.1'
>>> Crypto.Cipher.__doc__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Cipher'

Now I have to figure out why I have this package installed :smiley:. Thanks again!

:sunflower:

asolino commented 6 years ago

Good to know @ThePirateWhoSmellsOfSunflowers!

Closing this one.