Module: SocketLogger::SocketTracer

Defined in:
plugins/socket_logger.rb

Constant Summary collapse

@@last_id =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject

Returns the value of attribute context.



65
66
67
# File 'plugins/socket_logger.rb', line 65

def context
  @context
end

#paramsObject

Returns the value of attribute params.



65
66
67
# File 'plugins/socket_logger.rb', line 65

def params
  @params
end

Instance Method Details

#close(*args) ⇒ Object



82
83
84
85
# File 'plugins/socket_logger.rb', line 82

def close(*args)
  super(*args)
  @fd.close
end

#format_module_infoObject



91
92
93
94
95
96
97
98
# File 'plugins/socket_logger.rb', line 91

def format_module_info
  return '' unless params.context && params.context['MsfExploit']
  if params.context['MsfExploit'].respond_to? :fullname
    return 'via ' + params.context['MsfExploit'].fullname
  end

  'via ' + params.context['MsfExploit'].to_s
end

#format_socket_connObject



87
88
89
# File 'plugins/socket_logger.rb', line 87

def format_socket_conn
  "#{params.proto.upcase} #{params.localhost}:#{params.localport} > #{params.peerhost}:#{params.peerport}"
end

#initlog(path, prefix) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'plugins/socket_logger.rb', line 100

def initlog(path, prefix)
  @log_path = path
  @log_prefix = prefix
  @log_id = @@last_id
  @@last_id += 1
  @fd = File.open(File.join(@log_path, "#{@log_prefix}#{@log_id}.log"), 'w')
  @fd.puts "Socket created at #{Time.now} (#{Time.now.to_i})"
  @fd.puts "Info: #{format_socket_conn} #{format_module_info}"
  @fd.puts ''
  @fd.flush
end

#read(length = nil, opts = {}) ⇒ Object

Hook the read method



75
76
77
78
79
80
# File 'plugins/socket_logger.rb', line 75

def read(length = nil, opts = {})
  r = super(length, opts)
  @fd.puts "READ\t#{r ? r.length : 0}\t#{Rex::Text.encode_base64(r.to_s)}"
  @fd.flush
  return r
end

#write(buf, opts = {}) ⇒ Object

Hook the write method



68
69
70
71
72
# File 'plugins/socket_logger.rb', line 68

def write(buf, opts = {})
  @fd.puts "WRITE\t#{buf.length}\t#{Rex::Text.encode_base64(buf)}"
  @fd.flush
  super(buf, opts)
end