1

I need help with loading software that has a built-in platform_check script. My plan is to create a script titled uname which when executed will print an accepted platform. The script works as I need it to but I can't figure out how to get the uname command to search for my custom uname script instead of the /bin/uname default. I have tried using PATH something like PATH=~/.../path_to_uname:$PATH this does not work. I do not have root access so I cant just edit/create uname in its default location.

when I execute the script like so: exec /directory_to_uname/uname and /directory_to_uname/uname -r both work as I intend them I just need to trick the shell to look for my custom uname.

toolic
  • 57,801
  • 17
  • 75
  • 117
  • If you don't have sudo access, this doesn't seem possible unless you can modify the software loader. (If it were, it would be a huge security gap.) In that case, you don't need a script at all. Just hard wire the platform name you want. Another thing is that it doesn't seem likely that fooling the installer will end well. Installers need to know the system type to customize the package to fit the environment. Lying isn't advisable. As in the rest of life, what goes around comes around. – Gene Dec 22 '21 at 02:22
  • When you said you tried `PATH=~/.../path_to_uname:$PATH`, did you use the full path to your uname script itself, or the path to the folder where your uname is? You need the latter. – jimtut Dec 22 '21 at 14:34

3 Answers3

1

You can try to use alias to trick the shell. For example (using bash) edit ~/.bashrc and add alias uname='path/to/uname uname'. execute source ~/.bashrc and the command uname will get the one from alias. If you change it for alias uname='ls -lha' and load (source command) when executing uname it will list the files/dir.

Lucas Dias
  • 109
  • 4
  • Good idea, but any decent install script will deliberately use a shell without user variable settings to prevent exactly what the OP is trying to do. They want a pristine environment to avoid weird problems. – Gene Dec 22 '21 at 02:25
  • 1
    I do see how this could work thank you, definitely trying using this method. @Gene thanks for the heads up about this not working even if we get it to load, we were running out of options. Sadly, we cant boot up older vms due to security reasons. – Marcos Laureano Dec 22 '21 at 02:36
1

Assuming you have a platform check script that is calling uname as such, let's call it test.sh:

#!/bin/bash
uname

Initial run shows uname as expected:

user@computer:~$ ./test.sh 
Linux

Export uname as a bash function to echo what you want to use for trickery:

user@computer:~$ function uname {
> echo "hello"
> }
user@computer:~$ export -f uname
user@computer:~$ ./test.sh 
hello
tajacks
  • 71
  • 6
0

In order to know which files are accessed/used during a command, you can use the strace command:

strace -y uname

You'll get a whole bunch of files and processes which are used, and you might see if any can be adapted to your needs.

This, however, is quite dangerous (who knows what might be the side-effects?) therefore I would advise you creating and alias for the uname command.

Dominique
  • 16,450
  • 15
  • 56
  • 112