LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 12-29-2017, 06:27 PM   #1
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 759

Rep: Reputation: 39
GPG file encryption prevents restore source file?


After encrypting file with gpg I have deleted source file (the unencrypted one).
For curiosity, i undeleted removed source file.
It turned out that the recovered file is encrypted with GPG!

Question:
how is that possible that recovered file is encrypted? I removed unencrypted/source file.

Last edited by czezz; 01-01-2018 at 05:14 PM.
 
Old 01-02-2018, 07:52 AM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169
"Un-deleting" is not a predictable process – usually, it can't be done.

GPG will not overwrite or replace the file that it is encrypting, unless you want it to.
 
Old 01-02-2018, 02:30 PM   #3
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 759

Original Poster
Rep: Reputation: 39
Hi Sundialsvcs, thanks for reply.

1. How can I tell GPG to to overwrite or replace source file?
2. I do agree with un-delete statement although small .txt files are quite successful to recover.
Also, I have quite successful un-delete results with software from this guys: https://www.cgsecurity.org/

Anyway, file that I recovered in my test was somehow GPG encrypted (and I am able to decrypt it with this same password).
I have repeated this test number of times.
I have created a small container for this test, so no other disk operation before on this file system.

How on earth is that possible ?!?
 
Old 01-03-2018, 09:46 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169
Categorically speaking, filesystems do not support "un-deletion" and cannot do it reliably. Your Mileage May Vary.™

Although "secure delete" (overwrite ...) utilities do exist, once again you cannot be certain that they will, in fact, overwrite the data in every case. All applications must rely on the filesystem to perform all physical I/O and disk-space allocation tasks. You should never assume that fragments of your data – or, all of it – might not be recoverable by a forensic examination of the media.

So, continue to physically protect that media from theft and so forth. And, don't try to use computers to break the law.
 
Old 01-03-2018, 12:37 PM   #5
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 759

Original Poster
Rep: Reputation: 39
Question

Huh ???

Anyway, lets get back to the topic:
After encrypting file with gpg I have deleted source file (the unencrypted one).
I managed to undeleted it quite easily.
However (and this is actually good), it turned out that the recovered file is encrypted with GPG!

Questions:
1. Is there any syntax/switch to force gpg encryption to overwrite/destroy source file (yes, I know about /dev/urandom. Here I have actually even more interesting findings by overwriting gpg source file with /dev/urandom).
2. Does anyone know how come un-deleted source file is gpg encrypted?

Here it is how the restored and decrypted file looks like:
Code:
~/Desktop/x/recup_dir.1$ gpg -d f0002646.gpg 
gpg: AES encrypted data
gpg: encrypted with 1 passphrase
oeri test test test 
gpg: [don't know]: invalid packet (ctb=6c)
gpg: WARNING: encrypted message has been manipulated!
gpg: [don't know]: invalid packet (ctb=70)

Last edited by czezz; 01-03-2018 at 12:51 PM.
 
Old 01-03-2018, 06:57 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,362

Rep: Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514
Are you saying the sequence of events is

1. Encrypt source file, producing message.txt.gpg, message.txt still exists
2. rm message.txt
3. Attempt to undelete message.txt, recover only encrypted data

I don't believe there is anything gpg could be doing to destroy the data in step 2, since it is not even being run at that point. It is simply a coincidence that you failed to recover the data of message.txt. Since it is a small test file that you created recently, maybe it stayed in cache, and was never actually written to disk?
 
Old 01-04-2018, 04:01 AM   #7
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 759

Original Poster
Rep: Reputation: 39
Yes, that is exactly the sequence!
Following your advice, I have reproduced scenario with big file - over 100mb. And in this case, recovery output was split into a few UNENCRYPTED files (content looks good).

Then I reproduced the case scenario with small file again.
This time however, I did system shutdown/start up a couple of times (after gpg encryption and after file deletion) to make sure there is no cache leftovers. (i do the test in a small LUKS container, to isolate filesystem)

Recovery output is ENCRYPTED file, though.
That really blows my mind – why?

Additional question: what is the best practice once file is encrypted with gpg? Overwrite source with /dev/urandom ?

Last edited by czezz; 01-04-2018 at 06:31 AM.
 
Old 01-04-2018, 07:37 AM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,362

Rep: Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514
Quote:
Originally Posted by czezz View Post
Then I reproduced the case scenario with small file again.
This time however, I did system shutdown/start up a couple of times (after gpg encryption and after file deletion) to make sure there is no cache leftovers. (i do the test in a small LUKS container, to isolate filesystem)

Recovery output is ENCRYPTED file, though.
That really blows my mind why?
The shutdown procedure may have overwritten the deleted unencrypted data blocks.
 
Old 01-04-2018, 07:54 AM   #9
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 759

Original Poster
Rep: Reputation: 39
Maybe... but I repeated this same (shutdowns) for big file too. All the chunks of restored file are UNENCRYPTED.
 
Old 01-04-2018, 08:28 AM   #10
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,362

Rep: Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514Reputation: 1514
Quote:
Originally Posted by czezz View Post
Maybe... but I repeated this same (shutdowns) for big file too. All the chunks of restored file are UNENCRYPTED.
Large files/chunks may be handled differently from small ones.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] gpg: WARNING: unsafe permissions on configuration file `/home/b/.gnupg/options' gpg: widda Mandriva 9 07-30-2018 07:49 AM
LXer: Flat File Encryption with OpenSSL and GPG LXer Syndicated Linux News 0 04-04-2017 04:42 PM
Need simple process for File Encryption and decryption using gpg command in Linux lakshmi@Linux Linux - Newbie 8 03-16-2017 02:40 AM
LXer: The best file encryption software in open source group test LXer Syndicated Linux News 0 08-08-2011 01:00 PM
GPG - encode file while manipulating output file name itmozart Linux - Newbie 2 10-03-2009 12:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration