I'm working on a program which need to check if os.computerID() has been overwritted.
I've thought that if I check the size of os.computerID, I can compare it to the original size and check if there's differences.
But, I saw that it was the CC's Java part. So I can't get the original size.
Is there a way to know the size of this thing ? Or is there an easier way to check if os.computerID() has been overwritted ?
Thanks you in advance !
EDIT : Solved !
Spoiler
You might see if the bytecode it dumps to is consistent. Other than checking that, you won't really have any way of verifying that it is intact. This is ignoring the fact that if you're basing anything important on the computer ID, you've gone wrong several steps ago, of course.
Then the hypothetical attacker can override string.dump.(does this count as malicious code? it could be part of a legitimate sandbox) Edit: This can be countered by:local oldGetID, oldDump = os.computerID, string.dump function os.computerID() return 42 end function string.dump(f) if f == os.computerID then error("dan200.computer.core.LuaJLuaMachine$2 cannot be cast to org.luaj.vm2.LuaClosure", 0) end -- the exact error message CC gives return oldDump(f) end
which can be countered by:local old = os.computerID function os.computerID() end local isBeingAttacked = not pcall(string.dump, os.computerID) os.computerID = old
which can be countered by:local oldGetID, oldDump = os.computerID, string.dump function os.computerID() return 42 end local ourComputerID = os.computerID function string.dump(f) if f == ourComputerID then error("dan200.computer.core.LuaJLuaMachine$2 cannot be cast to org.luaj.vm2.LuaClosure", 0) end return oldDump(f) end
which can be countered by: …etc This could go on for a while. Eventually, the attacker will win. If a sufficiently determined attacker has full access to the computer running your program, they will always win, and there is nothing you can do about it. Of course, maybe this has nothing to do with security. If you're not trying to defend against sufficiently determined attackers, this should do:local isBeingAttacked = pcall(string.dump, string.dump)
local isComputerIDOverridden = pcall(string.dump, os.computerID)