pulsedive 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: '0892a58aba0128ac35e0ac680639d9c2a22809b5f2c5671e8d761e51f548fa1b'
4
+ data.tar.gz: c32a9d425841d42ede4aa5ee08e256a7288db142f95956b0b948c1a2e824e5a5
5
+ SHA512:
6
+ metadata.gz: c32662e0d848b285b3eb0936c9e7621247c4460cdf1e36781404092c58dc0d36f18d4cbf96b937a88dce93fea411b26b8ec7e8dadd83bd2e89441c32a7c2abb6
7
+ data.tar.gz: d06b91eb9ee0ed3e65de7a9213db2fee73785ad2fb1433945c4cbe199feff497388ad623051234e15e82efa157b616f701a84ce8d664f414653b7b078a8a4e4f
@@ -0,0 +1,13 @@
1
+
2
+ version: "2"
3
+ prepare:
4
+ fetch:
5
+ - url: "https://raw.githubusercontent.com/janlelis/relaxed.ruby.style/master/.rubocop.yml"
6
+ path: "alternate-rubocop-path.yml"
7
+ plugins:
8
+ rubocop:
9
+ enabled: true
10
+ config:
11
+ file: "alternate-rubocop-path.yml"
12
+ exclude_patterns:
13
+ - "spec/**/*"
@@ -0,0 +1,53 @@
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 failure tracking
53
+ .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.4.1
7
+ before_install: gem install bundler -v 1.16.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at manabu.niseki@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pulsedive.gemspec
6
+ gemspec
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pulsedive (0.1.0)
5
+ activesupport (~> 5.2)
6
+ thor (~> 0.20)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.0)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.5.2)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ concurrent-ruby (1.0.5)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.3)
22
+ dotenv (2.5.0)
23
+ hashdiff (0.3.7)
24
+ i18n (1.0.1)
25
+ concurrent-ruby (~> 1.0)
26
+ minitest (5.11.3)
27
+ public_suffix (3.0.2)
28
+ rake (10.5.0)
29
+ rspec (3.7.0)
30
+ rspec-core (~> 3.7.0)
31
+ rspec-expectations (~> 3.7.0)
32
+ rspec-mocks (~> 3.7.0)
33
+ rspec-core (3.7.1)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-expectations (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-mocks (3.7.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.7.0)
41
+ rspec-support (3.7.1)
42
+ safe_yaml (1.0.4)
43
+ thor (0.20.0)
44
+ thread_safe (0.3.6)
45
+ tzinfo (1.2.5)
46
+ thread_safe (~> 0.1)
47
+ vcr (4.0.0)
48
+ webmock (3.4.2)
49
+ addressable (>= 2.3.6)
50
+ crack (>= 0.3.2)
51
+ hashdiff
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 1.16)
58
+ dotenv (~> 2.5)
59
+ pulsedive!
60
+ rake (~> 10.0)
61
+ rspec (~> 3.0)
62
+ vcr (~> 4.0)
63
+ webmock (~> 3.4)
64
+
65
+ BUNDLED WITH
66
+ 1.16.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 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,140 @@
1
+ # pulsedive-rb
2
+
3
+ A Ruby library for [Pulsedive](https://pulsedive.com/) API.
4
+
5
+ [![Build Status](https://travis-ci.org/ninoseki/pulsedive-rb.svg?branch=master)](https://travis-ci.org/ninoseki/pulsedive-rb)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/35b08b3018cee65b42a0/maintainability)](https://codeclimate.com/github/ninoseki/pulsedive-rb/maintainability)
7
+
8
+ Ruby client for the pulsedive API
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'pulsedive'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install pulsedive
25
+
26
+ ## Usage
27
+
28
+ ### As a Library
29
+
30
+ ```rb
31
+ require 'pulsedive'
32
+
33
+ # When given nothing, it tries to load your Pulsedive API key from ENV["PULSEDIVE_API_KEY]
34
+ api = Pulsedive::API.new
35
+ # or you can pass your API key as an argument
36
+ api = Pulsedive::API.new(YOUR_API_KEY)
37
+
38
+ ## Indicator(https://pulsedive.com/api/?q=indicators)
39
+ api.indicator.get_by_id(2);
40
+ # => {"iid"=>2,"type"=>"domain","indicator"=>"alvoportas.com.br","risk"=>"high", ...
41
+ api.indicator.get_by_value("pulsedive.com")
42
+ # => {"iid"=>53929,"type"=>"domain","indicator"=>"pulsedive.com","risk"=>"none", ...
43
+ api.indicator.get_links_by_id(2)
44
+ # => {"Active DNS"=>[{"iid"=>3,"indicator"=>"187.191.98.202","type"=>"ip","risk"=>"none", ...
45
+ api.indicator.get_properties_by_id(2)
46
+ # => {"dns"=>[{"pid"=>15302704,"stamp_seen"=>"2018-07-12 11:08:32","name"=>"A", ...
47
+
48
+ ## Threat(https://pulsedive.com/api/?q=threats)
49
+ api.threat.get_by_id(1)
50
+ # => {"tid"=>1,"threat"=>"Zeus","category"=>"malware","risk"=>"high","description"=>"", ...
51
+ api.threat.get_by_name("Zeus")
52
+ # => {"tid"=>1,"threat"=>"Zeus","category"=>"malware","risk"=>"high","description"=>"", ...
53
+ api.threat.get_summary_by_id(1)
54
+ # => {"risk"=>{"critical"=>19,"unknown"=>24,"medium"=>47,"high"=>63,"low"=>71,"none"=>368}, ...
55
+ api.threat.get_linked_indicators_by_id(1)
56
+ # #=> {"page_current"=>0,"results"=>[{"iid"=>1,"indicator"=>"afobal.cl","type"=>"domain", ...
57
+
58
+ ## Feeds(https://pulsedive.com/api/?q=feeds)
59
+ api.feed.get_by_id(1)
60
+ # => {"fid"=>1,"feed"=>"Zeus Bad Domains","category"=>"malware","organization"=>"abuse.ch", ...
61
+ api.feed.get_linked_indicators_by_id(1)
62
+ # => {"page_current"=>0,"results"=>[{"iid"=>1,"indicator"=>"afobal.cl","type"=>"domain", ...
63
+
64
+ ## Analyze(https://pulsedive.com/api/?q=analyze)
65
+ api.analyze.add_to_queue("pulsedive.com")
66
+ # => {"success"=>"Added to queue.","qid"=>11781524}'
67
+ api.analyze.get_results_by_id(11781524)
68
+ # => {"success"=>"Analyzed domain: pulsedive.com","data"=>{"iid"=>"53929","type"=>"domain", ...
69
+
70
+ ## Search(https://pulsedive.com/api/?q=search)
71
+ params = {
72
+ "search": "feed",
73
+ "value": "zeus",
74
+ "category": [
75
+ "general", "abuse", "attack", "botnet", "crime", "fraud",
76
+ "group", "malware", "proxy", "pup", "reconnaissance",
77
+ "spam", "terrorism", "vulnerability"
78
+ ],
79
+ "splitrisk": "1"
80
+ }
81
+ api.search(params)
82
+ # => '{"results"=>[{"fid"=>1,"name"=>"Zeus Bad Domains","category"=>"malware", ...
83
+
84
+ ```
85
+
86
+ ### As a CLI
87
+
88
+ ```bash
89
+ $ pulsedive
90
+ Commands:
91
+ pulsedive analyze COMMAND # analyze commands
92
+ pulsedive feed COMMAND # feed commands
93
+ pulsedive help [COMMAND] # Describe available commands or one specific command
94
+ pulsedive indicator COMMAND # indicator commands
95
+ pulsedive threat COMMAND # threat commands
96
+
97
+ $ pusledive analyze
98
+ Commands:
99
+ pulsedive analyze add_to_queue [IOC] # add ioc to the queue for analysis
100
+ pulsedive analyze get_results_by_id [ID] # get analyze result
101
+ pulsedive analyze help [COMMAND] # Describe subcommands or one specific subcommand
102
+
103
+ Options:
104
+ [--API-KEY=API_KEY]
105
+
106
+ $ pulsedive feed
107
+ Commands:
108
+ pulsedive feed get_by_id [ID] # get feed by id
109
+ pulsedive feed get_linked_indicators_by_id [ID] # get linked indicators by id
110
+ pulsedive feed help [COMMAND] # Describe subcommands or one specific subcommand
111
+
112
+ Options:
113
+ [--API-KEY=API_KEY]
114
+
115
+ $ pulsedive indicator
116
+ Commands:
117
+ pulsedive indicator get_by_id [ID] # get indicators by id
118
+ pulsedive indicator get_by_value [VALUE] # get indicators by value
119
+ pulsedive indicator get_links_by_id [ID] # get links by id
120
+ pulsedive indicator get_properties_by_id [ID] # get properties by id
121
+ pulsedive indicator help [COMMAND] # Describe subcommands or one specific subcommand
122
+
123
+ Options:
124
+ [--API-KEY=API_KEY]
125
+
126
+ $ pulsedive threat
127
+ Commands:
128
+ pulsedive threat get_by_id [ID] # get threat by id
129
+ pulsedive threat get_by_name [NAME] # get threat by name
130
+ pulsedive threat get_linked_indicators_by_id [ID] # get linked indicators by id
131
+ pulsedive threat get_summary_by_id [ID] # get summary by id
132
+ pulsedive threat help [COMMAND] # Describe subcommands or one specific subcommand
133
+
134
+ Options:
135
+ [--API-KEY=API_KEY]
136
+ ```
137
+
138
+ ## License
139
+
140
+ 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 "pulsedive"
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,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "Pulsedive"
4
+
5
+ Pulsedive::CLI::Main::start
@@ -0,0 +1,17 @@
1
+ require "pulsedive/api"
2
+ require "pulsedive/error"
3
+ require "pulsedive/client"
4
+
5
+ require "pulsedive/analyze"
6
+ require "pulsedive/search"
7
+ require "pulsedive/feed"
8
+ require "pulsedive/indicator"
9
+ require "pulsedive/threat"
10
+
11
+ require "pulsedive/cli"
12
+
13
+ require "pulsedive/version"
14
+
15
+ module Pulsedive
16
+ # Your code goes here...
17
+ end
@@ -0,0 +1,21 @@
1
+ require "base64"
2
+
3
+ module Pulsedive
4
+ class Analyze < Client
5
+ def add_to_queue(ioc, enrich = 1, probe = 1)
6
+ params = {
7
+ "ioc": Base64.strict_encode64(ioc),
8
+ "enrich": enrich,
9
+ "probe": probe,
10
+ }
11
+ post("/api/analyze.php", params) { |json| json }
12
+ end
13
+
14
+ def get_results_by_id(id)
15
+ params = {
16
+ qid: id
17
+ }
18
+ get("/api/analyze.php", params) { |json| json }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require "dotenv/load"
2
+
3
+ module Pulsedive
4
+ class API
5
+
6
+ attr_reader :api_key
7
+ attr_reader :indicator
8
+ attr_reader :threat
9
+ attr_reader :feed
10
+ attr_reader :analyze
11
+
12
+ def initialize(api_key = ENV["PULSEDIVE_API_KEY"])
13
+ raise(ArgumentError, "'api_key' argument is required") unless api_key
14
+
15
+ @indicator = Indicator.new(api_key)
16
+ @threat = Threat.new(api_key)
17
+ @feed = Feed.new(api_key)
18
+ @analyze = Analyze.new(api_key)
19
+ end
20
+
21
+ def search(params)
22
+ Search.new(api_key).search(params)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,147 @@
1
+ require "thor"
2
+ require "json"
3
+
4
+ module Pulsedive
5
+ module CLI
6
+ class Base < Thor
7
+
8
+ class_option :API_KEY, type: :string
9
+
10
+ no_commands do
11
+ def api
12
+ options[:API_KEY] ? API.new(options[:API_KEY]) : API.new
13
+ end
14
+
15
+ def with_error_handling
16
+ yield
17
+ rescue ResponseError => e
18
+ puts "Warning: #{e}"
19
+ rescue ArgumentError => _
20
+ puts "Please provide your Pulsedive API key via --API_KEY or ENV['PULSEDIVE_API_KEY']"
21
+ end
22
+ end
23
+ end
24
+
25
+ class Indicator < Base
26
+ desc "get_by_id [ID]", "get indicators by id"
27
+ def get_by_id(id)
28
+ with_error_handling do
29
+ json = api.indicator.get_by_id(id)
30
+ puts JSON.pretty_generate(json)
31
+ end
32
+ end
33
+
34
+ desc "get_by_value [VALUE]", "get indicators by value"
35
+ def get_by_value(value)
36
+ with_error_handling do
37
+ json = api.indicator.get_by_value(value)
38
+ puts JSON.pretty_generate(json)
39
+ end
40
+ end
41
+
42
+ desc "get_links_by_id [ID]", "get links by id"
43
+ def get_links_by_id(id)
44
+ with_error_handling do
45
+ json = api.indicator.get_links_by_id(id)
46
+ puts JSON.pretty_generate(json)
47
+ end
48
+ end
49
+
50
+ desc "get_properties_by_id [ID]", "get properties by id"
51
+ def get_properties_by_id(id)
52
+ with_error_handling do
53
+ json = api.indicator.get_properties_by_id(id)
54
+ puts JSON.pretty_generate(json)
55
+ end
56
+ end
57
+ end
58
+
59
+ class Threat < Base
60
+ desc "get_by_id [ID]", "get threat by id"
61
+ def get_by_id(id)
62
+ with_error_handling do
63
+ json = api.threat.get_by_id(id)
64
+ puts JSON.pretty_generate(json)
65
+ end
66
+ end
67
+
68
+ desc "get_by_name [NAME]", "get threat by name"
69
+ def get_by_name(name)
70
+ with_error_handling do
71
+ json = api.threat.get_by_name(name)
72
+ puts JSON.pretty_generate(json)
73
+ end
74
+ end
75
+
76
+ desc "get_summary_by_id [ID]", "get summary by id"
77
+ def get_summary_by_id(id)
78
+ with_error_handling do
79
+ json = api.threat.get_summary_by_id(id)
80
+ puts JSON.pretty_generate(json)
81
+ end
82
+ end
83
+
84
+ desc "get_linked_indicators_by_id [ID]", "get linked indicators by id"
85
+ def get_linked_indicators_by_id(id)
86
+ with_error_handling do
87
+ json = api.threat.get_linked_indicators_by_id(id)
88
+ puts JSON.pretty_generate(json)
89
+ end
90
+ end
91
+ end
92
+
93
+ class Feed < Base
94
+ desc "get_by_id [ID]", "get feed by id"
95
+ def get_by_id(id)
96
+ with_error_handling do
97
+ json = api.feed.get_by_id(id)
98
+ puts JSON.pretty_generate(json)
99
+ end
100
+ end
101
+
102
+ desc "get_linked_indicators_by_id [ID]", "get linked indicators by id"
103
+ def get_linked_indicators_by_id(id)
104
+ with_error_handling do
105
+ json = api.feed.get_linked_indicators_by_id(id)
106
+ puts JSON.pretty_generate(json)
107
+ end
108
+ end
109
+ end
110
+
111
+ class Analyze < Base
112
+ option :enrich, type: :numeric
113
+ option :probe, type: :numeric
114
+ desc "add_to_queue [IOC]", "add ioc to the queue for analysis"
115
+ def add_to_queue(ioc)
116
+ enrich = options[:enrich] || 1
117
+ probe = options[:probe] || 1
118
+ with_error_handling do
119
+ json = api.analyze.add_to_queue(ioc, enrich, probe)
120
+ puts JSON.pretty_generate(json)
121
+ end
122
+ end
123
+
124
+ desc "get_results_by_id [ID]", "get analyze result"
125
+ def get_results_by_id(id)
126
+ with_error_handling do
127
+ json = api.analyze.get_results_by_id(id)
128
+ puts JSON.pretty_generate(json)
129
+ end
130
+ end
131
+ end
132
+
133
+ class Main < Thor
134
+ desc "indicator COMMAND", "indicator commands"
135
+ subcommand "indicator", Indicator
136
+
137
+ desc "threat COMMAND", "threat commands"
138
+ subcommand "threat", Threat
139
+
140
+ desc "feed COMMAND", "feed commands"
141
+ subcommand "feed", Feed
142
+
143
+ desc "analyze COMMAND", "analyze commands"
144
+ subcommand "analyze", Analyze
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,70 @@
1
+ require 'net/https'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/hash'
4
+
5
+ module Pulsedive
6
+ class Client
7
+
8
+ attr_reader :api_key
9
+
10
+ HOST = "pulsedive.com".freeze
11
+ URL = "https://#{HOST}".freeze
12
+
13
+ def initialize(api_key)
14
+ @api_key = api_key
15
+ end
16
+
17
+ private
18
+
19
+ def url_for(path)
20
+ URI(URL + path)
21
+ end
22
+
23
+ def https_options
24
+ if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"]
25
+ uri = URI(proxy)
26
+ {
27
+ proxy_address: uri.hostname,
28
+ proxy_port: uri.port,
29
+ proxy_from_env: false,
30
+ use_ssl: true
31
+ }
32
+ else
33
+ { use_ssl: true }
34
+ end
35
+ end
36
+
37
+ def request(req)
38
+ Net::HTTP.start(HOST, 443, https_options) do |http|
39
+ response = http.request(req)
40
+ if response.code == '200'
41
+ json = JSON.parse(response.body)
42
+ if json["error"]
43
+ raise(ResponseError, json["error"])
44
+ else
45
+ yield json
46
+ end
47
+ else
48
+ raise(ResponseError, "unsupported response code returned: #{response.code}")
49
+ end
50
+ end
51
+ end
52
+
53
+ def get(path, params, &block)
54
+ params["key"] = api_key
55
+
56
+ url = url_for(path)
57
+ url.query = params.to_query
58
+ get = Net::HTTP::Get.new(url)
59
+ request(get, &block)
60
+ end
61
+
62
+ def post(path, params , &block)
63
+ params["key"] = api_key
64
+
65
+ post = Net::HTTP::Post.new(url_for(path))
66
+ post.body = URI.encode_www_form(params)
67
+ request(post, &block)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module Pulsedive
2
+ class ResponseError < StandardError; end
3
+ end
@@ -0,0 +1,19 @@
1
+ module Pulsedive
2
+ class Feed < Client
3
+ def get_by_id(fid)
4
+ params = {
5
+ "fid": fid
6
+ }
7
+ get("/api/info.php", params) { |json| json }
8
+ end
9
+
10
+ def get_linked_indicators_by_id(fid, page = 0)
11
+ params = {
12
+ "fid": fid,
13
+ "get": "links",
14
+ "page": page
15
+ }
16
+ get("/api/info.php", params) { |json| json }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ module Pulsedive
2
+ class Indicator < Client
3
+
4
+ def get_by_id(iid, schema = 1)
5
+ params = {
6
+ "iid": iid,
7
+ "schema": schema
8
+ }
9
+ get("/api/info.php", params) { |json| json }
10
+ end
11
+
12
+ def get_by_value(indicator)
13
+ params = {
14
+ "indicator": indicator
15
+ }
16
+ get("/api/info.php", params) { |json| json }
17
+ end
18
+
19
+ def get_links_by_id(iid, page = 0)
20
+ params = {
21
+ "iid": iid,
22
+ "get": "links",
23
+ "page": page
24
+ }
25
+ get("/api/info.php", params) { |json| json }
26
+ end
27
+
28
+ def get_properties_by_id(iid)
29
+ params = {
30
+ "iid": iid,
31
+ "get": "properties"
32
+ }
33
+ get("/api/info.php", params) { |json| json }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ module Pulsedive
2
+ class Response
3
+ include Enumerable
4
+ def initialize(client, params)
5
+
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Pulsedive
2
+ class Search < Client
3
+ def search(params)
4
+ get("/api/search.php", params) { |json| json }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ module Pulsedive
2
+ class Threat < Client
3
+ def get_by_id(tid)
4
+ params = {
5
+ "tid": tid
6
+ }
7
+ get("/api/info.php", params) { |json| json }
8
+ end
9
+
10
+ def get_by_name(tname)
11
+ params = {
12
+ "tname": tname
13
+ }
14
+ get("/api/info.php", params) { |json| json }
15
+ end
16
+
17
+ def get_summary_by_id(tld)
18
+ params = {
19
+ "tid": tld,
20
+ "get": "links",
21
+ "summary": "1",
22
+ "splitrisk": "1"
23
+ }
24
+ get("/api/info.php", params) { |json| json }
25
+ end
26
+
27
+ def get_linked_indicators_by_id(tld)
28
+ params = {
29
+ "tid": tld,
30
+ "get": "links"
31
+ }
32
+ get("/api/info.php", params) { |json| json }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Pulsedive
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "pulsedive/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "pulsedive"
7
+ spec.version = Pulsedive::VERSION
8
+ spec.authors = ["Manabu Niseki"]
9
+ spec.email = ["manabu.niseki@gmail.com"]
10
+
11
+ spec.summary = "Ruby library for Pulsedive API"
12
+ spec.description = "Ruby library for Pulsedive API"
13
+ spec.homepage = "https://github.com/ninoseki/pulsedive-rb"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency 'dotenv', '~> 2.5'
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "vcr", "~> 4.0"
30
+ spec.add_development_dependency "webmock", "~> 3.4"
31
+
32
+ spec.add_runtime_dependency "activesupport", "~> 5.2"
33
+ spec.add_runtime_dependency "thor", "~> 0.20"
34
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pulsedive
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: 2018-07-21 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
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.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
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.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.2'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.20'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.20'
125
+ description: Ruby library for Pulsedive API
126
+ email:
127
+ - manabu.niseki@gmail.com
128
+ executables:
129
+ - pulsedive
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".codeclimae.yml"
134
+ - ".gitignore"
135
+ - ".rspec"
136
+ - ".travis.yml"
137
+ - CODE_OF_CONDUCT.md
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - exe/pulsedive
146
+ - lib/pulsedive.rb
147
+ - lib/pulsedive/analyze.rb
148
+ - lib/pulsedive/api.rb
149
+ - lib/pulsedive/cli.rb
150
+ - lib/pulsedive/client.rb
151
+ - lib/pulsedive/error.rb
152
+ - lib/pulsedive/feed.rb
153
+ - lib/pulsedive/indicator.rb
154
+ - lib/pulsedive/response.rb
155
+ - lib/pulsedive/search.rb
156
+ - lib/pulsedive/threat.rb
157
+ - lib/pulsedive/version.rb
158
+ - pulsedive.gemspec
159
+ homepage: https://github.com/ninoseki/pulsedive-rb
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.7.6
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Ruby library for Pulsedive API
183
+ test_files: []