Skip to content

Commit

Permalink
Merge pull request #192 from ninoseki/v2.1.1
Browse files Browse the repository at this point in the history
v2.1.1
  • Loading branch information
ninoseki authored Feb 7, 2024
2 parents 74c62ac + 8f26397 commit 9ae1ed2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
7 changes: 6 additions & 1 deletion lib/miteru/crawler.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# frozen_string_literal: true

require "colorize"

module Miteru
class Crawler < Service
#
# @param [Miteru::Website] website
#
def call(website)
Try[OpenSSL::SSL::SSLError, ::HTTP::Error, Addressable::URI::InvalidURIError] do
Miteru.logger.info("Website:#{website.truncated_url} has #{website.kits.length} kit(s).")
info = "Website:#{website.info}."
info = info.colorize(:red) if website.kits?

Miteru.logger.info(info)
return unless website.kits?

notify website
Expand Down
16 changes: 8 additions & 8 deletions lib/miteru/notifiers/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Miteru
module Notifiers
class SlackAttachment
# @return [String]
attr_reader :url

def initialize(url)
Expand All @@ -14,7 +15,7 @@ def initialize(url)
def to_a
[
{
text: defanged_url,
text:,
fallback: "VT & urlscan.io links",
actions:
}
Expand Down Expand Up @@ -47,10 +48,6 @@ def urlscan_link
}
end

def defanged_url
@defanged_url ||= url.to_s.gsub(".", "[.]")
end

def domain
@domain ||= [].tap do |out|
out << URI(url).hostname
Expand All @@ -59,6 +56,10 @@ def domain
end.first
end

def text
domain.to_s.gsub(".", "[.]")
end

def _urlscan_link
return nil unless domain

Expand All @@ -82,12 +83,11 @@ def call(website)
return unless callable?

attachment = SlackAttachment.new(website.url)
kits = website.kits.select(&:downloaded?)
notifier.post(text: website.message.capitalize, attachments: attachment.to_a) if kits.any?
notifier.post(text: website.info, attachments: attachment.to_a) if website.kits?
end

def callable?
!slack_webhook_url.nil?
!webhook_url.nil?
end

private
Expand Down
10 changes: 7 additions & 3 deletions lib/miteru/notifiers/urlscan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UrlScan < Base
def call(website)
return unless callable?

website.kits.each { |kit| submit(kit.url) }
website.kits.each { |kit| submit(kit.url, source: website.source) }
end

def callable?
Expand Down Expand Up @@ -41,8 +41,12 @@ def visibility
Miteru.config.urlscan_submit_visibility
end

def submit(url)
http.post("https://urlscan.io/api/v1/scan/", json: {tags:, visibility:, url:})
#
# @param [String] url
# @param [String] source
#
def submit(url, source:)
http.post("https://urlscan.io/api/v1/scan/", json: {tags: tags + ["source:#{source}"], visibility:, url:})
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/miteru/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Miteru
VERSION = "2.1.0"
VERSION = "2.1.1"
end
8 changes: 8 additions & 0 deletions lib/miteru/website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def truncated_url
url.truncate(64)
end

def defanged_truncated_url
truncated_url.to_s.gsub(".", "[.]")
end

def info
"#{defanged_truncated_url} has #{kits.length} kit(s) (Source: #{source})"
end

private

def timeout
Expand Down
6 changes: 6 additions & 0 deletions spec/website_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@
expect(website.kits?).to be(true)
end
end

describe "#info" do
it do
expect(website.info).to be_a(String)
end
end
end

0 comments on commit 9ae1ed2

Please sign in to comment.