[CentOS] bash file direct execution

dan1 dan1 at edenpics.com
Tue Aug 2 12:15:13 UTC 2005


Hello, Will. Inline answers are below..

>Ah, I was sat in /usr/share/file at the time. Does...
>
>$ ls -l /usr/share/file/magic /usr/share/magic
>-rw-r--r--  1 root root 356854 Apr 28 06:08 /usr/share/file/magic
>lrwxrwxrwx  1 root root     10 May 31 11:15 /usr/share/magic -> file/magic
>
>Look OK on your system?

Yes, exactly the same.

>If you actually less the file do its contents
>look OK? You should have a bunch of enties along the lines of...
>#------------------------------------------------------------------------------
># commands:  file(1) magic for various shells and interpreters
>#
>0       string          :                       shell archive or
>script for antique kernel text
>0       string/b        #!\ /bin/sh             Bourne shell script
>text executable
>0       string/b        #!\ /bin/csh            C shell script text 
>executable
># korn shell magic, sent by George Wu, gwu at clyde.att.com
>0       string/b        #!\ /bin/ksh            Korn shell script text
>executable

Yes, exactly the same lines of code. At least, now I know a bit more how the 
shell is run when directly running the command. :-)

>What happens if you just type in "ldd" without quotes, that's a shell
>script and it's in your PATH.

This is something interesting. If I run 'ldd', it works.
Now I copied this script to the / directory and run it again with /ldd. That 
works too.
Now I have transformed that file into my little echo script:
#!/bin/sh
echo testing

And that works too. So I have now two files (/ldd and /ldd2) which are 
scripts and which contains exactly the same content and which behaves 
differently, from the same directory. One is done from scratch and the other 
is modified from another working script.

Again each file's contents:
#! /bin/sh
echo testing

The result is the following when executed:
[root at box /]# ./ldd
testing
[root at box /]# ./ldd2
[root at box /]#

Here is the file's permissions:
-rwxr-xr-x    1 root root    25 Aug  2 14:07 ldd
-rwxr-xr-x    1 root root    25 Aug  2 14:07 ldd2

Strange, isn't it ? Is there something else as suid bits or so which could 
be mixed up ?


>What about aliases and the rest of your shell environment, is there
>anything out of the ordinary in there? What's the output of set and
>env ?

Here are the results:
[root at box /]# set
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="00" [2]="15" [3]="1" [4]="release" 
[5]="i686-redhat-linux-gnu")
BASH_VERSION='3.00.15(1)-release'
COLORS=/etc/DIR_COLORS.xterm
COLUMNS=157
DIRSTACK=()
EUID=0
GROUPS=()
G_BROKEN_FILENAMES=1
HISTFILE=/root/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
HOME=/root
HOSTNAME=box.mydomain.com
HOSTTYPE=i686
IFS=$' \t\n'
INPUTRC=/etc/inputrc
JAVA_HOME=/usr/java/j2sdk
KDEDIR=/usr
LANG=en_US.UTF-8
LESSOPEN='|/usr/bin/lesspipe.sh %s'
LINES=60
LOGNAME=root
LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:'
MACHTYPE=i686-redhat-linux-gnu
MAIL=/var/spool/mail/root
MAILCHECK=60
OLDPWD=/root
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/root/bin
PIPESTATUS=([0]="0")
PPID=3077
PROMPT_COMMAND='echo -ne 
"\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
PS1='[\u@\h \W]\$ '
PS2='> '
PS4='+ '
PWD=/
QTDIR=/usr/lib/qt-3.3
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_CLIENT='::ffff:89.214.2.219 2074 22'
SSH_CONNECTION='::ffff:89.214.2.219 2074 ::ffff:151.35.1.234 22'
SSH_TTY=/dev/pts/1
SUPPORTED=en_US.UTF-8:en_US:en
TERM=xterm
UID=0
USER=root
_=./testing1


[root at anoigo /]# env
HOSTNAME=box.mydomain.com
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=::ffff:89.214.2.219 2074 22
QTDIR=/usr/lib/qt-3.3
OLDPWD=/root
SSH_TTY=/dev/pts/1
USER=root
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:
KDEDIR=/usr
MAIL=/var/spool/mail/root
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/root/bin
INPUTRC=/etc/inputrc
PWD=/
JAVA_HOME=/usr/java/j2sdk
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION=::ffff:89.214.2.219 2074 ::ffff:151.35.1.234 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env


Kind regards,
Daniel





More information about the CentOS mailing list