Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/extensions/notifications/channels/ntfy.rb
1154 views
1
require 'net/http'
2
require 'uri'
3
4
module BeEF
5
module Extension
6
module Notifications
7
module Channels
8
class Ntfy
9
10
# Constructor
11
def initialize(message)
12
@config = BeEF::Core::Configuration.instance
13
14
# Endpoint URL
15
uri = URI.parse(@config.get('beef.extension.notifications.ntfy.endpoint_url'))
16
17
# Create client
18
http = Net::HTTP.new(uri.host, uri.port)
19
20
# Create Request
21
req = Net::HTTP::Post.new(uri.path)
22
23
# Add authentication if configured
24
if @config.get('beef.extension.notifications.ntfy.username') || @config.get('beef.extension.notifications.ntfy.password')
25
req.basic_auth @config.get('beef.extension.notifications.ntfy.username'), @config.get('beef.extension.notifications.ntfy.password')
26
end
27
28
# Set headers and body
29
req.content_type = 'text/plain'
30
req['Title'] = 'BeEF Notification'
31
req.body = message
32
33
# Use SSL if the URI scheme is 'https'
34
http.use_ssl = (uri.scheme == 'https')
35
36
# Send request
37
http.request(req)
38
end
39
40
end
41
end
42
end
43
end
44
end
45
46