Block binary execution

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Block binary execution
# 1  
Old 11-07-2013
RedHat Block binary execution

Hi guys,

Is it possible on rhel 6.2 to block execution of a binary and display a custom message on stdout or stderr?

thanks

Last edited by gkout; 11-07-2013 at 07:20 PM..
# 2  
Old 11-07-2013
If this is system-wide ian it is NOT a unix command ( e.g., a file in /usr/bin, /usr/local/bin, /usr/sbin, yes.

Code:
cd /path/to/binaryfiles
mv binaryfile binaryfile.keep
echo "Warning you cannot execute this file!!" > binaryfile
chmod +x binaryfile

If you do this to a unix command you will break the system - i.e., it probably will no longer reboot, lots of existing code will break.
# 3  
Old 11-07-2013
Quote:
Originally Posted by jim mcnamara
If this is system-wide ian it is NOT a unix command ( e.g., a file in /usr/bin, /usr/local/bin, /usr/sbin, yes.

Code:
cd /path/to/binaryfiles
mv binaryfile binaryfile.keep
echo "Warning you cannot execute this file!!" > binaryfile
chmod +x binaryfile

If you do this to a unix command you will break the system - i.e., it probably will no longer reboot, lots of existing code will break.
First, I must emphasize (like Jim did) that you should NOT do this to any binary that is supplied as part of your operating system.

Although Jim's suggestion will make attempts to run binaryfile produce an error message, the error message you get would be something like:
Code:
sh: Warning: not found

I think what was intended was something more like:
Code:
echo 'echo "Warning you cannot execute this file!!"' > binaryfile

which would instead print:
Code:
Warning you cannot execute this file!!

when someone tries to run binaryfile.
# 4  
Old 11-08-2013
Thank you both for your reply, but the idea would be to avoid manipulating the binary itself, as we need to do exactly the opposite with an allowed binary.

Run it and display a message that this is an allowed binary.
# 5  
Old 11-08-2013
It isn't easy to change the way an application behaves without changing the application.

I almost didn't post this, because the idea of trying to use a system that has been mangled like this is just abhorrent to me. And the same WARNINGS still apply: If you do this to any utility provided as part of your operating system, you may turn your computer into a doorstop.

But, here is a modified version of Jim's code that seems to do what you want. Save it in a file, make it executable, and invoke it with the name of one program to modify as its only argument:
Code:
cd /path/to/binaryfiles
mv "$1" "$1.real"
printf 'echo "You have permission to run %s."\nexec "$PWD/%s.real" "$@"\n' \
        "$1" "$1" > "$1"
chmod +x "$1"

Please do everything you can to convince whoever came up with this idea, that it is a horrible idea and should not be implemented. (Imagine how we'll the above script would work if printf wasn't a shell built-in and you used this script to change printf before you used it to change another program. Any program replaced by this script that has it's output redirected into a file will corrupt that file. Any program replaced by this script that is included in a pipeline will require that the next program in the pipeline be changed to discard the line that the modified program should never have printed.)
# 6  
Old 11-11-2013
I was thinking more of pam limits or cgroups, but the hard part is to have this stupid message displayed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Another Building Block, Binary File Manipulation...

Apologies for any typos, and IF this has been done before... This is yet another building block. The code generates a 256 byte binary file of _characters_ 0x00 to 0xFF for general usage and generates another binary file manipulated in a basic way. I need this facility for a kids project I am... (0 Replies)
Discussion started by: wisecracker
0 Replies

2. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

3. Emergency UNIX and Linux Support

Which OS Binary was build

We have recently installed RHEL 5.4 on some existing 6.2 OS and migrated our code from RH 6.2 to RHEL 5.4. We are facing a difficulty that given a binary (on both OS they have same name) how can we distinguish that which gcc and OS it was build as there are some minor differences in between binary... (2 Replies)
Discussion started by: uunniixx
2 Replies

4. AIX

how to create a variable block binary file on AIX

:confused: Hi there I have a requirement to create a variable block binary file on AIX. Once the file has been feed with info , the file needs to be ftp to MVS. The problem experienced; when transferring the file to MVS. MVS does not pick up the carriage return line feed, which OA OD ... (0 Replies)
Discussion started by: Luke21
0 Replies

5. Shell Programming and Scripting

Expect Issue Serial Forground Execution vs Concurrent Background Execution

I have an expect script that interrogates several hundred unix servers for both access and directories therein using "ssh user@host ls -l /path". The combination of host/path are unique but the host may be interrogated multiple times if there are multiple paths to test. The expect script is run... (2 Replies)
Discussion started by: twk
2 Replies

6. Solaris

compiled binary file gives "cannot execute binary file"

Hi, I have two Solaris machines. 1. SunOS X 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Blade-1500 2. SunOS Y 5.8 Generic_108528-13 sun4u sparc SUNW,Ultra-60 I am trying to buiild a project on both these machines. The Binary output file compiled on machine 2 runs on both the machines. Where... (0 Replies)
Discussion started by: scgupta
0 Replies

7. UNIX for Dummies Questions & Answers

Where is M4 binary?

Hello, I am configurating Sendmail on Mac OS 10.x terminal. I tried to execute m4 to generate a new sendmail.cf. It complains "Command not found". Anybody knows where the m4 binary is? Is it something coming along with Unix or Sendmail? Appreciate any help. Thanks in advance. pw (2 Replies)
Discussion started by: hypamw
2 Replies

8. Shell Programming and Scripting

is it text or binary

I need to know from a script if a given file is a text file (ascii) or binary. I need it in order to do dos2unix on each text file - and not on binary files (1 Reply)
Discussion started by: avnerht
1 Replies

9. UNIX for Dummies Questions & Answers

Binary Files

Here's the problem... I'm using a simulator on UNIX, and it requires a filename where bits are stored, it should read them out and do whatever with them at that point.. So what i'm trying to do is make a binary file on UNIX. On my PC i can use MSDEV, or any of my C++ compilers to generate a... (2 Replies)
Discussion started by: wcRandThor
2 Replies
Login or Register to Ask a Question