python-ransomware icon indicating copy to clipboard operation
python-ransomware copied to clipboard

Decryptions leaves old encrypted data

Open Gaunah opened this issue 5 years ago • 3 comments

Issue: If the encrypted base64 string is larger than the original file the f.write(data) will expand the file, while the decryption will f.seek(0) to the start of the file and write the original content but will leave a part of the encrypted base64 string at the "end" of the file.

fix: Use f.truncate(0) in addition to f.seek(0)

steps to reproduce:

echo "test" > test.txt
python main.py --action encrypt
cat test.txt
python main.py --action decrypt --keyfile keyfile
cat test.txt

Gaunah avatar Apr 12 '19 13:04 Gaunah

Worked thx :)

xM-Gx avatar Aug 20 '19 12:08 xM-Gx

got any fix?

SwapnilSoni1999 avatar Mar 14 '20 08:03 SwapnilSoni1999

Found it! f.truncate() will fix

f.seek(0)
f.write(data)
f.truncate()

SwapnilSoni1999 avatar Mar 14 '20 08:03 SwapnilSoni1999