1

I have access to a big remote server via SSH and I'm a root user on that server. However, there are multiple other root users who also have access to this server. I want to run some Fortran/C programs on this server, but I'm concerned about keeping my code private.

Is there a way to execute my Fortran/C programs without revealing the source code to other users on the server? I'm looking for solutions that allow me to maintain confidentiality while still being able to run my programs

I have a method in mind for protecting my source code while compiling on the server, and I’d like your feedback on its effectiveness, potential risks, and any overlooked measures I should consider.

First, cross-compilation isn’t an option for my situation; I need to compile the source code directly on the server. My goal is to ensure that accessing my source code requires significant expertise, ideally making it take days or even months for an average user. The entire remote session, including compilation and execution, will take about 30 minutes. I’m willing to spend around 5 additional minutes to implement protective measures.

Before I begin, I want to take several precautions with my root access:

  • Verify that my SSH connection is secure.
  • Check for any suspicious processes or daemons running on the server.
  • Confirm that secure boot has occurred.
  • Disable all logging and console input/output to limit exposure.
  • Verify the signatures of the compilers and libraries involved.

During the process, I plan to create a temporary folder in RAM, setting myself as the only owner. I’d like to know if it’s possible to receive alerts if someone attempts to access that folder. This will mitigate file system access risks from other root users. If someone is monitoring my activities undetected, I want to implement measures to make it more difficult for them.

For file transfers, I will use cryptographic encryption and a unique, hard-to-access password for decryption(@security_paranoid), piping the output directly to the compiler. After this, I want to run the compilation securely while minimizing risks, particularly regarding memory inspection (acknowledging that complete prevention is impossible). I assume that reverse engineering the object files and executable will take significant time, and I don't believe other root users are motivated enough to go through this process unless automated tools make it easy to reconstruct the source logic.

What Linux tools would you recommend to assist with these processes and precautions? Ideally, the only way to retrieve the program should be through hardware means rather than software.

17
  • 4
    Your question is a bit confusing. You talk about executing programs, but it seems what you actually want to do is compile code on the server. Those are two completely different things. If you just want to execute a program, then do the compilation on your local PC and only upload the binary. The server doesn’t need the source code. You can additionally use an obfuscator to make reverse engineering of the binary more difficult. If you want to compile the source code on the server, then you cannot protect it from root users. Anything you share with the server could be obtained by root users.
    – Ja1024
    Commented Sep 21 at 22:12
  • 2
    How did you even end up in this strange situation? Why are there so many root users who don't trust each other?
    – Ja1024
    Commented Sep 21 at 22:13
  • 3
    > optimizations to the object file specific to the hardware. Is there any reason why you can't cross compile with the correct optimisation flags? GCC has -Q and --help=target flags for example.
    – timuzhti
    Commented Sep 22 at 4:00
  • 4
    If the other actors are root and you are concerned about their trustworthiness, you would have to distrust any and all content on the server. This includes the SSH daemon or shell, which could capture your session, or the compiler, which could capture any source code fed to it. Really what makes you doubt your "peers" so much but still use such an exposed setup? Commented Sep 22 at 6:38
  • 4
    @AkhilAkkapelli Let me put my question differently: What do you actually trust on the system and to what extent do you distrust your adversaries? Everything you have mentioned so far can be tainted by someone with root privileges and sufficient motivation. Commented Sep 22 at 9:11

2 Answers 2

6

Fundamentally, you can't. You can make it less convenient to read your source, but not in any way that amounts to more than inconvenience; you quite simply can't achieve this goal at all. An unrestricted root user owns the system, and can observe literally anything that any user on it can do (yes, including SSH traffic, console input, the working memory of the compiler, and so on). They could install drivers, modify binaries, debug processes, log keystrokes, network traffic, and SSH session keys, and more. If your source code ever touches a computer in plain text, it can be read by any root user on that computer if they're trying hard enough.

The only real option would be to take advantage of your root access to get in the first strike, in a sense. Reduce the privileges of everybody else, ensure the binaries are untampered-with and the others can't tamper with them, ensure the kernel is clean, and file permissions are as they should be, etc. Of course, everything you're interacting with could in theory be a simulation of the real system - maybe you SSHed into a container or VM and some adversary is watching everything you do right down to being able to inspect (and modify) register values if they want - unless you were the first person to access the server (which you can't prove you were) and took your first strike immediately (which I presume you didn't). Also, in addition to being basically futile, this would be a remarkably hostile action, and despite your assumption of hostility in your root-access peers, that doesn't seem to be the kind of suggestion you're looking for.

So - now that we've established impossibility - how far do you actually want to go to make this inconvenient? How much inconvenience to them is the inconvenience to you worth? How motivated do you expect them to be?

Your basic plan is fine if you neither expect them to be actively looking for your source code, nor logging all your SSH traffic already, and thus only care about not leaving it on the file system. (You could also achieve this by transferring the files normally and then overwriting and deleting them after compiling, or creating a temporary RAMdisk and putting the files there for compilation, but that creates a slightly wider window of vulnerability.)

With that said, unless this compilation task is enormously difficult and the only computers you have access to are complete potatoes by comparison to the server, cross-compilation seems much simpler and more secure (if all you care about is the source code) than attempting this sort of shenanigan. You could even do things like compiling the code only partway (e.g. to AST) locally, and then transferring the intermediate representation (which is certain easier to reverse engineer than an optimized binary, but not actual source code) to the server and completing compilation there; the compiler back-end is where all the platform-specific optimizations happen anyhow.

Or you could get a server that doesn't have adversaries-with-root-access on it. It's generally extremely unwise to do literally anything on a computer where there are adversaries with root privileges! There are many computers in the world that you could access instead, and most of them don't have this problem.

6
  • 1
    Theoretically, there are modern hardware extensions (SGX, SEV, etc) that work towards being able to provide an attested confidential computing environment. They don't exactly inspire confidence though.
    – timuzhti
    Commented Sep 22 at 11:05
  • 2
    Yeah, I thought about trying to bring up secure enclave stuff, but I don't think it's worthwhile here. Even leaving aside the fact that people keep finding ways to leak data (keys, memory, etc.) out of the enclave when they have full control of the machine, the effort required - SSHing your source directly into the enclave and then running the compiler on it there - would be a ton of effort to set up, and assumes you have a unique key that nobody else has (which I would normally assume, but is not necessarily the case in an "everybody can log in as root" scenario). Good mention, though.
    – CBHacking
    Commented Sep 22 at 11:11
  • What measures can be taken in a system with unrestricted root users to enhance security for source code? Even though complete protection may not be achievable, I want to make it more difficult for unauthorized access. Could you provide solutions that offer increasing levels of difficulty for retrieving the source code, along with inconveniences for potential attackers? Commented Sep 22 at 11:11
  • 3
    The source code must exist in plain text on the server (unless you just compile on the client like normal); compilers can't compile ciphertext. It doesn't have to exist in persistent storage (disk), but it does have to exist in RAM, and it does have to exist in the file system (even if only in /dev/mem and the pipes connecting your SSHD to your shell to your compiler).
    – CBHacking
    Commented Sep 22 at 11:16
  • 1
    @AkhilAkkapelli: You keep asking the same question, even though CBHacking has already given you several options and explained their limitations. Did you read and understand the answer? If not, what exactly don't you understand? And you still haven't explained why you think cross-compilation isn't an option.
    – Ja1024
    Commented Sep 22 at 23:42
1

Compiling your code from the terminal directly into object (.o) files is a decent method, but the main problem I see with it is that while object files are harder to reverse engineer than source code, they can still be analysed through specific reverse engineering techniques.

So if other root user could manage this, they could inspect these files, even if they don’t have access to your original code.

But because you want to compile the program on the server, just as you suggested, encrypting the source code and then decrypting it with a password inside a bash script for compilation would work well.

Tools such as openssl can be used to encrypt your source code.

6
  • 1
    See my edit, please. This addresses a basic example with openssl. Commented Sep 22 at 10:14
  • 2
    Note that, if command logging is enabled (which it is by default for shell history to work, no adversarial action needed), you'd need to provide the password neither hardcoded inside a shell script nor as a command-line parameter. Inputs read by scripts (or other programs) aren't logged by default, though of course they can be if anybody with root privileges is trying.
    – CBHacking
    Commented Sep 22 at 11:07
  • 1
    @CBHacking Thanks for pointing this out, however I never said that my given command was the only way to use openssl to do this. It was an example. A basic example- I could’ve included a more sophisticated way to do this securely, but I was providing the OP with a snippet of code that took me two seconds to write. One potential work around to this problem, for example, is having something like s password vault that sshes to the OPs server then provides a one time token to decrypt the source code, which is derived from the password that is locally given. Commented Sep 22 at 20:24
  • 4
    @security_paranoid considering that one of the greatest banes of the security industry is insecure example code copypasta, I strongly discourage making more of it. At minimum, it's important to flag the problems with the example, which is what my comment was doing. You absolutely can't rely on the reader to have the security awareness to understand why your "example" is in fact a bad example from a security perspective, much less how to fix it.
    – CBHacking
    Commented Sep 22 at 20:54
  • 1
    @CBHacking you have a point there, especially as code can end up in LMs, google snippets, etc. Thanks for letting me know. Commented Sep 22 at 21:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .