Deleting root files from another user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting root files from another user
# 1  
Old 04-13-2004
Deleting root files from another user

I want to delete some files and directories owned by root from another different user in HP-UX 10.20.

The list of files looks like:

(user test)
bash-2.03$ ls -alrt
total 20
-rw-r--r-- 1 root root 55 Aug 27 2003 _index_jsp_2.dat
-rw-r--r-- 1 root root 4100 Aug 27 2003 _index.class
drwxr-xr-x 3 root other 512 Jan 22 13:33 ..
drwxr-xr-x 2 root root 512 Mar 5 10:53 error_5F_pages
drwxr-xr-x 4 root other 512 Mar 5 10:54 .
drwxr-xr-x 5 root root 512 Apr 12 19:24 jsp

I have programmed and compiled a C source as root that executes a shell and have set the s-uid-gid bit in order to execute them with the efective user root.

The C source sais:

/***********************************************/
#include <stdio.h>
#include <unistd.h>

int main(){

char *env[]={"PATH=/bin:/usr/bin",NULL};
char prog[]="/appli/test/shtest";

if (access(prog,X_OK)){
fprintf(stderr,"ERROR: %s \n",prog);
return(1);
}

system(prog);

perror("test");

return(1);
}


/***********************************************/

The shell (/appli/test/shtest):

rm -r /appli/test/www/*



-rw-r--r-- 1 root other 43 Apr 12 11:25 makefile
-rw-r--r-- 1 root other 328 Apr 12 11:47 test.c
-rwsrwsrwt 1 root other 6808 Apr 12 11:51 test2
-rwxrwxrwx 1 root other 74 Apr 13 08:39 shtest

The binary (test2) tries to execute shtest which is the shell that tries to remove these files.

When I execute it as "test" the system message says:

rm: /appli/test/www/_index.class: override protection 644 (yes/no)? yes
rm: /appli/test/www/_index.class not removed: Permission denied

The problem is that the directory where the list of files are stored is owned by root and the user isn't allowed for writing in it:

drwxr-xr-x 4 root other 512 Mar 5 10:54 www

It's not possible to change this permissons because they are automatically generated and we don't want to use a cron task which changes these permissons because there are thousands of files of this kind that we want to delete.

Do you know if I can remove these files and directories with a non-root (nor system...) user?

Thanks in advance
# 2  
Old 04-13-2004
What you are trying to do is very dangerous from a security standpoint. shtest is obviously a shell script of some kind. That is bad enough by itself, but you actually have shtest world-writable.

Rather than executing shtest, your c program should do all of the work itself. Deleting some files is not hard.

But the reason this is failing is that modern shells try to prohibit what you are trying. If they find themselves running a script and notice that the effective uid does not match the real uid, they reset the effective uid.

You can defeat that by adding a single line of code:
setuid(0);
to your c program prior to invoking system(). Mark my words though. Youll probably regret doing so later.
# 3  
Old 04-13-2004
It worked. I just added the line setuid(0) and it worked.

In fact the permissions you could see in the example are not those which will stay in the future. It's just a test. The reason why I ask here is also to do it in a safe way.

Thank you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

New user to own files made by root?

Hi, when I installed debian 8, all files are created and owned by root, when I add new user, for example marco, he can't create directory or change files created by root. I tried with ftp, permission denied. so, I am interested how to grant to user marco ownership of all files in the system so... (5 Replies)
Discussion started by: alanford
5 Replies

2. UNIX for Dummies Questions & Answers

Switching from root to normal user takes me to user's home dir

Whenever i switch from root to another user, by doing su - user, it takes me to home directory of user. This is very annoying as i want to be in same dir to run different commands as root sometimes and sometimes as normal user. How to fix this? (1 Reply)
Discussion started by: syncmaster
1 Replies

3. Shell Programming and Scripting

How to give root access to non root user?

Currently in my system Red Hat is installed. And Many user connect to my machine via SSH Techia Terminal. I want to give some users a root level access. Can anyone please help me how to make it possible. I too searched on the Google but didn't find the correct way Regards ADI (4 Replies)
Discussion started by: adisky123
4 Replies

4. UNIX for Advanced & Expert Users

Root and non-root user not able to delete the file

Hi!! one strange problem occurred with my RHEL 5 box. i'm having logs folder with ownership of non-root user. Created some files with root user under logs folder. here is the scene: -rw-r----- 1 root root 1048227 Feb 28 12:34 SystemOut_13.02.28_12.34.10.log -rw-r----- 1 root root ... (6 Replies)
Discussion started by: sukhdip
6 Replies

5. UNIX for Dummies Questions & Answers

Sudo to delegate permission from non-root user to another non-root user

I've been through many threads before i decide to create a separate thread. I can't really find the solution to my (simple) problem. Here's what I'm trying to achieve: As "canar" user I want to run a command, let's say "/opt/ocaml/bin/ocaml" as "duck" user. The only to achieve this is to... (1 Reply)
Discussion started by: canar
1 Replies

6. AIX

find command to list all the 777 files and directories owned by root user

Hi I'm logged in to an AIX box now and we need to do an audit on this box. cbssapr01:# pwd / Which command will show all the files and directories owned by root user with permissions as 777 ? (8 Replies)
Discussion started by: newtoaixos
8 Replies

7. UNIX for Dummies Questions & Answers

How to allow access to some commands having root privleges to be run bu non root user

hi i am new to unix and i have abig task. i have to \run particular commands having root privileges from a non root user. i know sudo is one of the way but i need sum other approach kindly help Thanks (5 Replies)
Discussion started by: suryashikha
5 Replies

8. UNIX for Dummies Questions & Answers

deleting another user's files

hi, I have two users, let us call them A and B. I do as User A touch tmpfile chmod 700 tmpfile Now as User B I do rm tmpfile - and it allows me to do it (after prompting me)...why? If I had done chmod 777 tmpfile, then sure User B should be able to delete it, but I did chmod 700... (3 Replies)
Discussion started by: JamesByars
3 Replies

9. Shell Programming and Scripting

Script for Deleting Core files on root filesystem

ok i am setting up a script to run daily using crontab. This script will search the root filesystem and delete any and all core files. I have set up this script The only problem i get with this script is it searches for directories and attempts to delete them. Since i have probably... (7 Replies)
Discussion started by: rgfirefly24
7 Replies

10. UNIX for Advanced & Expert Users

Other than root user .Normal user is unable to create files

Hi all, I am using Sun Solaris 9 .In this system normal users unable to create files from the command line.I added these users in bin,adm and even root group i found them unable to create a file. (1 Reply)
Discussion started by: mallesh
1 Replies
Login or Register to Ask a Question