Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 25 guests and 1 member online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Network Pen Testingarrow escaping restricted shell
EH-Net
May 23, 2013, 06:13:45 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1] 2   Go Down
  Print  
Author Topic: escaping restricted shell  (Read 9253 times)
0 Members and 1 Guest are viewing this topic.
wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« on: March 15, 2012, 09:55:26 AM »

I'm doing online challenges to improve my skills. However, my latest one is stumping me.

They give you a username/password to login with ssh and then it puts you in a restricted shell. all commands are disabled except for 'tee' and 'ls'. I am able to run things like 'set IFS=/' and have it accept that, but anything like 'set PATH=/bin/sh' will fail because they are read only. I have managed to break out of the shell a few times by pasting arbitrary code in there, but it doesn't seem to work with any regularity. I have been Googling for what seems like days to try to find something that will work 100% of the time, but I haven't found anything yet.

I can't run 'man' and then try to break out because that's disabled. I can't run 'vi', 'scp', etc, etc.

Does anyone know a better way to make it out of a restricted shell? I'm stumped here.
Logged
tturner
Sr. Member
****
Offline Offline

Posts: 432


View Profile WWW
« Reply #1 on: March 15, 2012, 01:55:45 PM »

How about

Code:
awk 'BEGIN {system("/bin/sh")}'

Not sure if you can use awk or not. If not, you could try using echo statements into a file to build a script to invoke /bin/sh with exec statements in Perl, Ruby, etc.

Another option is using less and more shell escapes using the !

Can you run sudo commands?




Logged

Certifications:
CISSP, CISA, GPEN, GWAPT, GAWN, GCIA, GCIH, GSEC, OPSE, CSWAE, CSTP, VCP

WIP: OSWP, GSSP-JAVA, GXPN

Udacity on hold, again. I suck.

http://sentinel24.com/blog  @tonylturner http://bsidesorlando.org
wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #2 on: March 15, 2012, 08:14:01 PM »

Hey, thanks for responding.

sudo and awk give me the same: restricted: cannot specify `/' in command names
I can use the echo statements but I can't redirect them to a file because it will give me the "cannot redirect output" error. I have found a few things where it will accept commands like:
umask 0
IFS=/;export IFS

However, trying to set the PATH or SHELL variables fails, because they are read-only. I'm really new to this kind of thing so there is a limit to my knowledge.

I did a scan with OpenVAS and it found:

OpenSSH CBC Mode Information Disclosure Vulnerability, but when I looked for any exploit I couldn't find anything that would allow me to take advantage of that either.
Logged
TheXero
Full Member
***
Offline Offline

Posts: 112


Try Harder!


View Profile WWW
« Reply #3 on: March 16, 2012, 04:38:37 AM »

wlandymore are you doing a hacking-lab.com challenge, ie 'got wurzel' or 'got root'?

These challenges I found quite hard (not complete 'got root' yet) but being able to break out of rbash is not something I have come across before.

Focus on what you can execute (in ~/bin) and and you should be able to break out of it fairly quickly Smiley
Logged

wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #4 on: March 16, 2012, 08:26:32 AM »

yeah, those are the ones I'm doing. I was looking at the /bin folder underneath the restricted1 folder and there was only the ping, ls, and tee. Like I said, I've broken out a couple of times (probably from blind luck) but usually I'm wasting so much time breaking out that I don't have a way of elevating to root after that. Then if I try again the same sets of things that worked previously don't work. I even ran a script to try to brute-force the SSH login for root because I was grasping at straws but after I got through about 500 passwords of my file they cut me off. Smiley

I got through the level 2 decryption one pretty easily, but these ones I'm finding are quite hard even though they're level 1. I'm trying to get better at this stuff with the trial and error but this one seems a lot harder without any experience to go on.
Logged
wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #5 on: March 16, 2012, 08:44:18 AM »

Oh my gosh...that was easy. I totally didn't think of using the ~/bin. I was trying to edit the commands before with 'tee' but I was using the whole path like: /home/user/bin instead so it would always complain that I had a / in the path.

Thanks.
« Last Edit: March 16, 2012, 08:59:33 AM by wlandymore » Logged
TheXero
Full Member
***
Offline Offline

Posts: 112


Try Harder!


View Profile WWW
« Reply #6 on: March 16, 2012, 09:29:32 AM »

Many people attempt these boxes all day (they get reset on the hour) so just try again and see if you can do exactly the same again Smiley
Logged

wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #7 on: March 16, 2012, 11:01:14 AM »

yeah, it was only about 10 minutes before it bumped me off and when I went back in it was back to default. I just ran the same thing editing the ping command with tee and it worked like a charm.

Now I can actually focus on exploiting the system instead of wasting all that time breaking out of the shell.

Thanks for the hint. Smiley
Logged
TheXero
Full Member
***
Offline Offline

Posts: 112


Try Harder!


View Profile WWW
« Reply #8 on: March 16, 2012, 11:26:26 AM »

Privilege escalation can be one of the most challenging and exciting parts, so good luck Smiley
Logged

wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #9 on: March 16, 2012, 09:10:40 PM »

thanks. Smiley

I've been compiling a lot of c exploits but I haven't been successful yet.
Logged
avinashs
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #10 on: March 17, 2012, 02:20:00 PM »

Hey,I have a doubt.I started doing this lab work today and one thing that I couldn't figure out was, the ~/bin/ping is an executable and if we do 
                                           tee -a ~/bin/ping with /bin/sh
the /bin/sh is appended to ~/bin/ping as plain text rite.So it wont execute.Same thing happened to me.It didn't get executed.I am just a beginner.Did I miss anything obvious  ?
Logged
wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #11 on: March 19, 2012, 02:00:59 PM »

yeah, you don't want to have the -a in there because that will just append it to what's already there.

However, if you run: tee ~/bin/ping
 
and then /bin/sh (then Ctrl+C to exit)
and then run: ping

You will pop out of the shell.
Logged
mulitia
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #12 on: March 31, 2012, 03:57:33 AM »

Hope this helps:

for 7002 Got Wurzel?:
______________________

# tee ping
/bin/bash
[ctrl-c] -or- [ctrl-d]

# ping


for 7002 Got Root:
______________________

# tee .bashrc
PATH=/usr/bin
export PATH
[ctrl-d]

[logout/log back in]

# vi

[esc] :set shell=/bin/bash
[esc] :shell


have fun Wink
Logged
wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #13 on: April 03, 2012, 10:22:54 PM »

Hey thanks. I finally found the answer to the first one and it's not actually an exploit that was required at all.

Now I'm trying to break the 'got root' one but not having the same luck. Smiley
« Last Edit: April 09, 2012, 10:14:05 AM by wlandymore » Logged
TheXero
Full Member
***
Offline Offline

Posts: 112


Try Harder!


View Profile WWW
« Reply #14 on: April 04, 2012, 03:03:03 AM »

The whole reason that I use Hacking-Lab is because of a lack of spoilers (no taking the easy way out) and actually learning something.

I'm sure many others here will agree that spoilers ruin the challenge and I personally do not agree with spoilers being given here.
Logged

Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.059 seconds with 23 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Free Business and Tech Magazines and eBooks

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.