Running su noninteractively?

1

So, I got locked out of a server (sshd seems to have stopped responding). I got a reverse shell (added a jenkins job that gives me a reverse shell), but I've hit a snag - su wants a terminal, and refuses to run.

So, is there a way to run su noninteractively, or some other way of escalating to my normal user account?

hintss

Posted 2015-05-02T15:59:07.033

Reputation: 41

Answers

1

So, it turns out I didn't google this quite enough when I caved and made this question.

The answer is to do as https://serverfault.com/a/495154/68820 says, and run

python -c 'import pty; pty.spawn("/bin/sh")'

inside of the reverse shell, which gets you a pty.

Doing this, I was able to su to my normal user, and restart the sshd.

hintss

Posted 2015-05-02T15:59:07.033

Reputation: 41

And as you restart ssh will be wise to add jenkins in sudo :) – Romeo Ninov – 2015-05-02T16:31:02.680

but jenkins doesn't normally ever need sudo. doing so would be a security risk – hintss – 2015-05-02T16:32:08.497

No risk if you do not provide passwordless sudo access. And provide ability to sudo to standard user, not root – Romeo Ninov – 2015-05-02T16:33:36.937

0

Try with sudo. This is the contemporary (and much safe way)

Of commands like this:

echo "password"|su - -c "command"

echo -e "password\n"|su - -c "command"

Romeo Ninov

Posted 2015-05-02T15:59:07.033

Reputation: 2 062

the jenkins user doesn't have sudo access – hintss – 2015-05-02T16:10:09.443

Add to /etc/sudoers file the appropriate record for jenkins user – Romeo Ninov – 2015-05-02T16:10:53.823

1which I can't do without access to a more priviledged user – hintss – 2015-05-02T16:11:58.987

I am sure the machine in question have sysadmin to take care. So contact him/her and ask for those records – Romeo Ninov – 2015-05-02T16:13:14.917

1I am the sysadmin, the sshd died, so this is my only access to this box – hintss – 2015-05-02T16:14:02.037

try something like: echo "password"|su - -c "command" Or echo -e "password\n"|su - -c "command" – Romeo Ninov – 2015-05-02T16:16:40.667

regarding your edit, no, su will not run without a terminal, regardless. – hintss – 2015-05-02T16:22:49.713

also, I solved this via another solution already – hintss – 2015-05-02T16:23:03.323

So add your answer here (as own answer to the question) – Romeo Ninov – 2015-05-02T16:25:16.867