Skip to content

Commit d8c850a

Browse files
committed
Add support for the execution of single powershell commands
1 parent f8f61e8 commit d8c850a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def initialize(client)
3131
end
3232

3333

34-
def execute_string(string)
34+
def execute_string(code)
3535
request = Packet.create_request('powershell_execute')
36+
request.add_tlv(TLV_TYPE_POWERSHELL_CODE, code)
3637

3738
response = client.send_request(request)
38-
39-
return response
39+
return response.get_tlv_value(TLV_TYPE_POWERSHELL_RESULT)
4040
end
4141

4242
end

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Extensions
66
module Powershell
77

88
TLV_TYPE_POWERSHELL_CODE = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 1)
9+
TLV_TYPE_POWERSHELL_RESULT = TLV_META_TYPE_STRING | (TLV_EXTENSIONS + 2)
910

1011
end
1112
end

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def cmd_powershell_execute(*args)
6262
#end
6363
}
6464

65-
client.powershell.execute_string(code)
65+
result = client.powershell.execute_string(code)
66+
print_good("Command execution completed:\n#{result}")
6667
end
6768

6869
end

0 commit comments

Comments
 (0)