Setuid not working in Linux as script fails to write to file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setuid not working in Linux as script fails to write to file.
# 15  
Old 06-28-2013
Just Ice,

Inline with your suggestion d I came up with a way to encrypt the file using gpg (GNU Privacy guard) and then decrypting it.
'
(1) First encrypt it using the below command which generates a binary encrypted file.

echo "some passphrase" |gpg --passphrase-fd 0 --output <full path of output encrypted file> --symmetric <full path of input file>

(2) Then delete the readable flat file

(3) Within my scripts, decrypt the encrypted environment file using
echo "above passphrase" |gpg --passphrase-fd 0 --output <full path of output decrypted file> --decrypt <full path of input encrypted file>

(4) Source the resulting decrypted flat file and read all variables defined in it and immediately delete it within the script.

With this approach nobody would be able to view the flat file as at any point there will only be an encrypted binary file in the file system.
However the caveat with this approach to hiding DB passwords in the env file from developers is that is that developers need to remember the passphrase to use with GPG.If they have access to passphrase anybody can decrypt the encrypted file.

Can you please suggest a mechanism to read the passphrase from somewhere so that nobody can actually see the passphrase but should be able to use it to encrypt and decrypt the envronment file without any problems ?


thanks
# 16  
Old 06-28-2013
if you have to have the passphrase, put it in a file in a protected directory (i.e., /home/sqadmin/.sqlpp) that is source in the beginning of the script as far away as the line sourcing the password and hidden within comments if you could do it ...
Code:
#! /bin/ksh
# jhkjhkhfkljhfkljhlkjh
. /home/sqadmin/.sqlpp #hgjhgjhghkhkjhkjhk
# kljhkjhkljhkljfhsklljljlj;lkj;lkj;lkj;l
# kjlkjdflkj;lkj;lkj;lkjk;k;'k;'lk;'k;l
# llkjlj;lkjlkj;lkjlkj;lkj;lj;lkj;lkjl;kjlk
# lkj;lkj;lkj;lkjlkjlkj;lj;lkjl;kjlkjlkjl
# lkj;lkjl;kjlkjjlkj;ljlkj;lkjljljlkjlkjljj

script=$0
admin=admin@some.com
log=/dir/log
password=$get_sql_pass
date=$(date +%Y%m%d)

.......
.......
......

exit 0

# 17  
Old 06-28-2013
. . . . . Deleted . . . . .
# 18  
Old 06-28-2013
Quote:
Originally Posted by waavman
Can you please suggest a mechanism to read the passphrase from somewhere so that nobody can actually see the passphrase but should be able to use it to encrypt and decrypt the envronment file without any problems ?
No, we cannot. If the script can decrypt it, so can anyone examining the script, since by necessity it contains complete instructions for doing so.
# 19  
Old 06-28-2013
You could PPK encrypt it using someone's public key, so only their private key can decode it. The private key is usually in a user-only-readable file 0400. Of course, root can peek!
# 20  
Old 06-28-2013
This nicely protects the public key, but I don't see how this prevents any access to the encrypted file. Same problem as before again. If the script can access the private key, so can they, if the script can decrypt the file from it so can they.

Last edited by Corona688; 06-28-2013 at 04:13 PM..
# 21  
Old 06-28-2013
The script can only decode if it has read access to the private key, so it has to be run by that user or root. Admittedly, the LINUX culture had gone sadly root/sudo, and that is only not-root-user-safe and no-backdoor-file-access-safe.

Beyond that, the problem becomes like a movie player/file that only plays when conditions are met. Most of them have been hacked open.

There is password encryption, where the script has to ask for the password.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
Login or Register to Ask a Question