Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/ruby/print.rb
1154 views
1
#
2
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
7
# Function used to print errors to the console
8
# @param [String] s String to be printed
9
def print_error(s)
10
puts Time.now.localtime.strftime('[%k:%M:%S]') + '[!]' + ' ' + s.to_s
11
BeEF.logger.error s.to_s
12
end
13
14
# Function used to print information to the console
15
# @param [String] s String to be printed
16
def print_info(s)
17
puts Time.now.localtime.strftime('[%k:%M:%S]') + '[*]' + ' ' + s.to_s
18
BeEF.logger.info s.to_s
19
end
20
21
# Function used to print information to the console (wraps print_info)
22
# @param [String] s String to be printed
23
def print_status(s)
24
print_info(s)
25
end
26
27
# Function used to print warning information
28
# @param [String] s String to be printed
29
def print_warning(s)
30
puts Time.now.localtime.strftime('[%k:%M:%S]') + '[!]' + ' ' + s.to_s
31
BeEF.logger.warn s.to_s
32
end
33
34
# Function used to print debug information
35
# @param [String] s String to be printed
36
# @note This function will only print messages if the debug flag is set to true
37
def print_debug(s)
38
config = BeEF::Core::Configuration.instance
39
return unless config.get('beef.debug') || BeEF::Core::Console::CommandLine.parse[:verbose]
40
41
puts Time.now.localtime.strftime('[%k:%M:%S]') + '[>]' + ' ' + s.to_s
42
BeEF.logger.debug s.to_s
43
end
44
45
# Function used to print successes to the console
46
# @param [String] s String to be printed
47
def print_success(s)
48
puts Time.now.localtime.strftime('[%k:%M:%S]') + '[+]' + ' ' + s.to_s
49
BeEF.logger.info s.to_s
50
end
51
52
# Function used to print successes to the console (wraps print_success)
53
# @param [String] s String to be printed
54
def print_good(s)
55
print_success(s)
56
end
57
58
# Print multiple lines with decoration split by the return character
59
# @param [String] s String to be printed
60
# @note The string passed needs to be separated by the "\n" for multiple lines to be printed
61
def print_more(s)
62
time = Time.now.localtime.strftime('[%k:%M:%S]')
63
64
lines = if s.instance_of?(Array)
65
s
66
else
67
s.split("\n")
68
end
69
70
lines.each_with_index do |line, index|
71
if (index + 1) == lines.size
72
puts "#{time} |_ #{line}"
73
BeEF.logger.info "#{time} |_ #{line}"
74
else
75
puts "#{time} | #{line}"
76
BeEF.logger.info "#{time} | #{line}"
77
end
78
end
79
end
80
81
# Function used to print over the current line
82
# @param [String] s String to print over current line
83
# @note To terminate the print_over functionality your last print_over line must include a "\n" return
84
def print_over(s)
85
time = Time.now.localtime.strftime('[%k:%M:%S]')
86
print "\r#{time}" + '[*]'.blue + " #{s}"
87
BeEF.logger.info s.to_s
88
end
89
90