HOME is not set when exploiting a vulnerability












1















I have an error
sh: line 61: cd: HOME not set.



enter image description here



Distribution: Metasploitable 2 (Ubuntu 8.04)



/root/.bashrc (comments and whitespace removed):



[ -z "$PS1" ] && return
shopt -s checkwinsize
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in
xterm-color)
PS1='${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[00m]$ '
;;
*)
PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
;;
esac
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "33]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}07"'
;;
*)
;;
esac
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
fi


cat /root/.profile



# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n


ps -p $$ -ocomm=



sh


I tried to use "rlogin -l root x.x.x.x" from my kali to this machine, but it did not work. The .rhosts files are ok, but i get this error message, so maybe this is the reason why it doesnt work.



1) login with telnet using backdoor at 1524



enter image description here



2) login with samba userman script exploit:



enter image description here



3) ssh with password (cd is working):



enter image description here










share|improve this question




















  • 1





    What distribution is this? Just set the HOME environment variable. What shell are you using?

    – James Mills
    Jun 13 '15 at 15:10











  • Please cat /root/.bashrc and cat /root/.profile

    – Michael Durrant
    Jun 13 '15 at 15:14











  • @MichaelDurrant no, we'd rather have all information here. That's what code blocks are for.

    – terdon
    Jun 13 '15 at 15:26











  • Please edit your question and add i) your OS; ii) if Linux, your distribution; iii) the files that Michael Durrant asked for; iv) your shell (ps -p $$ -ocomm=)

    – terdon
    Jun 13 '15 at 15:29











  • Try commenting out the case "$TERM" esac part

    – Michael Durrant
    Jun 13 '15 at 16:05


















1















I have an error
sh: line 61: cd: HOME not set.



enter image description here



Distribution: Metasploitable 2 (Ubuntu 8.04)



/root/.bashrc (comments and whitespace removed):



[ -z "$PS1" ] && return
shopt -s checkwinsize
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in
xterm-color)
PS1='${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[00m]$ '
;;
*)
PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
;;
esac
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "33]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}07"'
;;
*)
;;
esac
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
fi


cat /root/.profile



# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n


ps -p $$ -ocomm=



sh


I tried to use "rlogin -l root x.x.x.x" from my kali to this machine, but it did not work. The .rhosts files are ok, but i get this error message, so maybe this is the reason why it doesnt work.



1) login with telnet using backdoor at 1524



enter image description here



2) login with samba userman script exploit:



enter image description here



3) ssh with password (cd is working):



enter image description here










share|improve this question




















  • 1





    What distribution is this? Just set the HOME environment variable. What shell are you using?

    – James Mills
    Jun 13 '15 at 15:10











  • Please cat /root/.bashrc and cat /root/.profile

    – Michael Durrant
    Jun 13 '15 at 15:14











  • @MichaelDurrant no, we'd rather have all information here. That's what code blocks are for.

    – terdon
    Jun 13 '15 at 15:26











  • Please edit your question and add i) your OS; ii) if Linux, your distribution; iii) the files that Michael Durrant asked for; iv) your shell (ps -p $$ -ocomm=)

    – terdon
    Jun 13 '15 at 15:29











  • Try commenting out the case "$TERM" esac part

    – Michael Durrant
    Jun 13 '15 at 16:05
















1












1








1








I have an error
sh: line 61: cd: HOME not set.



enter image description here



Distribution: Metasploitable 2 (Ubuntu 8.04)



/root/.bashrc (comments and whitespace removed):



[ -z "$PS1" ] && return
shopt -s checkwinsize
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in
xterm-color)
PS1='${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[00m]$ '
;;
*)
PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
;;
esac
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "33]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}07"'
;;
*)
;;
esac
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
fi


cat /root/.profile



# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n


ps -p $$ -ocomm=



sh


I tried to use "rlogin -l root x.x.x.x" from my kali to this machine, but it did not work. The .rhosts files are ok, but i get this error message, so maybe this is the reason why it doesnt work.



1) login with telnet using backdoor at 1524



enter image description here



2) login with samba userman script exploit:



enter image description here



3) ssh with password (cd is working):



enter image description here










share|improve this question
















I have an error
sh: line 61: cd: HOME not set.



enter image description here



Distribution: Metasploitable 2 (Ubuntu 8.04)



/root/.bashrc (comments and whitespace removed):



[ -z "$PS1" ] && return
shopt -s checkwinsize
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
case "$TERM" in
xterm-color)
PS1='${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[00m]$ '
;;
*)
PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
;;
esac
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "33]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}07"'
;;
*)
;;
esac
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
fi


cat /root/.profile



# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

mesg n


ps -p $$ -ocomm=



sh


I tried to use "rlogin -l root x.x.x.x" from my kali to this machine, but it did not work. The .rhosts files are ok, but i get this error message, so maybe this is the reason why it doesnt work.



1) login with telnet using backdoor at 1524



enter image description here



2) login with samba userman script exploit:



enter image description here



3) ssh with password (cd is working):



enter image description here







environment-variables home






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago









Rui F Ribeiro

39.6k1479132




39.6k1479132










asked Jun 13 '15 at 14:43









BlackCatBlackCat

1851415




1851415








  • 1





    What distribution is this? Just set the HOME environment variable. What shell are you using?

    – James Mills
    Jun 13 '15 at 15:10











  • Please cat /root/.bashrc and cat /root/.profile

    – Michael Durrant
    Jun 13 '15 at 15:14











  • @MichaelDurrant no, we'd rather have all information here. That's what code blocks are for.

    – terdon
    Jun 13 '15 at 15:26











  • Please edit your question and add i) your OS; ii) if Linux, your distribution; iii) the files that Michael Durrant asked for; iv) your shell (ps -p $$ -ocomm=)

    – terdon
    Jun 13 '15 at 15:29











  • Try commenting out the case "$TERM" esac part

    – Michael Durrant
    Jun 13 '15 at 16:05
















  • 1





    What distribution is this? Just set the HOME environment variable. What shell are you using?

    – James Mills
    Jun 13 '15 at 15:10











  • Please cat /root/.bashrc and cat /root/.profile

    – Michael Durrant
    Jun 13 '15 at 15:14











  • @MichaelDurrant no, we'd rather have all information here. That's what code blocks are for.

    – terdon
    Jun 13 '15 at 15:26











  • Please edit your question and add i) your OS; ii) if Linux, your distribution; iii) the files that Michael Durrant asked for; iv) your shell (ps -p $$ -ocomm=)

    – terdon
    Jun 13 '15 at 15:29











  • Try commenting out the case "$TERM" esac part

    – Michael Durrant
    Jun 13 '15 at 16:05










1




1





What distribution is this? Just set the HOME environment variable. What shell are you using?

– James Mills
Jun 13 '15 at 15:10





What distribution is this? Just set the HOME environment variable. What shell are you using?

– James Mills
Jun 13 '15 at 15:10













Please cat /root/.bashrc and cat /root/.profile

– Michael Durrant
Jun 13 '15 at 15:14





Please cat /root/.bashrc and cat /root/.profile

– Michael Durrant
Jun 13 '15 at 15:14













@MichaelDurrant no, we'd rather have all information here. That's what code blocks are for.

– terdon
Jun 13 '15 at 15:26





@MichaelDurrant no, we'd rather have all information here. That's what code blocks are for.

– terdon
Jun 13 '15 at 15:26













Please edit your question and add i) your OS; ii) if Linux, your distribution; iii) the files that Michael Durrant asked for; iv) your shell (ps -p $$ -ocomm=)

– terdon
Jun 13 '15 at 15:29





Please edit your question and add i) your OS; ii) if Linux, your distribution; iii) the files that Michael Durrant asked for; iv) your shell (ps -p $$ -ocomm=)

– terdon
Jun 13 '15 at 15:29













Try commenting out the case "$TERM" esac part

– Michael Durrant
Jun 13 '15 at 16:05







Try commenting out the case "$TERM" esac part

– Michael Durrant
Jun 13 '15 at 16:05












1 Answer
1






active

oldest

votes


















4














When you log in via a normal method (on the console, over SSH, etc.), the program handling the login sets a few environment variables, including HOME. If you get access to a shell not via logging in, but by exploiting a vulnerability in a program, you get that program's environment, which often but not always includes HOME.



In bash, for some reason, the cd command with no argument uses the value of HOME as the target. Tilde expansion, however, falls back to the home directory from the user database (e.g. /etc/passwd) if HOME is not set. So if HOME is not set, cd complains, but cd ~ changes to the user's home directory. cd $HOME runs cd with no argument when HOME is not set.



When you're exploiting a vulnerability, you can't count on the environment being a familiar one. It's part of the craft of making an exploit — the easy part — to go from being able to execute code (e.g. having a shell) to setting up a convenient environment to run standard code.






share|improve this answer
























  • if you are in sh or bash: if/when HOME is not set, you can set it via if [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi

    – Trevor Boyd Smith
    Mar 13 '18 at 18:35













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f209429%2fhome-is-not-set-when-exploiting-a-vulnerability%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














When you log in via a normal method (on the console, over SSH, etc.), the program handling the login sets a few environment variables, including HOME. If you get access to a shell not via logging in, but by exploiting a vulnerability in a program, you get that program's environment, which often but not always includes HOME.



In bash, for some reason, the cd command with no argument uses the value of HOME as the target. Tilde expansion, however, falls back to the home directory from the user database (e.g. /etc/passwd) if HOME is not set. So if HOME is not set, cd complains, but cd ~ changes to the user's home directory. cd $HOME runs cd with no argument when HOME is not set.



When you're exploiting a vulnerability, you can't count on the environment being a familiar one. It's part of the craft of making an exploit — the easy part — to go from being able to execute code (e.g. having a shell) to setting up a convenient environment to run standard code.






share|improve this answer
























  • if you are in sh or bash: if/when HOME is not set, you can set it via if [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi

    – Trevor Boyd Smith
    Mar 13 '18 at 18:35


















4














When you log in via a normal method (on the console, over SSH, etc.), the program handling the login sets a few environment variables, including HOME. If you get access to a shell not via logging in, but by exploiting a vulnerability in a program, you get that program's environment, which often but not always includes HOME.



In bash, for some reason, the cd command with no argument uses the value of HOME as the target. Tilde expansion, however, falls back to the home directory from the user database (e.g. /etc/passwd) if HOME is not set. So if HOME is not set, cd complains, but cd ~ changes to the user's home directory. cd $HOME runs cd with no argument when HOME is not set.



When you're exploiting a vulnerability, you can't count on the environment being a familiar one. It's part of the craft of making an exploit — the easy part — to go from being able to execute code (e.g. having a shell) to setting up a convenient environment to run standard code.






share|improve this answer
























  • if you are in sh or bash: if/when HOME is not set, you can set it via if [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi

    – Trevor Boyd Smith
    Mar 13 '18 at 18:35
















4












4








4







When you log in via a normal method (on the console, over SSH, etc.), the program handling the login sets a few environment variables, including HOME. If you get access to a shell not via logging in, but by exploiting a vulnerability in a program, you get that program's environment, which often but not always includes HOME.



In bash, for some reason, the cd command with no argument uses the value of HOME as the target. Tilde expansion, however, falls back to the home directory from the user database (e.g. /etc/passwd) if HOME is not set. So if HOME is not set, cd complains, but cd ~ changes to the user's home directory. cd $HOME runs cd with no argument when HOME is not set.



When you're exploiting a vulnerability, you can't count on the environment being a familiar one. It's part of the craft of making an exploit — the easy part — to go from being able to execute code (e.g. having a shell) to setting up a convenient environment to run standard code.






share|improve this answer













When you log in via a normal method (on the console, over SSH, etc.), the program handling the login sets a few environment variables, including HOME. If you get access to a shell not via logging in, but by exploiting a vulnerability in a program, you get that program's environment, which often but not always includes HOME.



In bash, for some reason, the cd command with no argument uses the value of HOME as the target. Tilde expansion, however, falls back to the home directory from the user database (e.g. /etc/passwd) if HOME is not set. So if HOME is not set, cd complains, but cd ~ changes to the user's home directory. cd $HOME runs cd with no argument when HOME is not set.



When you're exploiting a vulnerability, you can't count on the environment being a familiar one. It's part of the craft of making an exploit — the easy part — to go from being able to execute code (e.g. having a shell) to setting up a convenient environment to run standard code.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jun 14 '15 at 17:40









GillesGilles

533k12810721594




533k12810721594













  • if you are in sh or bash: if/when HOME is not set, you can set it via if [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi

    – Trevor Boyd Smith
    Mar 13 '18 at 18:35





















  • if you are in sh or bash: if/when HOME is not set, you can set it via if [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi

    – Trevor Boyd Smith
    Mar 13 '18 at 18:35



















if you are in sh or bash: if/when HOME is not set, you can set it via if [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi

– Trevor Boyd Smith
Mar 13 '18 at 18:35







if you are in sh or bash: if/when HOME is not set, you can set it via if [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi

– Trevor Boyd Smith
Mar 13 '18 at 18:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f209429%2fhome-is-not-set-when-exploiting-a-vulnerability%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Loup dans la culture

How to solve the problem of ntp “Unable to contact time server” from KDE?

ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux