Module: PWN::Plugins::BeEF

Defined in:
lib/pwn/plugins/beef.rb

Overview

This plugin is used for interacting w/ BeEF’s REST API using the ‘rest’ browser type of PWN::Plugins::TransparentBrowser.

Constant Summary collapse

@@logger =
PWN::Plugins::PWNLogger.create

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



259
260
261
262
263
# File 'lib/pwn/plugins/beef.rb', line 259

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.helpObject

Display Usage for this Module



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/pwn/plugins/beef.rb', line 267

public_class_method def self.help
  puts "USAGE:
    beef_obj = #{self}.login(
      beef_ip: 'required host/ip of Nexpose Console (server)',
      beef_port: 'optional - port of BeEF server (defaults to 3000)',
      username: 'required username',
      password: 'optional password (will prompt if nil)'
    )

    hooks = #{self}.hooks(
      beef_obj: 'required beef_obj returned from #login method'
    )

    hooked_browser_info = #{self}.hooked_browser_info(
      beef_obj: 'required beef_obj returned from #login method',
      browser_session: 'required - browser session id returned from #hooks method'
    )

    logs = #{self}.logs(
      beef_obj: 'required beef_obj returned from #login method'
    )

    hooked_browser_logs = #{self}.hooked_browser_logs(
      beef_obj: 'required beef_obj returned from #login method',
      browser_session: 'required - browser session id returned from #hooks method'
    )

    modules = #{self}.modules(
      beef_obj: 'required beef_obj returned from #login method'
    )

    module_info = #{self}.module_info(
      beef_obj: 'required beef_obj returned from #login method',
      module_id: 'required - module id returned from #modules method'
    )

    beef_obj = #{self}.logout(
      beef_obj: 'required beef_obj returned from #login method'
    )

    #{self}.authors
  "
end

.hooked_browser_info(opts = {}) ⇒ Object

Supported Method Parameters

hooked_browser_info = PWN::Plugins::BeEF.hooked_browser_info(

beef_obj: 'required beef_obj returned from #login method',
browser_session: 'required - browser session id returned from #hooks method'

)



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/pwn/plugins/beef.rb', line 146

public_class_method def self.hooked_browser_info(opts = {})
  beef_obj = opts[:beef_obj]
  browser_session = opts[:browser_session].to_s.scrub

  @@logger.info('Retrieving Browser Info...')

  response = beef_rest_call(
    beef_obj: beef_obj,
    rest_call: "hooks/#{browser_session}"
  )

  JSON.parse(response)
rescue StandardError => e
  raise e
end

.hooked_browser_logs(opts = {}) ⇒ Object

Supported Method Parameters

hooked_browser_logs = PWN::Plugins::BeEF.hooked_browser_logs(

beef_obj: 'required beef_obj returned from #login method',
browser_session: 'required - browser session id returned from #hooks method'

)



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/pwn/plugins/beef.rb', line 187

public_class_method def self.hooked_browser_logs(opts = {})
  beef_obj = opts[:beef_obj]
  browser_session = opts[:browser_session].to_s.scrub

  @@logger.info('Retrieving Browser Logs...')

  response = beef_rest_call(
    beef_obj: beef_obj,
    rest_call: "logs/#{browser_session}"
  )

  JSON.parse(response)
rescue StandardError => e
  raise e
end

.hooks(opts = {}) ⇒ Object

Supported Method Parameters

hooks = PWN::Plugins::BeEF.hooks(

beef_obj: 'required beef_obj returned from #login method'

)



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pwn/plugins/beef.rb', line 126

public_class_method def self.hooks(opts = {})
  beef_obj = opts[:beef_obj]
  @@logger.info('Retrieving BeEF Hooks...')

  response = beef_rest_call(
    beef_obj: beef_obj,
    rest_call: 'hooks'
  )

  JSON.parse(response)
rescue StandardError => e
  raise e
end

.login(opts = {}) ⇒ Object

Supported Method Parameters

beef_obj = PWN::Plugins::BeEF.login(

beef_ip: 'required - host/ip of BeEF Server',
beef_port: 'optional - port of BeEF server (defaults to 3000)',
username: 'required - username',
password: 'optional - password (will prompt if nil)'

)



20
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
58
59
60
61
62
63
64
65
# File 'lib/pwn/plugins/beef.rb', line 20

public_class_method def self.(opts = {})
  beef_ip = opts[:beef_ip]
  beef_port = if opts[:beef_port]
                opts[:beef_port].to_i
              else
                3000
              end

  username = opts[:username].to_s.scrub
  base_beef_api_uri = "http://#{beef_ip}:#{beef_port}/api".to_s.scrub

  password = if opts[:password].nil?
               PWN::Plugins::AuthenticationHelper.mask_password
             else
               opts[:password].to_s.scrub
             end

  auth_payload = {}
  auth_payload[:username] = username
  auth_payload[:password] = password

  @@logger.info("Logging into BeEF REST API: #{beef_ip}")
  browser_obj = PWN::Plugins::TransparentBrowser.open(browser_type: :rest)
  rest_client = browser_obj[:browser]::Request

  response = rest_client.execute(
    method: :post,
    url: "#{base_beef_api_uri}/admin/login",
    payload: auth_payload.to_json
  )

  # Return array containing the post-authenticated BeEF REST API token
  json_response = JSON.parse(response)
  beef_success = json_response['success']
  api_token = json_response['token']
  beef_obj = {}
  beef_obj[:beef_ip] = beef_ip
  beef_obj[:beef_port] = beef_port
  beef_obj[:beef_success] = beef_success
  beef_obj[:api_token] = api_token
  beef_obj[:raw_response] = response

  beef_obj
rescue StandardError => e
  raise e
end

.logout(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::BeEF.logout(

beef_obj: 'required beef_obj returned from #login method'

)



249
250
251
252
253
254
255
# File 'lib/pwn/plugins/beef.rb', line 249

public_class_method def self.logout(opts = {})
  beef_obj = opts[:beef_obj]
  @@logger.info('Logging out...')
  beef_obj = nil
rescue StandardError => e
  raise e
end

.logs(opts = {}) ⇒ Object

Supported Method Parameters

logs = PWN::Plugins::BeEF.logs(

beef_obj: 'required beef_obj returned from #login method'

)



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/pwn/plugins/beef.rb', line 167

public_class_method def self.logs(opts = {})
  beef_obj = opts[:beef_obj]
  @@logger.info('Retrieving BeEF Logs...')

  response = beef_rest_call(
    beef_obj: beef_obj,
    rest_call: 'logs'
  )

  JSON.parse(response)
rescue StandardError => e
  raise e
end

.module_info(opts = {}) ⇒ Object

Supported Method Parameters

module_info = PWN::Plugins::BeEF.module_info(

beef_obj: 'required beef_obj returned from #login method',
module_id: 'required - module id returned from #modules method'

)



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/pwn/plugins/beef.rb', line 228

public_class_method def self.module_info(opts = {})
  beef_obj = opts[:beef_obj]
  module_id = opts[:module_id].to_i

  @@logger.info('Retrieving Module Info...')

  response = beef_rest_call(
    beef_obj: beef_obj,
    rest_call: "modules/#{module_id}"
  )

  JSON.parse(response)
rescue StandardError => e
  raise e
end

.modules(opts = {}) ⇒ Object

Supported Method Parameters

modules = PWN::Plugins::BeEF.modules(

beef_obj: 'required beef_obj returned from #login method'

)



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/pwn/plugins/beef.rb', line 208

public_class_method def self.modules(opts = {})
  beef_obj = opts[:beef_obj]
  @@logger.info('Retrieving BeEF Modules...')

  response = beef_rest_call(
    beef_obj: beef_obj,
    rest_call: 'modules'
  )

  JSON.parse(response)
rescue StandardError => e
  raise e
end