@@ -31,12 +31,11 @@ def on_before_socket_create(comm, param)
31
31
32
32
def on_socket_created ( comm , sock , param )
33
33
# 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' ] )
35
35
sock . extend ( SocketLogger ::SocketTracer )
36
36
sock . context = param . context
37
37
sock . params = param
38
38
sock . initlog ( @path , @prefix )
39
-
40
39
end
41
40
end
42
41
end
@@ -60,7 +59,7 @@ def name
60
59
end
61
60
62
61
def desc
63
- "Logs all socket operations to hex dumps in /tmp "
62
+ "Log socket operations to a directory as individual files "
64
63
end
65
64
66
65
protected
@@ -78,17 +77,16 @@ module SocketTracer
78
77
79
78
# Hook the write method
80
79
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
83
82
super ( buf , opts )
84
83
end
85
84
86
85
# Hook the read method
87
86
def read ( length = nil , opts = { } )
88
87
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
92
90
return r
93
91
end
94
92
@@ -97,15 +95,28 @@ def close(*args)
97
95
@fd . close
98
96
end
99
97
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
+
100
110
def initlog ( path , prefix )
101
111
@log_path = path
102
112
@log_prefix = prefix
103
113
@log_id = @@last_id
104
114
@@last_id += 1
105
115
@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 } "
108
118
@fd . puts ""
119
+ @fd . flush
109
120
end
110
121
111
122
end
0 commit comments