Skip to content

Commit 2d129f9

Browse files
author
HD Moore
committed
Clean up socket_logger, record the module name
1 parent b1726fd commit 2d129f9

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

plugins/socket_logger.rb

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ def on_before_socket_create(comm, param)
3131

3232
def on_socket_created(comm, sock, param)
3333
# Sockets created by the exploit have MsfExploit set and MsfPayload not set
34-
if (param.context['MsfExploit'] and (! param.context['MsfPayload'] ))
34+
if param.context and param.context['MsfExploit'] and (! param.context['MsfPayload'])
3535
sock.extend(SocketLogger::SocketTracer)
3636
sock.context = param.context
3737
sock.params = param
3838
sock.initlog(@path, @prefix)
39-
4039
end
4140
end
4241
end
@@ -60,7 +59,7 @@ def name
6059
end
6160

6261
def desc
63-
"Logs all socket operations to hex dumps in /tmp"
62+
"Log socket operations to a directory as individual files"
6463
end
6564

6665
protected
@@ -78,17 +77,16 @@ module SocketTracer
7877

7978
# Hook the write method
8079
def write(buf, opts = {})
81-
@fd.puts "WRITE (#{buf.length} bytes)"
82-
@fd.puts Rex::Text.to_hex_dump(buf)
80+
@fd.puts "WRITE\t#{buf.length}\t#{Rex::Text.encode_base64(buf)}"
81+
@fd.flush
8382
super(buf, opts)
8483
end
8584

8685
# Hook the read method
8786
def read(length = nil, opts = {})
8887
r = super(length, opts)
89-
90-
@fd.puts "READ (#{r.length} bytes)"
91-
@fd.puts Rex::Text.to_hex_dump(r)
88+
@fd.puts "READ\t#{ r ? r.length : 0}\t#{Rex::Text.encode_base64(r.to_s)}"
89+
@fd.flush
9290
return r
9391
end
9492

@@ -97,15 +95,28 @@ def close(*args)
9795
@fd.close
9896
end
9997

98+
def format_socket_conn
99+
"#{params.proto.upcase} #{params.localhost}:#{params.localport} > #{params.peerhost}:#{params.peerport}"
100+
end
101+
102+
def format_module_info
103+
return "" unless params.context and params.context['MsfExploit']
104+
if params.context['MsfExploit'].respond_to? :fullname
105+
return "via " + params.context['MsfExploit'].fullname
106+
end
107+
"via " + params.context['MsfExploit'].to_s
108+
end
109+
100110
def initlog(path, prefix)
101111
@log_path = path
102112
@log_prefix = prefix
103113
@log_id = @@last_id
104114
@@last_id += 1
105115
@fd = File.open(File.join(@log_path, "#{@log_prefix}#{@log_id}.log"), "w")
106-
@fd.puts "Socket created at #{Time.now}"
107-
@fd.puts "Info: #{params.proto} #{params.localhost}:#{params.localport} -> #{params.peerhost}:#{params.peerport}"
116+
@fd.puts "Socket created at #{Time.now} (#{Time.now.to_i})"
117+
@fd.puts "Info: #{format_socket_conn} #{format_module_info}"
108118
@fd.puts ""
119+
@fd.flush
109120
end
110121

111122
end

0 commit comments

Comments
 (0)