Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to copy an only executalbe file

Posted on 1997-12-14
4
Medium Priority
?
259 Views
Last Modified: 2010-04-21
Hi there,

I'd like to copy a file which is protected for writing as well as for reading. The only thing I can do is to execute it. Is it possible to copy a file like this to anywhere else? And if YES: How can I do it?

Thanks for your help
scotty

0
Comment
Question by:gageli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:rickyr
ID: 2008301
Hiya...

As a normal user you can't copy something if you aint got read permission, Unless of course you are root. If a file you want to copy is owned by you then read on.

add read permission to the file...
$ chmod u+r filetocopy
copy the file...
$ cp filetocopy copiedfile
take away read permission from the copied file...
$ chmod u-r copiedfile
take read permission away from the filetocopy...
$ chmod u-r filetocopy

or to automate this you could write a script...

launch vi...

$ vi

type the following....

#!/bin/sh
if [ $# -ne 2 ] ; then
echo usage mycp [ fromfile tofile ]
exit
fi
chmod u+r $1
cp $1 $2
chmod u-r $2
chmod u-r $1

type...

:w mycp

type...

Hold shift and type ZZ

then make your file executable...

$chmod u+x mycp

now type....

$ mycp filetocopy newfilename

What I have suggested is just a work around, This is why I have only supplied a comment and not an answer. the real answer to your question is "it cant be done unles your root"
I hope I helped
0
 
LVL 5

Expert Comment

by:n0thing
ID: 2008302
I agree with rickyr. You cannot copy an excutable only file.
You'll have be root or hacked root.

0
 
LVL 10

Accepted Solution

by:
rbr earned 150 total points
ID: 2008303
For copying the file you have to get read access. If the file isn't yours only the owner of the file or root can change the access. chmod a+r filename
0
 
LVL 3

Expert Comment

by:rickyr
ID: 2008304
Hi
You do not need to get the owner of the file to do this for you.
You can do this yourself if you know the password of the owner of
the file. then....

$> su file_owner
$> password: file_owner_passwd

This is of course a security risk (knowledge of others passwords), but the su utility is for switching users, whether you are super-user or a normal user.

$> su - file_owner

to get the new users environment, no hyphen to retain your environment.

The script I have mentioned above could be owned by the file_to_copy owner and given SUID access...
$> chmod u+s mycp
Then whoever runs it, it will be run as the owner of the file
file_to_copy. Beware of the security risks aswell. chmod a+r
will give read access to the world.

Okay gageli....
Whos been the most help here?
Maybe I should have supplied the above as an answer, but I believe "It cant be done, but heres a sloppy work around" is just not good enough for an answer, Go and get your points back.
regards
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question