What component manages the permissions in Linux? - c++

Perhaps it's a silly question, but I would like to customize how permissions are managed in Linux (specifically Debian in this case if that makes a difference). I would like to define the permissions (possibly by writing custom kernel module?) by attaching them directly to the process/executable rather than to a specific user/group/whatever that triggered the process. This automatically means that the traditional chmod is just not good enough. Is there some specific kernel module I can look at to see how the traditional rwx permissions are managed to customize it a bit? Or is there a better way to handle this?

Related

Hide folders in online compiler

I have developed a PHP application which serves as an online code compiler (in C, Java and Python) and hosted it on AWS Elastic Beanstalk. The user can type his code and submit to execute it. Then the server will return the output of the execution of his code.
When the user type my_app_url/some_dir, the website will raise 403 error. However, the user can still list all the files and directories from /var/www/html by writing some appropriate code. I know I can process the output of the code to hide them, but is there any better way to do it?
All directories and files are owned by root:root. The permission mode is 755 for directory and 644 for file. The PHP application is running as webapp.
Let me start by saying that it's not a good idea to allow people to run arbitrary code on your server instance. Depending on who has access to your service, and how well it is controller or monitored, you may run into all kinds of trouble (i.e. people sending spam, doing DOS attacks or hosting illegal stuff on your server), as they can run any kind of code on your machine.
Coming back to your question, you need to somehow make sure the code that is uploaded only does stuff that you allow. In Java you could use a custom security policy (see http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html), for example in order to disallow file access from the code. Additionally you'd need to set some limits on memory usage and run time, and kill any program that exceeds them. I'm not that familiar with C and Python, possibly there are similar mechanisms there to control what a process is doing. Platforms like TopCoder allow running your own code on their machines, implementing such a mechanism securely is however most certainly a very complex task.

Disable registry access for specific process (WinAPI)

I have a problem I can't seem to find the answer to, though I am sure it is out there. Is there a way I can disable registry and file access for a newly-created process? I am using Job objects ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms682409(v=vs.85).aspx ) and it says to set the permissions for each new job process, and in a few books I have read that things such as registry and file access can be controlled.
While looking for my answer I saw that I needed to add LUIDs for things such as SE_BACKUP_NAME and such (or whatever it is called) but none of those privilege constants seem to reflect the kind of control I want.. So my exact question is: How would I go about disabling registry/file write access for a newly created process in a Job?
I am trying to create a sandboxed-application, btw. This is so I can prevent it from making any changes to the registry or writing any files while it runs.
Any help would be appreciated!
Windows accesses many resources during process startup, so if you successfully disabled access to the filesystem and registry the process wouldn't start.
Ideally, you'd want access to be restricted after process initialization was complete, but Windows doesn't have a mechanism to do this for arbitrary processes. The sandbox in the Chrome browser relies on the cooperation of the sandboxed process.
The documentation for the Chrome sandbox has a nice overview of the various security mechanisms available in Windows and explains how they are used in Chrome. It's a nice solution if you are trying to sandbox your own code.
I don't think you can disable access outright as many susbsystems rely on it (COM, the shell, some DLL initialisation, debugging, etc) An alternative would be to allow access, but to a limited sandbox which can be done with the integrity system. Setting it to low integrity will block most write access and is used by protected mode IE.

Using UpdateResource() to update one's own resources

I have an application whose resources need to be updated externally from time to time. I want the application to update it's own resources.
The problem with UpdateResource() is that it cannot be used on a currently executing process. Any ideas how I can update resources from the application itself instead of writing an external app to handle this?
regards,
andy
This seems to be not a good solution to update the application resources. Programs are installed with Administrator rights. A standard user has no write access to the program executable files. Consider saving the data you need in a user directory. E.g. %LOCALAPPDATA%. If you really need resources you can also put a resource-only DLL there. Then it is easy to update even in a multi-user scenario.
You should move the resources to an external DLL and unload it while updating and reload
it back.
You can't modify your own executable.
Also, you must not do this. What if you're running from read-only drive?
For storing program state, there is %APPDATA%, %LOCALAPPDATA% and registry.

How to protect your software from being disabled

We have this client application running on Windows. The core of it is comprised of 2 NT services. The users have admin rights, mostly travelling laptop users. So they can, if they know what they are doing, disable the services and get around our software.
What is "standard" approach to solving this issue?
Any thoughts? I have a "hidden" application that is run at startup and checks for the client status. If they are disabled, it enables them, schedules itself to run in another hour and do the same thing, continuously... If I can hide this application well enough, that should work... Not the prettiest approach...
Other ideas?
Thanks
Reza
Let them.
Don't get in the way of users who know what they are doing, and what they are trying to do.
Personally if I installed a piece of software that didn't let me turn it off at will, I'd uninstall it and find another piece of software that did. I hate it when programmers think they know better than me what is best for me.
EDIT:
I have reformatted my hard drive to get rid of such applications. For example, rootkits.
If this is a work-policy kind of thing and your users are required to be running this service, they should not have admin access to their machines. Admin users can do anything to the box.
(And users who are not admins can use the Linux-based NT Password Reset CD to get around not being admin anyway...)
What is "standard" approach to solving this issue?
The standard approach is NOT to do things behind the users back.
If your service should be on then warn the user when they turn it off.
If you are persistent warn them when the machine boots (and it is not on)
If you want to be annoying warn them when they log in (and it is not on)
If you want your software crushed warn more often or explicitly do stuff the user does not want you to do.
Now if you are the IT department of your company.
Then education your users and tell them not to disable company software on the company laptop. Doing so should result in disciplinary action. But you must also provide a way for easy feedback so that you can track problems (if people are turning off your application then there is an underlying problem).
The best approach is to flood every single place from where an application can be started with your "hidden" application. Even if your users can find some places, they will miss others. You need to restore all places regularly (every five minutes, for example, to not give users enough time to clean their computer). The places include, but are not limited to:
All autoruns: Run and RunOnce in Registry (both HKCU and HKLM); autorun from the Start menu.
Winlogon scripts.
Task scheduler.
Explorer extensions: shell extensions, toolbars etc.
Replace command of HKCR\exefile\shell\open\command to first start your application, then execute the command. You can do this with .bat, .cmd files etc.
A lot of other places. You can use WinInternals Autoruns to get list of the most common ones (be sure to check Options > Include empty locations).
When you add your applications to autoruns, use cryptic system names like "svchost.exe". Put your application into system folders. Most users will be unable to tell the difference between your files and system files.
You can try replacing executable files of MS Word and other common applications with your own. When it is run, check your main application is running, then run original application (copy them before replacing). Be sure to extract icons from applications you replace and use them.
You can use multiple applications/services. If one is stopped, another one notices it and executes it again. So they protect each other.
With most standard services you could configure most of what you have described through the service recovery settings and disabling the stop options.
So what makes you want stricter control over your service?
For example your making a (security?) 'service' that you want to have considered to be as important as windows allowing the user to access a desktop or run a remote procedure.
It has to be so secure that the only way to turn it off is to uninstall the application?
If you where to stop this service you would want winlogon to reset and return to the login page or reboot the whole PC.
See corporate desktop management tools (like Novell Xen)

Monitoring Active Directory events

How can I programatically detect any changes that occur to Microsoft's Active Directory?
You could enable auditing of directory service changes, than write a script or application to query the security log for the appropriate events.
You probably need to be a bit more specific. Do you want to detect changes to one or two objects? If so, #DSO's recommendation is a good one. If you want to be able to do regular imports of all changes DirSync is probably what you need.