Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/console/commandline.rb
1873 views
1
#
2
# Copyright (c) 2006-2026 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
require 'optparse'
7
8
module BeEF
9
module Core
10
module Console
11
#
12
# This module parses the command line argument when running beef.
13
#
14
module CommandLine
15
@options = {}
16
@options[:verbose] = false
17
@options[:resetdb] = false
18
@options[:ascii_art] = false
19
@options[:ext_config] = ''
20
@options[:port] = ''
21
@options[:ws_port] = ''
22
@options[:update_disabled] = false
23
@options[:update_auto] = false
24
25
@already_parsed = false
26
27
#
28
# Parses the command line arguments of the console.
29
# It also populates the 'options' hash.
30
#
31
def self.parse
32
return @options if @already_parsed
33
34
optparse = OptionParser.new do |opts|
35
opts.on('-x', '--reset', 'Reset the database') do
36
@options[:resetdb] = true
37
end
38
39
opts.on('-v', '--verbose', 'Display debug information') do
40
@options[:verbose] = true
41
end
42
43
opts.on('-a', '--ascii-art', 'Prints BeEF ascii art') do
44
@options[:ascii_art] = true
45
end
46
47
opts.on('-c', '--config FILE', "Load a different configuration file: if it's called custom-config.yaml, git automatically ignores it.") do |f|
48
@options[:ext_config] = f
49
end
50
51
opts.on('-p', '--port PORT', 'Change the default BeEF listening port') do |p|
52
@options[:port] = p
53
end
54
55
opts.on('-w', '--wsport WS_PORT', 'Change the default BeEF WebSocket listening port') do |ws_port|
56
@options[:ws_port] = ws_port
57
end
58
59
opts.on('-d', '--update-disabled', 'Skips update') do
60
@options[:update_disabled] = true
61
end
62
63
opts.on('-u', '--update-auto', 'Automatic update with no prompt') do
64
@options[:update_auto] = true
65
end
66
67
opts.on('-h', '--help', 'Show this help') do
68
puts opts
69
exit 0
70
end
71
72
end
73
74
optparse.parse!
75
@already_parsed = true
76
@options
77
rescue OptionParser::InvalidOption
78
puts 'Invalid command line option provided. Please run beef --help'
79
exit 1
80
end
81
end
82
end
83
end
84
end
85
86