HOME is not set when exploiting a vulnerability
I have an error
sh: line 61: cd: HOME not set.
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
2) login with samba userman script exploit:
3) ssh with password (cd is working):
environment-variables home
|
show 6 more comments
I have an error
sh: line 61: cd: HOME not set.
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
2) login with samba userman script exploit:
3) ssh with password (cd is working):
environment-variables home
1
What distribution is this? Just set theHOME
environment variable. What shell are you using?
– James Mills
Jun 13 '15 at 15:10
Pleasecat /root/.bashrc
andcat /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 thecase "$TERM"
esac
part
– Michael Durrant
Jun 13 '15 at 16:05
|
show 6 more comments
I have an error
sh: line 61: cd: HOME not set.
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
2) login with samba userman script exploit:
3) ssh with password (cd is working):
environment-variables home
I have an error
sh: line 61: cd: HOME not set.
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
2) login with samba userman script exploit:
3) ssh with password (cd is working):
environment-variables home
environment-variables home
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 theHOME
environment variable. What shell are you using?
– James Mills
Jun 13 '15 at 15:10
Pleasecat /root/.bashrc
andcat /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 thecase "$TERM"
esac
part
– Michael Durrant
Jun 13 '15 at 16:05
|
show 6 more comments
1
What distribution is this? Just set theHOME
environment variable. What shell are you using?
– James Mills
Jun 13 '15 at 15:10
Pleasecat /root/.bashrc
andcat /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 thecase "$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
|
show 6 more comments
1 Answer
1
active
oldest
votes
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.
if you are insh
orbash
: if/whenHOME
is not set, you can set it viaif [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi
– Trevor Boyd Smith
Mar 13 '18 at 18:35
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
if you are insh
orbash
: if/whenHOME
is not set, you can set it viaif [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi
– Trevor Boyd Smith
Mar 13 '18 at 18:35
add a comment |
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.
if you are insh
orbash
: if/whenHOME
is not set, you can set it viaif [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi
– Trevor Boyd Smith
Mar 13 '18 at 18:35
add a comment |
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.
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.
answered Jun 14 '15 at 17:40
GillesGilles
533k12810721594
533k12810721594
if you are insh
orbash
: if/whenHOME
is not set, you can set it viaif [ -z "${HOME:-}" ]; then export HOME="$(cd ~ && pwd)"; fi
– Trevor Boyd Smith
Mar 13 '18 at 18:35
add a comment |
if you are insh
orbash
: if/whenHOME
is not set, you can set it viaif [ -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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
andcat /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