This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
InDieTasten's profile picture

How to improve the security of an OS [weak]

Started by InDieTasten, 02 April 2013 - 10:51 PM
InDieTasten #1
Posted 03 April 2013 - 12:51 AM
Edit:
This method is not as 'perfect' as I've described it.
It will protect your files against 98% of attackers. Those who really want to
get the contents will get them if they know how to do it.
If a highly skilled player has access, I would guess he needs about 3 minutes
to figure out what you've done and break it via fs.list from the lua prompt.

(Additionally you could overwrite the fs.list command, but the overwriting process can
be tracked in the startups as everything else too(unless you bytecode it))

The used encryption api is still ok to use, as the work to crack it wouldn't be less as the fs.list backdoor itself.
"If you improve your door lock too much, people will break through the wall next to the door", which basically means
you have to improve your wall, which isn't necassarily possible in computercraft without having a remote service running,
which is 100% secure from unauthorised users.

Prolog:
Welcome to my first tutorial in this forum. Would be nice if you'll give me some suggestions what i should do next or better. So lots of people are working on their own OS. It's a good training to learn to solve all kinds of problems. I think when someone did a complex OS he is able to do whatever he wants to do in Computercraft. Some people are annoyed from all these OS's and how bad they all are and stuff. I'm kind of that guy. But I want to change something instead of just offend the creators. So here a little tutorial of one ADDITIONAL way to protect the OS and the users data.

The way to do it:
I chose the way of encryption. Cryptography is really cool and interresting I thought. And even more, if it's not the "I move every character 3 characters back in the alphabet". Doing it with passwords is a good way. To those that like to script their own encryption should take a look to the string.byte and string.char methods/functions in the string API. Doing your own will increase your skills and causes (in the most cases) more protection.
But here is my encryption/decryption API:
Spoiler

function encrypt(sText, sKey)
	if #sKey >= #sText then
		error("Text needs to be longer than the Passphrase")
	end
	local tKeyNum = {}
	for i = 1, #sKey,1 do
		tKeyNum[i] = string.byte(sKey,i,i)
	end
	local tTextNum = {}
	for i = 1, #sText,1 do
		tTextNum[i] = string.byte(sText,i,i)
	end
	local tCryptNum = {}
	for i = 1,#sText,1 do
		if i <= #sKey then
			tCryptNum[i] = tTextNum[i] + tKeyNum[i]
		else
			if i%(#sKey) == 0 then
				tCryptNum[i] = tTextNum[i] + tKeyNum[i%(#sKey)+1]
			else
				tCryptNum[i] = tTextNum[i] + tKeyNum[i%(#sKey)]
			end
		end
	end
	local tEncryptedText = {}
	for i = 1,#sText,1 do
		tEncryptedText[i] = string.char(tCryptNum[i])
	end
	local sEncryptedText = ""
	for i = 1,#sText,1 do
		sEncryptedText = sEncryptedText..tostring(tEncryptedText[i])
	end
	print(sEncryptedText)
	return sEncryptedText
end
function decrypt(sEncryptedText, sKey)
	if #sKey >= #sEncryptedText then
		error("Passphrase needs to be shorter than Text")
	end
	local tKeyNum = {}
	for i = 1, #sKey,1 do
		tKeyNum[i] = string.byte(sKey,i,i)
	end
	local tEncryptedTextNum = {}
	for i = 1, #sEncryptedText,1 do
		tEncryptedTextNum[i] = string.byte(sEncryptedText,i,i)
	end
	local tTextNum = {}
	for i = 1,#sEncryptedText,1 do
		if i <= #sKey then
			tTextNum[i] = tEncryptedTextNum[i] - tKeyNum[i]
		else
			if i%(#sKey) == 0 then
				tTextNum[i] = tEncryptedTextNum[i] - tKeyNum[i%(#sKey)+1]
			else
				tTextNum[i] = tEncryptedTextNum[i] - tKeyNum[i%(#sKey)]
			end
		end
	end
	local tText = {}
	for i = 1,#sEncryptedText,1 do
		tText[i] = string.char(tTextNum[i])
	end
	local sText = ""
	for i = 1,#sEncryptedText,1 do
		sText = sText..tostring(tText[i])
	end
	print(sText)
	return sText
end

Now the idea:
So, my idea for this tutorial is to protect the main folder of the os and the user documents in it(they should be all in one folder next to the os but not in the root directory). This directory should be in another randomly genarated and invisible(means a . before the name of it) directory. After that the path to the os get encrypted by any password your user chose and saved in some way. A startup with a kind of login can see the encrypted path and trys to decrypt it by the input of the player. it checks the decrypted path after existance and starts the os it self. Now in order for an installer of your OS:

1. generate a random path for the main directory of the os and user data
2. get some login details(username &amp; pw) from the user
3. encrypt the path with these logIn details
4. install the os itself at this path
5. generate the startup with the information of the encrypted path
6. have a more secure OS
This method is good for multiplayer and allows you to protect your data without worrying about termination of your OS in any way. Without the password an attacker can't find any data on your computer. This Method is usable with all OSs that manage their user data in a seperate folder. So yeah, thats it. if there are any fails in my idea please tell me. I hope I could improve the most OSs of these who read this tutorial. If you think that this is a good way to protect user data too, i would like to get some votes ;)/>

~InDieTasten
Edited on 11 January 2015 - 02:55 PM
Bubba #2
Posted 03 April 2013 - 09:19 AM
You'd be better off using a one way hash than a two way encryption. Having a decrypt method sitting around is just asking for trouble and it's not necessary in terms of passwords and such. All you have to do is hash the user input and compare that to the stored hash and see if they are equal, which is much safer.
InDieTasten #3
Posted 03 April 2013 - 10:08 AM
You'd be better off using a one way hash than a two way encryption. Having a decrypt method sitting around is just asking for trouble and it's not necessary in terms of passwords and such. All you have to do is hash the user input and compare that to the stored hash and see if they are equal.

i know what you mean but in this case the decryption is needed, because the startup needs to know what the os path is in clear text. to check if the password is correct, i could simply do that. but i want to hide the os and user data. there's no clear version of the path anywhere on the computer. just the encrypted one. so only owning the right password can return the right path. thats the most secure.
Bubba #4
Posted 03 April 2013 - 10:12 AM
You'd be better off using a one way hash than a two way encryption. Having a decrypt method sitting around is just asking for trouble and it's not necessary in terms of passwords and such. All you have to do is hash the user input and compare that to the stored hash and see if they are equal.

i know what you mean but in this case the decryption is needed, because the startup needs to know what the os path is in clear text. to check if the password is correct, i could simply do that. but i want to hide the os and user data. there's no clear version of the path anywhere on the computer. just the encrypted one. so only owning the right password can return the right path. thats the most secure.

Actually it's not. That's the same as having an encrypted password sitting around - all you need to do is decrypt the path (simple to do considering that Lua has no compilation and obfuscation is such a pain), decrypt the password the path gives you, and wala you're in. A one way hash however will protect you from that.
PixelToast #5
Posted 04 April 2013 - 07:00 AM
need more hashing (and possibly salting)
if a user makes a bad password data could be corrupt easialy
InDieTasten #6
Posted 04 April 2013 - 10:13 AM
You'd be better off using a one way hash than a two way encryption. Having a decrypt method sitting around is just asking for trouble and it's not necessary in terms of passwords and such. All you have to do is hash the user input and compare that to the stored hash and see if they are equal.
i know what you mean but in this case the decryption is needed, because the startup needs to know what the os path is in clear text. to check if the password is correct, i could simply do that. but i want to hide the os and user data. there's no clear version of the path anywhere on the computer. just the encrypted one. so only owning the right password can return the right path. thats the most secure.
Actually it's not. That's the same as having an encrypted password sitting around - all you need to do is decrypt the path (simple to do considering that Lua has no compilation and obfuscation is such a pain), decrypt the password the path gives you, and wala you're in. A one way hash however will protect you from that.
there's no way for you to decrypt the path without the right password. if you don't know the password you are not able to use the decrypt. a one way hash would be possible to implement but it's not needed. you can look as a hacker to my generated startup and see something like this:

sEncryptedOsLocation = "????????????????????"
unloadApi("crypt")
loadApi("crypt")
print("pls insert password:")
sInput = read('X')
sDecryptedOsLocation = crypt.decrypt(sEncryptedOsLocation, sInput)
if fs.exists(sDecryptedOsLocation) then
shell.run(sDecryptedOsLocation)
end
so you can't get the right key, because you only see some question marks on the encryptedOsLocation path. you can't just decrypt it without the right password.
InDieTasten #7
Posted 04 April 2013 - 10:20 AM
need more hashing (and possibly salting) if a user makes a bad password data could be corrupt easialy
i don't need more hashing. but you can do it for yourself. and it doesn't corrupt anything after a bad password. the startup works like i wrote before in another post in here. it first checks if the path is available. and if so it executes it
Kilobyte #8
Posted 08 April 2013 - 12:03 PM
Tomass made a lua only implementation of sha1 (or was it 2?). its pretty much what everyone wuses if hashes are used. Another thing to note is that you should restrict access to the password file. so only an admin user can even open it. Thats done by sandboxing fs api. I am actually working on an OS that does it and woulde linked example files, but a fried (who also works on it) somehow removed all fs related files as i just saw, need to slap him.
theoriginalbit #9
Posted 08 April 2013 - 04:05 PM
Tomass made a lua only implementation of sha1 (or was it 2?). its pretty much what everyone wuses if hashes are used.
it was SHA-1, which SHA-1 is basically like using MD5… The best ones to use are the SHA-2 functions made by GravityScore, and are pretty much what everyone uses now.

Thats done by sandboxing fs api.
Have fun working on that, sandboxes can be easily broken if not done right.
Jarle212 #10
Posted 08 April 2013 - 08:25 PM
Well there is uses for this. I do not recomend encrypting the password, but you could use it for file encryption.

Edit: Someone should makea Murmur2 hashing method.
theoriginalbit #11
Posted 08 April 2013 - 08:29 PM
Well there is uses for this. I do not recomend encrypting the password, but you could use it for file encryption.
File encryption has virtually no use in ComputerCraft, the all programs are open source, and at some point an unencrypted file is required for the computer to read it. Its best to hash the string so it is not plain text and use sandboxing over a file encryption system.
Jarle212 #12
Posted 08 April 2013 - 08:36 PM
Well there is uses for this. I do not recomend encrypting the password, but you could use it for file encryption.
File encryption has virtually no use in ComputerCraft, the all programs are open source, and at some point an unencrypted file is required for the computer to read it. Its best to hash the string so it is not plain text and use sandboxing over a file encryption system.

Well I was thinking about encrypting the image and text files and when using them decrypting them. sandboxing isn't that secure unless it is done in bios. Encryption is safe outside of computercraft aswell. :P/>
theoriginalbit #13
Posted 08 April 2013 - 08:40 PM
Encryption is safe outside of computercraft aswell. :P/>
Again though, at some point you are going to need to have the password in plaintext, and the startup program is going to need to be in plaintext… if neither of these are the case the computer has no way of reading and running the programs. really the best method of security would be a sandbox, encryption and closed-source/compiled programs and/or read-only files. short of that there are always ways around everything else.
Jarle212 #14
Posted 08 April 2013 - 09:09 PM
Thats true, you whould end up having to need a program for decrypting and running the files everytime you want to use them. :)/>
theoriginalbit #15
Posted 08 April 2013 - 09:30 PM
exactly, and by the pure fact of that you may as well leave them unencrypted, since all it is doing is slowing down and adding overhead to your program.
Pharap #16
Posted 04 May 2013 - 01:28 PM
You'd be better off using a one way hash than a two way encryption. Having a decrypt method sitting around is just asking for trouble and it's not necessary in terms of passwords and such. All you have to do is hash the user input and compare that to the stored hash and see if they are equal.
i know what you mean but in this case the decryption is needed, because the startup needs to know what the os path is in clear text. to check if the password is correct, i could simply do that. but i want to hide the os and user data. there's no clear version of the path anywhere on the computer. just the encrypted one. so only owning the right password can return the right path. thats the most secure.
Actually it's not. That's the same as having an encrypted password sitting around - all you need to do is decrypt the path (simple to do considering that Lua has no compilation and obfuscation is such a pain), decrypt the password the path gives you, and wala you're in. A one way hash however will protect you from that.
there's no way for you to decrypt the path without the right password. if you don't know the password you are not able to use the decrypt. a one way hash would be possible to implement but it's not needed. you can look as a hacker to my generated startup and see something like this:

sEncryptedOsLocation = "????????????????????"
unloadApi("crypt")
loadApi("crypt")
print("pls insert password:")
sInput = read('X')
sDecryptedOsLocation = crypt.decrypt(sEncryptedOsLocation, sInput)
if fs.exists(sDecryptedOsLocation) then
shell.run(sDecryptedOsLocation)
end
so you can't get the right key, because you only see some question marks on the encryptedOsLocation path. you can't just decrypt it without the right password.
You can if you can read binary. By opening the file in string and binary mode, you can find out where in the binary stream the question marks are and then extract the bytes that normally get read as question marks.
InDieTasten #17
Posted 06 May 2013 - 05:36 PM
You can if you can read binary. By opening the file in string and binary mode, you can find out where in the binary stream the question marks are and then extract the bytes that normally get read as question marks.
i don't think you understand how the system works. or my english is too bad to explain how it works. my encryption/decryption api is nearly perfect. i'm not the best with mathematics and ciphering and stuff like this. but let's say, if you encrypt a string with a password, you aren't able to get back the string without the password.
so there is this random generated osPath, let's say it's ".osPath-9234723492345728432349". ok. it gets enrcypted by the installer with a user chosen password. now the encrypted osPath is like:
"???H?d???n??s??./&sup3;??5?92??3}??"),". this get saved to the startup as osPath. installation complete.
after running the startup, it requests the password. it reads in the password. decrypt the given encrypted osPath and checks, if the outcome exists in the filesystem. if not -> bad password, if -> shell the os.

so, no matter of binary or string mode. there's just the encrypted path. it's only possible to get the right localization of the os, if you know the right password. because it doesn't compare the password with the input, it just tries, if the input works or not. so even not the startup itself knows the right password. and this system works with all kind of programs, that use passwords.
immibis #18
Posted 07 May 2013 - 09:31 AM
Can't an attacker just use fs.list to find the os directory?
D3matt #19
Posted 07 May 2013 - 01:20 PM
Immibis is right, having a plaintext that's easily indntifiable makes nearly any encryption algorithm insecure. Somebody could theoretically get the password by reversing your decryption and basically using the osPath as the key to get the password from the encrypted OS path.
PixelToast #20
Posted 07 May 2013 - 02:40 PM
*cough* *cough* *cough*
http://pastebin.com/Q20qiLbz
one of my first programs
it takes around 30 min to crack a 6 character long password using CC
when coded in python its around 3 seconds :P/>
just make the hashing better and your good