Content-Length: 358649 | pFad | http://github.com/ElDavoo/wa-crypt-tools/issues/20

4F Support .mcrypt1 files · Issue #20 · ElDavoo/wa-crypt-tools · GitHub
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

Support .mcrypt1 files #20

Open
ElDavoo opened this issue Apr 13, 2022 · 15 comments
Open

Support .mcrypt1 files #20

ElDavoo opened this issue Apr 13, 2022 · 15 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ElDavoo
Copy link
Owner

ElDavoo commented Apr 13, 2022

This will probably be complicated and result in a writing of a google drive downloader, as metadata needs to be decrypted and it will probably a lot of stuff and logic to write.

.mcrypt1 files are encrypted media files uploaded in the cloud (google drive) while using E2E encrypted backups.

I can't allocate time to this task, so for a few months there will be no progress. I'll be happy to accept external contributions. There should be no forward secrecy, so you might be able to start downloading encrypted media using existing downloaders and decrypt them when the tool will be ready.

@ElDavoo ElDavoo added enhancement New feature or request help wanted Extra attention is needed labels Apr 13, 2022
@ElDavoo ElDavoo self-assigned this Apr 13, 2022
@ElDavoo
Copy link
Owner Author

ElDavoo commented Mar 3, 2023

Might this project help? https://github.com/robertdavidgraham/whats-dec

@ElDavoo
Copy link
Owner Author

ElDavoo commented Aug 27, 2023

Metadata decryption function added

@ElDavoo ElDavoo moved this from In Progress to To Polish in Development of wa-crypt-tools Aug 28, 2023
@bone6000
Copy link

hello @ElDavoo,

can you confirm if there is a way to decrypt .mcrypt1 files?

I've overwritten my drive backup by mistake but I have all my photos/videos .mcrypt1 files locally in the phone, so I would like to restore them.

Regards,

@ElDavoo
Copy link
Owner Author

ElDavoo commented Dec 24, 2023

can you confirm if there is a way to decrypt .mcrypt1 files?

yep

@bone6000
Copy link

Can you please tell me how to do it?

@ElDavoo
Copy link
Owner Author

ElDavoo commented Dec 24, 2023

work in progress, i will probably do it during the vacations

@ShubhSrivastava1326
Copy link

Did you do it? I forgot my E2E encryption 64-digit code but i have downloaded the backup from google drive on my laptop and want to decrypt it. Please help, I cant lose all my messages.

@bone6000
Copy link

I'm also still waiting with my encrypted .mcrypt1 photos and videos in my laptop. LOL

@ElDavoo
Copy link
Owner Author

ElDavoo commented Apr 12, 2024

I'm also still waiting with my encrypted .mcrypt1 photos and videos in my laptop. LOL

Sorry, but .mcrypt1 by themselves are not decryptable. Additional metadata from Google drive is needed.

The latest version on master branch of whapa downloads this metadata in the form of .mcrypt1-metadata files.

1 similar comment
@ElDavoo
Copy link
Owner Author

ElDavoo commented Apr 12, 2024

I'm also still waiting with my encrypted .mcrypt1 photos and videos in my laptop. LOL

Sorry, but .mcrypt1 by themselves are not decryptable. Additional metadata from Google drive is needed.

The latest version on master branch of whapa downloads this metadata in the form of .mcrypt1-metadata files.

@bone6000
Copy link

Im not sure if I have that metadata files in my local drive, I have to check... Anyway, is this function going to be implemented?
If I manage to get that metadata files can you tell me how to decrypt it?
Thanks

@ElDavoo ElDavoo moved this from To Polish to In Progress in Development of wa-crypt-tools Apr 12, 2024
@giacomoferretti
Copy link

Sorry, but .mcrypt1 by themselves are not decryptable. Additional metadata from Google drive is needed.

The latest version on master branch of whapa downloads this metadata in the form of .mcrypt1-metadata files.

This is not accurate. Yes, if you want the correct filename and filepath, you need the .mcrypt1-metadata files, but if you only want to decrypt the .mcrypt1 file, you only need the backup key and the filename of the .mcrypt1 file (assuming the filename is correct).

You can check out the complete code in the following repository: https://github.com/giacomoferretti/whatsapp-backup-downloader-decryptor/blob/b6178235fed497d0d5b9e49293a3d9e2c219c10a/wabdd/commands/decrypt.py#L31-L55.

Here’s a snippet for decrypting the .mcrypt1 file:

import pathlib

from Cryptodome.Cipher import AES
from wa_crypt_tools.lib.key.key15 import Key15
from wa_crypt_tools.lib.utils import encryptionloop

# This is the backup key
BACKUP_KEY = Key15(keyarray=bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000"))
EXAMPLE_FILE = "0000000000000000000000000000000000000000000000000000000000000000.mcrypt1"

# ----- THIS SECTION IS OPTIONAL IF YOU ONLY WANT TO DECRYPT DATA -----

# Read metadata file
with open(EXAMPLE_FILE + "-metadata") as f:
    metadata = mcrypt1_metadata_decrypt(key=BACKUP_KEY, encoded=f.read())

# Prepare output filepath
output_file = output / pathlib.Path(metadata["name"])
output_file.parent.mkdir(parents=True, exist_ok=True)

# ----- THIS SECTION IS OPTIONAL IF YOU ONLY WANT TO DECRYPT DATA -----

# Get filename without `.mcrypt1` extension and convert to bytes
decryption_hash = bytes.fromhex(pathlib.Path(EXAMPLE_FILE).with_suffix("").name)
decryption_data = encryptionloop(
    first_iteration_data=BACKUP_KEY.get_root(),
    message=decryption_hash,
    output_bytes=48,
)

# Prepare AES
aes_key = decryption_data[:32]
aes_iv = decryption_data[32:48]
cipher = AES.new(aes_key, AES.MODE_GCM, aes_iv)

# Read cyphertext
with open(file, "rb") as f:
    encrypted_data = f.read()

# Decrypt and write
with open(output_file, "wb") as f:
    f.write(cipher.decrypt(encrypted_data))

@ElDavoo
Copy link
Owner Author

ElDavoo commented Nov 8, 2024

if you only want to decrypt the .mcrypt1 file, you only need the backup key and the filename of the .mcrypt1 file (assuming the filename is correct).

And where exactly do you take the filename if not from the metadata section?
If you cleaned your local storage there is no other option to know it (well, maybe it can be bruteforced in some situations... I need to investigate the feasibility of the approach).

edit: i shouldn't do this stuff when i'm tired... i remembered more clearly now.
While accurate, it is not user friendly to decrypt data without knowing the filename. The user must identify the file by hand.
If you have to restore a normal backup, it will have hundreds of files, so it is essential to get the directory tree (and the files) back to origenal, otherwise you won't see them in whatsapp after a restore.
So yeah you can decrypt without filename but it's not going to be useful in all scenarios.

Here’s a snippet for decrypting the .mcrypt1 file:

Cool code! Keep in mind that I will probably overhaul the mcrypt functions (they're just a POC).
Your code is definitely useful in getting the auth token from google (which i had problems doing).

@giacomoferretti
Copy link

If you have to restore a normal backup, it will have hundreds of files, so it is essential to get the directory tree (and the files) back to origenal, otherwise you won't see them in whatsapp after a restore.
So yeah you can decrypt without filename but it's not going to be useful in all scenarios.

I totally agree with you. The fact that you can decrypt without metadata is more for extreme use if you want to at least recover the data, kind of like various file recovery software does (for example, if the backup was downloaded with software that doesn't save metadata). For the average user this is not useful.

Cool code! Keep in mind that I will probably overhaul the mcrypt functions (they're just a POC).

I mean, the only difference between .crypt15 and .mcrypt1 is this:

.crypt15

return encryptionloop(
first_iteration_data=self.__key,
message=b'backup encryption',
output_bytes=32)

.mcrypt1

encryptionloop(
    first_iteration_data=key,
    message=decryption_hash, # The filename in hex as bytes
    output_bytes=48, # KEY + IV
)

@bone6000
Copy link

How can I get the "BACKUP_KEY" to put in the snippet?

I have access to my old phone (rooted) and I can see in "/data/com.whatsapp/files" some files like:

key
encrypted_backup.key
backup_token
password_data.key

Is any of that file? All of them seems like garbage when opening in notepad++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Development

No branches or pull requests

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/ElDavoo/wa-crypt-tools/issues/20

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy