Module: Msf::Simple::Buffer

Defined in:
lib/msf/base/simple/buffer.rb

Overview

Wraps interaction with a generated buffer from the framework. Its primary use is to transform a raw buffer into another format.

Class Method Summary collapse

Class Method Details

.comment(buf, fmt = "ruby") ⇒ Object

Creates a comment using the supplied format. The formats supported are raw, ruby, python, perl, bash, js_be, js_le, c, and java.


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/msf/base/simple/buffer.rb', line 63

def self.comment(buf, fmt = "ruby")
  case fmt
    when 'raw'
    when 'num', 'dword', 'dw'
      buf = Rex::Text.to_js_comment(buf)
    when 'ruby', 'rb', 'python', 'py'
      buf = Rex::Text.to_ruby_comment(buf)
    when 'perl', 'pl'
      buf = Rex::Text.to_perl_comment(buf)
    when 'bash', 'sh'
      buf = Rex::Text.to_bash_comment(buf)
    when 'c'
      buf = Rex::Text.to_c_comment(buf)
    when 'csharp'
      buf = Rex::Text.to_c_comment(buf)
    when 'js_be', 'js_le'
      buf = Rex::Text.to_js_comment(buf)
    when 'java'
      buf = Rex::Text.to_c_comment(buf)
    else
      raise ArgumentError, "Unsupported buffer format: #{fmt}", caller
  end

  return buf
end

.transform(buf, fmt = "ruby") ⇒ Object

Serializes a buffer to a provided format. The formats supported are raw, num, dword, ruby, python, perl, bash, c, js_be, js_le, java and psh


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/msf/base/simple/buffer.rb', line 21

def self.transform(buf, fmt = "ruby")
  case fmt
    when 'raw'
    when 'num'
      buf = Rex::Text.to_num(buf)
    when 'dword', 'dw'
      buf = Rex::Text.to_dword(buf)
    when 'python', 'py'
      buf = Rex::Text.to_python(buf)
    when 'ruby', 'rb'
      buf = Rex::Text.to_ruby(buf)
    when 'perl', 'pl'
      buf = Rex::Text.to_perl(buf)
    when 'bash', 'sh'
      buf = Rex::Text.to_bash(buf)
    when 'c'
      buf = Rex::Text.to_c(buf)
    when 'csharp'
      buf = Rex::Text.to_csharp(buf)
    when 'js_be'
      buf = Rex::Text.to_unescape(buf, ENDIAN_BIG)
    when 'js_le'
      buf = Rex::Text.to_unescape(buf, ENDIAN_LITTLE)
    when 'java'
      buf = Rex::Text.to_java(buf)
    when 'powershell', 'ps1'
      buf = Rex::Text.to_powershell(buf)
    when 'vbscript'
      buf = Rex::Text.to_vbscript(buf)
    when 'vbapplication'
      buf = Rex::Text.to_vbapplication(buf)
    else
      raise ArgumentError, "Unsupported buffer format: #{fmt}", caller
  end

  return buf
end

.transform_formatsObject

Returns the list of supported formats


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/msf/base/simple/buffer.rb', line 92

def self.transform_formats
  [
    'bash',
    'c',
    'csharp',
    'dw',
    'dword',
    'java',
    'js_be',
    'js_le',
    'num',
    'perl',
    'pl',
    'powershell',
    'ps1',
    'py',
    'python',
    'raw',
    'rb',
    'ruby',
    'sh',
    'vbapplication',
    'vbscript'
  ]
end