John The Reaper error solved
John The reaper python2 error solved
Introduction
When using tools like ssh2john
, which is part of the John the Ripper utility suite, you might run into an error like this:
1
2
3
4
5
6
File "/usr/bin/ssh2john", line 194, in <module>
read_private_key(filename)
File "/usr/bin/ssh2john", line 154, in read_private_key
saltstr = data[salt_offset:salt_offset+salt_length].encode("hex")
AttributeError: 'bytes' object has no attribute 'encode'. Did you mean: 'decode'?
This error happens because the script was originally written for Python 2, where you could do:
1
some_bytes.encode("hex")
However, in Python 3—the standard nowadays—that method is no longer valid. Instead, you should use:
1
2
some_bytes.hex()
Or if you’re working with encoded strings:
1
some_bytes.decode('utf-8')
But since the script hasn’t been updated, and you’re using an old version of John the Ripper installed via your package manager (pacman -S john
or apt install john
), it throws this Python error.
The Quick Fix
This problem is easily solved by installing the up-to-date GitHub version of John the Ripper. It’s Python 3 compatible and works smoothly.
On Arch Linux:
1
sudo pacman -S john-git
Or if you’re using yay
:
1
yay -S john-git
On Debian/Ubuntu (if john-git
is available):
1
sudo apt install john-git
If it’s not available, just clone and compile it manually:
1
2
3
git clone https://github.com/openwall/john.git
cd john/src
./configure && make -s clean && make -sj4