urlhaus 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5477fabbbdf34adfdc9d340b17482e6c4b4ebbf22608a338226f7eb0279f6710
4
+ data.tar.gz: f84100297b425aced954cf4ae053446a28da1afef7db43bc2d095cb33c767f00
5
+ SHA512:
6
+ metadata.gz: 18c16de427a92b56ec6f9b5085db4454c78a646fd4b93a15c0e50d6e0990d810864ac12bd5a461ed7763634842638f4d6cde40c5928fc495e9de2bbb3f9c6671
7
+ data.tar.gz: 3c05dad7bb361637ba71886a4c999b2af732ddb80dc82a02d8ce741c53008b292b1a9fa8378f583c07707f91e823b33f2322d86281f2f4073c694b567ef39949
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.1
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in urlhaus.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Manabu Niseki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # urlhaus
2
+
3
+ [![Build Status](https://travis-ci.org/ninoseki/urlhaus.svg?branch=master)](https://travis-ci.org/ninoseki/urlhaus)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ninoseki/urlhaus/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/urlhaus?branch=master)
5
+
6
+ [URLHaus](https://urlhaus.abuse.ch/) query API wrapper for Ruby.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ gem install urlhaus
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ require "urlhaus"
18
+
19
+ api = URLhaus::API.new
20
+
21
+ # Query URL information
22
+ api.url("http://sskymedia.com/VMYB-ht_JAQo-gi/INV/99401FORPO/20673114777/US/Outstanding-Invoices/")
23
+ # Query host information
24
+ api.host("vektorex.com")
25
+ # Query payload information
26
+ api.payload("12c8aec5766ac3e6f26f2505e2f4a8f2")
27
+ # Query tag information
28
+ api.tag("Retefe")
29
+ # Query signature information
30
+ api.signature("Gozi")
31
+ ```
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "urlhaus"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "urlhaus/api"
4
+ require "urlhaus/version"
5
+
6
+ module URLhaus
7
+ class Error < StandardError; end
8
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/https"
5
+ require "uri"
6
+
7
+ module URLhaus
8
+ class API
9
+ # The path to the REST API endpoint.
10
+ HOST = "urlhaus-api.abuse.ch"
11
+ VERSION = "v1"
12
+ BASE_URL = "https://#{HOST}/#{VERSION}"
13
+
14
+ def url(url)
15
+ post("/url/", url: url)
16
+ end
17
+
18
+ def host(host)
19
+ post("/host/", host: host)
20
+ end
21
+
22
+ def payload(hash)
23
+ len = hash.length
24
+ case len
25
+ when 32
26
+ params = { md5_hash: hash }
27
+ when 64
28
+ params = { sha256_hash: hash }
29
+ else
30
+ raise ArgumentError("Hash should be MD5 or SHA256")
31
+ end
32
+
33
+ post("/payload/", params)
34
+ end
35
+
36
+ def tag(tag)
37
+ post("/tag/", tag: tag)
38
+ end
39
+
40
+ def signature(signature)
41
+ post("/signature/", signature: signature)
42
+ end
43
+
44
+ def download(sha256)
45
+ get("/download/#{sha256}")
46
+ end
47
+
48
+ private
49
+
50
+ def _host
51
+ self.class::HOST
52
+ end
53
+
54
+ def base_url
55
+ self.class::BASE_URL
56
+ end
57
+
58
+ def request(req)
59
+ Net::HTTP.start(_host, 443, https_options) do |http|
60
+ response = http.request(req)
61
+
62
+ if response.code.to_i != 200
63
+ raise Error, "#{response.code}: #{response.body}"
64
+ end
65
+
66
+ JSON.parse response.body
67
+ end
68
+ end
69
+
70
+ # Perform a direct GET HTTP request to the REST API.
71
+ def get(path, **params)
72
+ uri = URI("#{base_url}#{path}")
73
+ uri.query = URI.encode_www_form(params) if params
74
+ req = Net::HTTP::Get.new(uri)
75
+ request req
76
+ end
77
+
78
+ # Perform a direct POST HTTP request to the REST API.
79
+ def post(path, **params)
80
+ uri = URI("#{base_url}#{path}")
81
+ req = Net::HTTP::Post.new(uri)
82
+ req.set_form_data(params) if params
83
+
84
+ request req
85
+ end
86
+
87
+ def https_options
88
+ if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
89
+ uri = URI(proxy)
90
+ {
91
+ proxy_address: uri.hostname,
92
+ proxy_port: uri.port,
93
+ proxy_from_env: false,
94
+ use_ssl: true,
95
+ }
96
+ else
97
+ { use_ssl: true }
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module URLhaus
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "urlhaus/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "urlhaus"
9
+ spec.version = URLhaus::VERSION
10
+ spec.authors = ["Manabu Niseki"]
11
+ spec.email = ["manabu.niseki@gmail.com"]
12
+
13
+ spec.summary = "URLhaus query API wrapper for Ruby"
14
+ spec.description = "URLhaus query API wrapper for Ruby"
15
+ spec.homepage = "https://github.com/ninoseki/urlhaus"
16
+ spec.license = "MIT"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "coveralls", "~> 0.8"
29
+ spec.add_development_dependency "rake", "~> 12.3"
30
+ spec.add_development_dependency "rspec", "~> 3.8"
31
+ spec.add_development_dependency "vcr", "~> 4.0"
32
+ spec.add_development_dependency "webmock", "~> 3.5"
33
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: urlhaus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Manabu Niseki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.5'
97
+ description: URLhaus query API wrapper for Ruby
98
+ email:
99
+ - manabu.niseki@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/urlhaus.rb
114
+ - lib/urlhaus/api.rb
115
+ - lib/urlhaus/version.rb
116
+ - urlhaus.gemspec
117
+ homepage: https://github.com/ninoseki/urlhaus
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.0.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: URLhaus query API wrapper for Ruby
140
+ test_files: []