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

Recovering #1

Open
doctormo opened this issue Jun 27, 2019 · 6 comments
Open

Recovering #1

doctormo opened this issue Jun 27, 2019 · 6 comments

Comments

@doctormo
Copy link

I have a backup which suffers from the Bad MAC issue. This tool can decrypt it and stores all the various bits of information.

I did have to fix one thing. __handle_statement was trying to create a table called sqlite_sequence so I special excepted it out. Apparently in my version of sqlite (Ubuntu 18.04) it's a special value.

What I need now is the ability to repack the information I have to reconstruct a clean backup. This looks like it should be possible to do, but I'd like to hear your expertise on if you think this is even possible.

@pshem
Copy link

pshem commented Apr 15, 2020

I'm running into the same bug as @doctormo :

Traceback (most recent call last):
  File "/home/pshem/z/source/debruitage/debruitage/bin/signal-bkp-decrypt", line 11, in <module>
    load_entry_point('signal-backup-manager', 'console_scripts', 'signal-bkp-decrypt')()
  File "/home/pshem/z/source/debruitage/signal_backup_manager/cli.py", line 23, in run
    bkp = SignalBackup(args.backup_file, args.passphrase)
  File "/home/pshem/z/source/debruitage/signal_backup_manager/signal_backup.py", line 56, in __init__
    self.__handle_statement(frame.statement)
  File "/home/pshem/z/source/debruitage/signal_backup_manager/signal_backup.py", line 193, in __handle_statement
    self.db_cursor.execute(statement.statement, params)
sqlite3.OperationalError: object name reserved for internal use: sqlite_sequence

Would you mind saying how you fixed it, @doctormo? Trying to catch the exception with

        try:
            self.db_cursor.execute(statement.statement, params)
        except sqlite3.OperationalError:
            pass

Gave me an sqlite3.IntegrityError instead, so I'm assuming you've found a better way.

Traceback (most recent call last):
  File "/home/pshem/z/source/debruitage/debruitage/bin/signal-bkp-decrypt", line 11, in <module>
    load_entry_point('signal-backup-manager', 'console_scripts', 'signal-bkp-decrypt')()
  File "/home/pshem/z/source/debruitage/signal_backup_manager/cli.py", line 23, in run
    bkp = SignalBackup(args.backup_file, args.passphrase)
  File "/home/pshem/z/source/debruitage/signal_backup_manager/signal_backup.py", line 56, in __init__
    self.__handle_statement(frame.statement)
  File "/home/pshem/z/source/debruitage/signal_backup_manager/signal_backup.py", line 193, in __handle_statement
    self.db_cursor.execute(statement.statement, params)
sqlite3.IntegrityError: UNIQUE constraint failed: recipient.group_id

@doctormo
Copy link
Author

diff --git a/signal_backup_manager/signal_backup.py b/signal_backup_manager/signal_backup.py
index 6c2aacd..b8b9c3f 100644
--- a/signal_backup_manager/signal_backup.py
+++ b/signal_backup_manager/signal_backup.py
@@ -190,6 +190,10 @@ class SignalBackup():
             if param.HasField('nullparameter'):
                 params += (param.nullparameter,)
 
+        if 'sqlite_sequence(name,seq)' in statement.statement:
+            print(f"REFUSING: {statement.statement}")
+            return
+        print(f"BEEP: {statement.statement} {params}")
         self.db_cursor.execute(statement.statement, params)
 
     def __handle_preference(self, preference):

@pshem
Copy link

pshem commented Apr 16, 2020

Thanks, I applied your patch but the effects are the same as my try except, so the sqlite3.IntegrityError has got to be a separate issue.

@elkhadiy
Copy link
Owner

@doctormo

I have a backup which suffers from the Bad MAC issue. This tool can decrypt it and stores all the various bits of information.

I did have to fix one thing. __handle_statement was trying to create a table called sqlite_sequence so I special excepted it out. Apparently in my version of sqlite (Ubuntu 18.04) it's a special value.

Yup nice catch, seems like they forgot to drop some tables in the 'new' (been a while since I looked into signal) backup code signalapp/Signal-Android@128da6d

If you send a PR this way with your patch I can merge it if you want.

What I need now is the ability to repack the information I have to reconstruct a clean backup. This looks like it should be possible to do, but I'd like to hear your expertise on if you think this is even possible.

I am by no means an expert on the subject but yeah that was the idea I had when I wrote this tool. Wanted to make a bridging tool to export conversation history from messenger to signal. Last time I worked on it (a while back), I think I was able to create new threads and new messages (should be in the notebooks). And I'm pretty sure it's feasible to re-encrypt the backup with the same passphrase.
Unfortunately I really don't have spare time to work on this right now.

@pshem

Thanks, I applied your patch but the effects are the same as my try except, so the sqlite3.IntegrityError has got to be a separate issue.

Maybe try with if 'sqlite_' in statement.statement:?

@pshem
Copy link

pshem commented Apr 16, 2020

@elkhadiy I tried that and it catches the same single statement as if 'sqlite_sequence(name,seq)' in statement.statement: does. Interestingly, even when erroring out, a valid database is produced, it just lacks the vast majority of data. I'm assuming that's because your tool works frame by frame.

I got the full database out with https://github.com/tbvdm/sigbak/tree/portable

@elkhadiy
Copy link
Owner

@pshem Good to hear! Unfortunately I can't have a crack at it right now but thanks for the input.

Some other good tools out there (from my history):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants