-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ninoseki/improve-detection
refactor: improve detection method
- Loading branch information
Showing
6 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require "http" | ||
require "oga" | ||
|
||
module Miteru | ||
class Website | ||
attr_reader :url | ||
def initialize(url) | ||
@url = url | ||
end | ||
|
||
def title | ||
doc.at_css("title")&.text | ||
end | ||
|
||
def zip_files | ||
@zip_files ||= doc.css("a").map do |a| | ||
href = a.get("href") | ||
href&.end_with?(".zip") ? href : nil | ||
end.compact | ||
end | ||
|
||
def index? | ||
title == "Index of /" | ||
end | ||
|
||
def zip_files? | ||
!zip_files.empty? | ||
end | ||
|
||
def has_kit? | ||
index? && zip_files? | ||
end | ||
|
||
private | ||
|
||
def get | ||
res = HTTP.get(url) | ||
raise HTTPResponseError if res.code != 200 | ||
|
||
res.body.to_s | ||
end | ||
|
||
def doc | ||
@doc ||= Oga.parse_html(get) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Miteru::Website, :vcr do | ||
subject { Miteru::Website } | ||
describe "#has_kit?" do | ||
context "when giving a url which contains a phishint kit" do | ||
before do | ||
path = File.expand_path("./fixtures/index.html", __dir__) | ||
data = File.read(path) | ||
|
||
allow_any_instance_of(Miteru::Website).to receive(:get).and_return(data) | ||
end | ||
it "should return true" do | ||
expect(subject.new("http://localhost").has_kit?).to eq(true) | ||
end | ||
end | ||
end | ||
context "when giving a url which doesn't contain a phishint kit" do | ||
before do | ||
allow_any_instance_of(Miteru::Website).to receive(:get).and_return("None") | ||
end | ||
it "should return false" do | ||
expect(subject.new("http://localhost").has_kit?).to eq(false) | ||
end | ||
end | ||
end |