Sponsored Content
Top Forums Shell Programming and Scripting Setuid not working in Linux as script fails to write to file. Post 302827429 by Just Ice on Friday 28th of June 2013 04:26:38 PM
Old 06-28-2013
another option is to port the script into c program binary ... chmod 711 binary and place it in a protected directory ... users can then run the program at will without being able to read anything as long as they have the correct path ... encrypt all source code in a protected directory ... sample below runs hostname in shtest ... lstest is just a copty of /bin/ls ...

if taking this option, make sure you account for what the users may want to change (i.e., different file path, current time, logfile name, etc.) so there is no constant recompile and looking at the sourcecode ...

from regular user perspective:
Code:
otto@susegeek:/tmp> cd testdir
otto@susegeek:/tmp/testdir> ls -ld
drwxr-xr-x 3 root root 4096 Jun 28 15:48 .
otto@susegeek:/tmp/testdir> ls -l
total 4
drwx--x--x 2 root root 4096 Jun 28 15:39 700
-rw-r--r-- 1 root root    0 Jun 28 15:48 test1
-rw-r--r-- 1 root root    0 Jun 28 15:48 test2
-rw-r--r-- 1 root root    0 Jun 28 15:48 test3
-rw-r--r-- 1 root root    0 Jun 28 15:48 test4
-rw-r--r-- 1 root root    0 Jun 28 15:48 test5
otto@susegeek:/tmp/testdir> ls -l 700
ls: cannot open directory 700: Permission denied
otto@susegeek:/tmp/testdir> ls -l 700/shtest
-rwx--x--x 1 root root 33 Jun 28 15:21 700/shtest
otto@susegeek:/tmp/testdir> ls -l 700/lstest
-rwx--x--x 1 root root 112892 Feb 18  2011 700/lstest
otto@susegeek:/tmp/testdir> 700/shtest
/bin/ksh: 700/shtest: cannot open [Permission denied]
otto@susegeek:/tmp/testdir> 700/lstest
700  test1  test2  test3  test4  test5
otto@susegeek:/tmp/testdir> strings 700/lstest
strings: 700/lstest: Permission denied
otto@susegeek:/tmp/testdir> cat 700/shtest
cat: 700/shtest: Permission denied
otto@susegeek:/tmp/testdir>

from root's perpective:
Code:
susegeek:/tmp/testdir # ls -ld .
drwxr-xr-x 3 root root 4096 Jun 28 15:48 .
susegeek:/tmp/testdir # ls -ld *
drwx--x--x 2 root root 4096 Jun 28 15:39 700
-rw-r--r-- 1 root root    0 Jun 28 15:48 test1
-rw-r--r-- 1 root root    0 Jun 28 15:48 test2
-rw-r--r-- 1 root root    0 Jun 28 15:48 test3
-rw-r--r-- 1 root root    0 Jun 28 15:48 test4
-rw-r--r-- 1 root root    0 Jun 28 15:48 test5
susegeek:/tmp/testdir # ls -l 700
total 116
-rwx--x--x 1 root root 112892 Feb 18  2011 lstest
-rwx--x--x 1 root root     33 Jun 28 15:21 shtest
susegeek:/tmp/testdir # file 700/*
700/lstest: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.4, stripped
700/shtest: Korn shell script text
susegeek:/tmp/testdir # 700/shtest
susegeek
susegeek:/tmp/testdir # 700/lstest
700  test1  test2  test3  test4  test5
susegeek:/tmp/testdir #

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need to write a home-grown backup script for Linux

I am researching ways in which to backup files or whole file systems for backup to another system. We are using Suse Linux 7.0 with no tape backup devices or secondary disks. What utilities would be the best to use for a simple yet flexible script for backup purposes? tar, cpio, compress. (3 Replies)
Discussion started by: darthur
3 Replies

2. Shell Programming and Scripting

log file when the script fails !

i have a script that will retrive some info from database. The script is working fine but i have to add new feature in it when the script fails or retrive null result it should reflect in the log file. below the script AMR_Inactive.sh while read i do connect1=`sqlplus -silent... (3 Replies)
Discussion started by: ali560045
3 Replies

3. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

4. UNIX for Advanced & Expert Users

when a process fails to write to /dev/log

Hi , when a process fails to write to /dev/log ? (1 Reply)
Discussion started by: Gopi Krishna P
1 Replies

5. UNIX for Dummies Questions & Answers

a problem with write a script in Linux version 2.4.27-ubnt0

Hello everyone, I have a radio wireless called UBNT Nanostation5 It has this linux OS:Linux version 2.4.27-ubnt0 When i want to write a script in ssh, i get some errors The script is: ifconfig eth0 down ifconfig eth0 hw ether 00:15:6D:**:**:** ifconfig eth0 up cfg -x echo... (1 Reply)
Discussion started by: cygol
1 Replies

6. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

7. Red Hat

process fails if setuid bit is set

Hi, OS : Linux I have an executable (P1) owned by user say "abcd" and the setuid bit is set. And there is another executable (P2) which brings up the process (P1). When the setuid bit is set, the process P1 is failing, if the setuid bit is not set there is no issue. I was wondering if... (6 Replies)
Discussion started by: ahamed101
6 Replies

8. UNIX for Beginners Questions & Answers

Linux shell | how to exit a script if any command fails.

Hi, i am new here let me say HI for all. now i have a question please: i am sending one command to my machine to create 3 names. if one of the names exists then the box return error message that already have the name but will continue to create the rests. How i can break the command and... (7 Replies)
Discussion started by: Amiri
7 Replies

9. UNIX for Beginners Questions & Answers

What keeps me from abusing setuid(0) and programs with setuid bit set?

Just learning about the privilege escalation method provided by setuid. Correct me if I am wrong but what it does is change the uid of the current process to whatever uid I set. Right ? So what stops me from writing my own C program and calling setuid(0) within it and gaining root privileges ? ... (2 Replies)
Discussion started by: sreyan32
2 Replies
machid(1)						      General Commands Manual							 machid(1)

NAME
machid: hp9000s200, hp9000s300, hp9000s400, hp9000s500, hp9000s700, hp9000s800, hp-mc680x0, hp-pa, pdp11, u370, u3b, u3b10, u3b2, u3b5, vax - provide truth value about processor type SYNOPSIS
DESCRIPTION
The following commands return a true value (exit code 0) if the a processor type matches the command name. Otherwise a false value (exit code nonzero) is returned. These commands are commonly used within makefiles and shell procedures to improve portability of applications (see make(1)). +-----------+-------------------------++--------+--------------------------+ |Command | True for ||Command | True for | +-----------+-------------------------++--------+--------------------------+ |hp9000s200 | Series 200 ||pdp11 | PDP-11/45 or PDP-11/70 | |hp9000s300 | Series 300 ||u3b | 3B20 computer | |hp9000s400 | Series 400 ||u3b2 | 3B2 computer | |hp9000s500 | Series 500 ||u3b5 | 3B5 computer | |hp9000s700 | Series 700 ||u3b10 | 3B10 computer | |hp9000s800 | Series 800 or 700 ||u370 | IBM System/370 computer | |hp-mc680x0 | Series 200, 300, or 400 ||vax | VAX-11/750 or VAX-11/780 | |hp-pa | Series 700 or 800 || | | +-----------+-------------------------++--------+--------------------------+ EXAMPLES
Given a shell script that must behave differently when run on an HP 9000 Series 700 or 800 system, select the correct code segment to be executed: WARNINGS
always returns true on both Series 800 and Series 700 systems. Therefore, when using this command in scripts to determine hardware type, always use both and in the appropriate sequence to ensure correct results (see machid(1) will no longer provide support for future machines beyond the Series 800 and Series 700 systems. Decisions should be based on the hardware and software configuration information returned by getconf(1). SEE ALSO
getconf(1), make(1), sh(1), test(1), true(1). machid(1)
All times are GMT -4. The time now is 06:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy