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


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

def context
  @context
end

#paramsObject

Returns the value of attribute params


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

def params
  @params
end

Instance Method Details

#close(*args) ⇒ Object


93
94
95
96
# File 'plugins/socket_logger.rb', line 93

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

#format_module_infoObject


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

def format_module_info
  return "" unless params.context and 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


98
99
100
# File 'plugins/socket_logger.rb', line 98

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

#initlog(path, prefix) ⇒ Object


110
111
112
113
114
115
116
117
118
119
120
# File 'plugins/socket_logger.rb', line 110

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


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

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


79
80
81
82
83
# File 'plugins/socket_logger.rb', line 79

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