(More) Specifics:
- Undoing the protection should include filling in a password.
- The password should be different from the one used with
sudo
or any other passwords that are used for acquiring elevated privileges.
All (possible) solutions and suggestions are welcome! Thanks in advance!
Edit: Perhaps additional specifications:
- With 'displace‘, I mean anything involving that resembles the result of
mv
,cp
(move, cut, copy) or whatsoever. The files should remain in their previously assigned locations/places and should not be able to 'pop up' anywhere. - I require for the files to be unreadable.
- I don't care if it's modifiable or not.
- I don't require this for my whole system! Only for a specific set of files.
It sounds like you want these files to be encrypted.
Someone already suggested encrypting them with GPG, but maybe you want the files themselves to also be isolated, even while their data is encrypted. In that case, consider an encrypted volume. I assume you’re familiar with LUKS - you can encrypt a partition with a different password and disable auto-mount pretty easily. But if you’d rather use a file-based volume, then check out VeraCrypt - it’s a FOSS-ish [1], cross-platform tool that provides this capability. The official documentation is very Windows-focused - the ArchLinux wiki article is a pretty useful Linux focused alternative.
Normal operation is that you use a file to store the volume, which can be “dynamic” with a max size or can be statically sized (you can also directly encrypt a disk partition, but you could do that with LUKS, too). Then, before you can access the files - read or write - you have to enter the password, supply the encryption key, etc., in order to unlock it.
Someone without the password but with permission to modify the file will be capable of corrupting it (which would prevent you from accessing every protected file), but unless they somehow got access to the password they wouldn’t be able to view or modify the protected files.
The big advantage over LUKS is ease of creating/mounting file-based volumes and portability. If you’re concerned about another user deleting your encrypted volume, then you can easily back it up without decrypting it. You can easily load and access it on other systems, too - there are official, stable apps on Windows and Mac, though you’ll need admin access to run them. On Android and iOS options are a bit more slim - EDS on Android and Disk Decipher on iOS. If you’re copying a volume to a Linux system without VeraCrypt installed, you’ll likely still be able to mount it, as dm-crypt has support for VeraCrypt volumes.
- 1 - It’s based on TrueCrypt, which has some less free restrictions, e.g.,
c. Phrase "Based on TrueCrypt, freely available at http://www.truecrypt.org/" must be displayed by Your Product (if technically feasible) and contained in its documentation.”
Someone without the password but with permission to modify the file will be capable of corrupting it (which would prevent you from accessing every protected file), but unless they somehow got access to the password they wouldn’t be able to view or modify the protected files.
Is it possible to force a corruption if a disk clone is attempted?
Is it possible to force a corruption if a disk clone is attempted?
Anything that corrupts a single file would work. You could certainly change your own disk cloning binaries to include such functionality, but if someone were accessing your data directly via their own OS, that wouldn’t be effective. I don’t know of a way to circumvent that last part other than ensuring that the data isn’t left on disk when you’re done. For example, you could use a ramdisk instead of non-volatile storage. You could delete or intentionally corrupt the volume when you unmount it. You could split the file, storing half on your USB flash drive and keeping the other half on your PC. You could XOR the file with contents of another file (e.g., one on your USB flash drive instead of on your PC) and then XOR it again when you need to access it.
What sort of attack are you trying to protect from here?
If the goal is plausible deniability, then it’s worth noting that VeraCrypt volumes aren’t identifiable as distinct from random data. So if you have a valid reason for having a big block of random data on disk, you could say that’s what the file was. Random files are useful because they are not compressible. For example, you could be using those files to test: network/storage media performance or compression/hash/backup&restore/encrypt&decrypt functions. You could be using them to have a repeatable set of random values to use in a program (like using a seed, but without necessarily being limited to using a PRNG to generate the sequence).
If that’s not sufficient, you should look into hidden volumes. The idea is that you take a regular encrypted volume, whose free space, on disk, looks just like random data, you store your hidden volume within the free space. The hidden volume gets its own password. Then, you can mount the volume using the first password and get visibility into a “decoy” set of files or use the second password to view your “hidden” files. Note that when mounting it to view the decoy files, any write operations will have a chance of corrupting the hidden files. However, you can supply both passwords to mount it in a protected mode, allowing you to change the decoy files and avoid corrupting the hidden ones.
- 1 - It’s based on TrueCrypt, which has some less free restrictions, e.g.,
What do you mean by a file being displaced? Like do you want it to be unreadable, or unmodified, or just not deleted?
It's not really possible to have a level of protection that would require more than
sudo
because with root access you bypass anything else.You could put the files on an encrypted volume that uses a special password when it is mounted. Or you could use the
chattr
command to set special ext4 attributes that would make it unmodifiable (but could be removed with sudo). Or just record the file's hash, and that way you know it hasn't been modified later.Like do you want it to be unreadable, or unmodified, or just not deleted?
I don't necessariy care for any of those. They are 'bonuses' if you will. Though...:
- Unreadable will be required for preventing recreating the file elsewhere.
- Unmodifiable is not necessarily required. Maybe I would like to 'append' something to an existing file. But I'm fine either way. It should not be possible to delete some of the original data though.
- Not deleted is a must as well.
I guess you can use ACLs depending on your filesystem, or SELinux user contexts.
Seems interesting. Got any sources to read up on? Thanks in advance!
You can read about SELinux here or ACLs here. SELinux can be pretty complex if you've never used it, so make sure you understand it well. I believe it should be able to do what you want to achieve.
If you don't want files to be accessible by you, then have another user own them.
If you don't want files to be accessible by root, then don't have them at all.
This seems interesting. However, if I'm correct. What you suggest is not capable (by itself) to prevent said files to be copied through a disk clone. Am I right? Even if they're otherwise encrypted or inaccessible, then still they will come through the disk clone. Did I understood you correctly?
Just make the file root owned and readable by no one. An unreadable file can't be copied. You can use
chattr
to add some flags like immutability if you desire (shouldn't really need to). Use a command likefind /some/path -type f -exec chattr whatever {} \;
if you need to do this recursively. Root account should need a password, and should (hopefully) not be accessable with an unprivileged user's password throughsudo
/doas
, but on its own account with it's own password usingsu
orlogin
.Note that without encrypting the file, this does not protect you from someone just grabbing your storage device and mounting it with root permissions and then they can do whatever they want with your data. It also doesn't protect you if someone gets root access to your device through other remote means. If you want to encrypt the file, use something like
openssl some-cipher -k 'your password' -in file -out file.cipher_ext
. If you want to encrypt multiple files, put them in atar
ball and encrypt the tarball. You can again also usefind
withopenssl
to encrypt/decrypt recursively if you don't want to use a tarball, which may be better with ciphers like blowfish that aren't secure at large file sizes; but if you do that, you expose your encrypted file system structure to attackers.I am not a fan of full disk encryption, because it usually means leaving all your data decrypted during runtime with how most people use it. If you only decrypt a block device when you need to, there's nothing wrong with that, and can work as an alternative to encrypting a tarball.
Definitely one of the better answers I've received so far. Thank you for that. However, I feel as if the following part reveals that it's not as 'protected' as I'd like:
It also doesn’t protect you if someone gets root access to your device through other remote means.
Though, at this point, I've somewhat accepted that I'm seeking a software solution for a hardware problem. Hence, the impossibility of my query... I hope I'm wrong and perhaps you can point me towards the solution I'm seeking. However, if that's not the case, then I would like you to know that I appreciate your comment. Thank you.
😅. It's a requirement that the data stays on the same drive that I run my system from.
It sounds like you're actually more concerned about the data in the files not being able to 'pop up' elsewhere, rather than the files themselves. In thus case I'd suggest simply encrypting them, probably using
gpg
. That'll let you set a password that is distinct from the one used forsudo
or similar.You should also be using full disk encryption to reduce the risk of a temporary file being exposed, or even overwritten sectors/pages being available to an attacker.
I've failed tremendously in making my demands come across :P .
Uhmm..., what you propose with
gpg
definitely solves one part of the puzzle.But, if I understood correctly, it doesn't help to prevent a disk clone from getting hold of the files.
Yes, the files are encrypted, but that's not sufficient for my needs by itself. If the files would somehow destroy or corrupt themselves on a disk clone (or something to that effect), I would have acquired what I'm seeking.
Nothing can prevent a disk clone cloning the data, and there's no way to make something happen when a disk is cloned as you're not in control of the process.
If you wish to mask the existence of the files, use either full disk encryption, in which case cloning the disk doesn't reveal the existence of the files without the decrypt password, or use a file based encrypted partition such as veracrypt in which case the cloner would just see a single encrypted blob rather than your file names.
Ultimately encrypting the files with gpg means they have already effectively 'destroyed or corrupted' themselves when cloned. If you don't want to reveal the filenames, just call them something else.
If you could be a bit more specific about your threat model people may have better ideas to help.
If you could be a bit more specific about your threat model people may have better ideas to help.
Threat model is me protecting myself from myself.
Incoming XY problem.
I want to prevent myself from reinstalling my system. The trick I came up with involved the use of files that couldn't be disk cloned. However, if it's far far easier to accomplish it through other means, then please feel free to enlighten me on this.
Ok, I'm still not clear on exactly what you're trying to achieve as I can't quite see the connection between somehow preventing certain files being duplicated when cloning the disk and preventing yourself from reinstalling the system.
Bear in mind that reinstalling the system would replace all of the OS, so there's no way to leave counter-measures there, and the disk itself can't do anything to your data, even if it could detect a clone operation.
If what you're trying to protect against is someone who knows everything you do accessing your data, you could look to use TPM to store the encryption key for your FDE. That way you don't know the password, it's stored encrypted with a secret key that is, in turn, stored and protected by your CPU. That way a disk clone couldn't be used on any hardware except your specific machine.
Ok, I’m still not clear on exactly what you’re trying to achieve as I can’t quite see the connection between somehow preventing certain files being duplicated when cloning the disk and preventing yourself from reinstalling the system.
Premises:
- Very important files on disk (somehow) protected from copy/mv/clone whatever.
- Reinstalling my OS wipes the disk.
Therefore, I would lose those very important files if I were to attempt a wipe. If said files are important enough for me to reconsider wiping, then the act of protecting them from copy/mv/clone has fulfilled its job of preventing me from reinstalling the OS.
Bear in mind that reinstalling the system would replace all of the OS, so there’s no way to leave counter-measures there, and the disk itself can’t do anything to your data, even if it could detect a clone operation.
I understand.
If what you’re trying to protect against is someone who knows everything you do accessing your data, you could look to use TPM to store the encryption key for your FDE. That way you don’t know the password, it’s stored encrypted with a secret key that is, in turn, stored and protected by your CPU. That way a disk clone couldn’t be used on any hardware except your specific machine.
Very interesting. A couple of questions:
- Is it possible to only protect a set of files through this? So not the entire disk?
- Does TPM get flushed/randomized on OS reinstall?
This seems like a very complicated way to achieve your goal! It sounds like sitting yourself down and giving you a stern talking to might be a beter aporoach.
Having said that, if you have these very important files that you don't want to lose, please make sure they're backed up somewhere off of your machine. Storage fails, and it's a horrible feeling losing something important. Unfortunately doing so would defeat the approach you're thinking of.
This might be a case of needing to reframe the question to get to the cause of the issue, and then solve that. So, why do you want to make it hard to reinstall your machine? Is it the amount of time you spend on it, the chance of screwing it up, needing it working, has it become a compulsion or something else? Maybe if we can get to the root of the issue we can find a solution.
With regard to TPM, it's basically just a key store, so you can use it fir anything really, althought it's normally used by generating a TPM key and using it to encrypt the key that's actually used to encrypt your data, storing the encrypted key with the OS. Just reinstalling won't wipe the TPM, but unless you made an effort to save the encrypted key it'll be gone. Given your problem statement above it just adds to the data you'd need to save, which isn't helpful.
This seems like a very complicated way to achieve your goal! It sounds like sitting yourself down and giving you a stern talking to might be a beter aporoach.
You're probably right. But, it ensures a surefire method if accomplished.
Having said that, if you have these very important files that you don't want to lose, please make sure they're backed up somewhere off of your machine. Storage fails, and it's a horrible feeling losing something important. Unfortunately doing so would defeat the approach you're thinking of.
Thank you for your concerns!
This might be a case of needing to reframe the question to get to the cause of the issue, and then solve that.
Makes sense.
So, why do you want to make it hard to reinstall your machine?
I want to set it up in a particular way to ensure maximum productivity. But I'm afraid that I'll not go through with it (as has happened a lot in the past). Thus, making it impossible to reinstall should enable me to go through. As I wouldn't have any other choice.
Is it the amount of time you spend on it
The amount of time spent unproductively. Yes.
the chance of screwing it up
Nope. I haven't had a serious breakage since over one and a half years. I think I'm managing splendidly.
needing it working
Don't really have particular problems related to keeping my system up and running.
has it become a compulsion or something else?
Not sure what you meant with this.
Maybe if we can get to the root of the issue we can find a solution.
I believe I touched upon this earlier in this comment. I just want to be very productive.
With regard to TPM, it's basically just a key store, so you can use it fir anything really, althought it's normally used by generating a TPM key and using it to encrypt the key that's actually used to encrypt your data, storing the encrypted key with the OS. Just reinstalling won't wipe the TPM, but unless you made an effort to save the encrypted key it'll be gone. Given your problem statement above it just adds to the data you'd need to save, which isn't helpful.
Uhmm..., I feel as if I should properly read up on this. Have you got any pointers you would recommend?
Sorry for the slow reply, life occurred.
I think I understand where you're coming from with the desired to be productive and not reinstall. I think I've been there too! One thing that I can suggest, if you do have the time, is to learn a system like Ansible and use it to setup and configure your machine. The discipline of keeping all of the config as source rather than making ad-hoc changes reduces the chance of thinking you'll make just one little change and breaking something, and, if something does go wrong, you can get back to your working configuration quickly.
Bearing in mind that there really isn't anything you can do to stop yourself if you're really determined to not lose the data, because if you can read it at any time you can back it up, the closest you are likely to come is something like creating new key with GPG then using the TPM to wrap your secret key and deleting the original. That way the key is only usable on that specific machine. Then use the key-pair to encrypt your 'guard' files. You can still decrypt them because you have the wrapped secret keys and you're on the same machine, but if you wipe the drive and lose those keys the data is gone. The TPM wrapping prevents you from taking the keys to a different machine to decrypt your data.
There's an article with some examples here,
Having said all of that, this still doesn't help if you just clone the disk as all of the data, including the wrapped key and the encrypted files will be cloned. The one difference there is that the serial number of the hard drive will be different. Maybe you could use that, combined with a passphrase as the passphrase for your GPG key, but we're getting into pretty esoteric territory here. So you could generate a secret key with a command like:
( lsblk -dno SERIAL /dev/sdb ; zenity --title "Enter decrypt password" --password) | sha1sum | cut -c1-40
Where
/dev/sdb
is the device your root partition is on.zenity
is a handy utility for displaying dialogs, there are others available. In this use it just prompts for a passsword. We then concatenate the drive serial number fromlsblk
with the password you entered and hash the result. The hashing is really only a convenient way to mix the two without worrying about the newlinelsblk
spits out. Don't record the result of this command, but use it to set the passphrase on your newGPG
key. Wrapping the secret key in the manner the article above suggests is a nice extra step to make it harder to move the drive to another machine or mess around in that sort of way, but not strictly necessary as that wasn't in the scope of your original question.Now you can encrypt your file with:
gpg -e -r <your key name> <your file>'. That will produce an encrypted version of
<your file>called
<your file>.gpg. To decrypt the file you can get
gpg` to use the hashing command from above to get the passphrase with something like:gpg -d --pinentry-mode=loopback --batch --passphrase-fd 3 <your file>.gpg 3< <( ( lsblk -dno SERIAL /dev/sdb ; zenity --title "Enter decrypt password" --password) | sha1sum | cut -c1-40 )
Once you've tested that you can decrypt the file successfully you can remove the original, plaintext, file. Your data is now encrypted with a key that is secured with a passphrase made of a string you know and the serial number of your disk and optionally wrapped with a key from the TPM that is tied to your physical machine. If you change the disk or the machine the data is irretrievable (ignoring the caveats discussed above). I think that's about as close to your original goal as you can get. It's rough around the edges, and I'm not sure I'd trust my data to it, but I believe it'll work. If you do something like this, please test it thoroughly, I can't guarantee it!