During a red team engagement, penetration test, or an Active Directory assessment, we will often find ourselves in a situation where we might have already compromised the required credentials, ssh keys, hashes, or access tokens to move onto another host, but there may be no other host directly reachable from our attack host. In such cases, we may need to use a pivot host that we have already compromised to find a way to our next target. One of the most important things to do when landing on a host for the first time is to check our privilege level, network connections, and potential VPN or other remote access software. If a host has more than one network adapter, we can likely use it to move to a different network segment. Pivoting is essentially the idea of moving to other networks through a compromised host to find more targets on different network segments.
There are many different terms used to describe a compromised host that we can use to pivot to a previously unreachable network segment. Some of the most common are:
Pivot HostProxyFootholdBeach Head systemJump Host
Primary use is to defeat segmentation of a network. Tunneling is a subset of pivoting.
Tunneling = encapsulate network traffic into another protocol and route traffic through it.
Difference between pivoting and lateral movement: Lateral movement is a technique to further access to additional hosts / applications / services in an environment.
- Often includes privilege escalation across hosts https://www.paloaltonetworks.com/cyberpedia/what-is-lateral-movement https://attack.mitre.org/tactics/TA0008/
To summarize, we should look at these tactics as separate things. Lateral Movement helps us spread wide within a network, elevating our privileges, while Pivoting allows us to delve deeper into the networks accessing previously unreachable environments. Keep this comparison in mind while moving through this module.
Pivoting Utilizing multiple hosts to cross network boundaries you would not usually have access to. More of a targeted objective. Practical example:
During one tricky engagement, the target had their network physically and logically separated. This separation made it difficult for us to move around and complete our objectives. We had to search the network and compromise a host that turned out to be the engineering workstation used to maintain and monitor equipment in the operational environment, submit reports, and perform other administrative duties in the enterprise environment. That host turned out to be dual-homed (having more than one physical NIC connected to different networks). Without it having access to both enterprise and operational networks, we would not have been able to pivot as we needed to complete our assessment.
Tunneling Various protocols are used to shuttle traffic in/out of a network where there's a chance of traffic being detected. Using HTTP to mask C&C traffic from a server we own -> victim host. Obfuscation purposes and using https over tls / ssh over other transport protocols These actions enable tactics like exfiltration out of a target network or delivery of more payloads
Practical example:
One way we used Tunneling was to craft our traffic to hide in HTTP and HTTPS. This is a common way we maintained Command and Control (C2) of the hosts we had compromised within a network. We masked our instructions inside GET and POST requests that appeared as normal traffic and, to the untrained eye, would look like a web request or response to any old website. If the packet were formed properly, it would be forwarded to our Control server. If it were not, it would be redirected to another website, potentially throwing off the defender checking it out.
The networking behind pivoting
IP addressing and Nics Every computer needs an IP. IP assigned automatically from DHCP Static IPs are common with:
- Servers
- Routers
- Switch virtual interfaces
- Printers
- Any devices providing critical services
IP addresses are assigned to NICs Network Interface Controllers NIC referred to as a Network Interface Card or Network Adapter Computers can have multiple NICs
Example of how we connect to HTB networks over VPN:
When we connect to any of HTB's VPN servers through Pwnbox or our own attack host, we will always notice a tunnel interface gets created and assigned an IP address. The VPN allows us to access the lab network environments hosted by HTB. Keep in mind that these lab networks are not reachable without having a tunnel established. The VPN encrypts traffic and also establishes a tunnel over a public network (often the Internet), through NAT on a public-facing network appliance, and into the internal/private network.
Default Gateways
When network traffic is destined for an IP address located in a different network, the computer will send the traffic to its assigned default gateway. The default gateway is usually the IP address assigned to a NIC on an appliance acting as the router for a given LAN
Routing
It is common to think of a network appliance that connects us to the Internet when thinking about a router, but technically any computer can become a router and participate in routing. Some of the challenges we will face in this module require us to make a pivot host route traffic to another network. One way we will see this is through the use of AutoRoute, which allows our attack box to have routes to target networks that are reachable through a pivot host. One key defining characteristic of a router is that it has a routing table that it uses to forward traffic based on the destination IP address. Let's look at this on Pwnbox using the commands netstat -r or ip route.
stejwes@htb[/htb]$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default 178.62.64.1 0.0.0.0 UG 0 0 0 eth0
10.10.10.0 10.10.14.1 255.255.254.0 UG 0 0 0 tun0
10.10.14.0 0.0.0.0 255.255.254.0 U 0 0 0 tun0
10.106.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth1
10.129.0.0 10.10.14.1 255.255.0.0 UG 0 0 0 tun0
178.62.64.0 0.0.0.0 255.255.192.0 U 0 0 0 eth0
Routing table assists with routing decisions. When packets are created with destination, the routing table is used to decide where it goes
In the above example, packet destined for 10.129.10.25:
- Forwarded to gateway out of corresponding nic
- Computer isn't using routing protocol to learn about routes. It's given through connected nics.
- Standalone appliance designated routers typically learn routes through:
- static route creation
- dynamic routing protocols
- directly connected interfaces
Any traffic destined for networks not present in routing table will be sent to the default route (gateway of last resort)
Protocols, services, and ports
Protocols - Rules that govern network communications. Ports - Act as identifiers.
- Logical ports are software assigned to applications. https://academy.hackthebox.com/course/preview/introduction-to-networking