Giter Site home page Giter Site logo

chrislee35 / passivedns-client Goto Github PK

View Code? Open in Web Editor NEW
195.0 25.0 42.0 507 KB

passivedns-client provides a library and a query tool for querying several passive DNS providers

License: MIT License

Ruby 100.00%
ruby passive-dns circl mnemonic farsight passivetotal dnsdb 360cn riskiq bfkit

passivedns-client's Introduction

PassiveDNS::Client

This rubygem queries the following Passive DNS databases:

  • CIRCL
  • DNSDB (FarSight)
  • OpenSource Context (OSC)
  • PassiveTotal
  • RiskIQ
  • VirusTotal

Passive DNS is a technique where IP to hostname mappings are made by recording the answers of other people's queries.

There is a tool included, pdnstool, that wraps a lot of the functionality that you would need.

Please note that use of any passive DNS database is subject to the terms of use of that passive DNS database. Use of this script in violation of their terms is strongly discouraged. Also, please do not add any obfuscation to try to work around their terms of service. If you need special services, ask the providers for help/permission. Remember, these passive DNS operators are my friends. I don't want to have a row with them because some jerk used this library to abuse them.

If you like this library, please buy the Passive DNS operators a round of beers.

Installation

Add this line to your application's Gemfile:

gem 'passivedns-client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install passivedns-client

Configuration

From version 2.0.0 on, all configuration keys for passive DNS providers are in one configuration file. By default the location of the file is $HOME/.passivedns-client . The syntax of this file is as follows:

[dnsdb]
APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
[virustotal]
APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
[passivetotal]
USERNAME = [email protected]
APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
[circl]
USERNAME = circl_user
PASSWORD = circl_pass
[riskiq]
API_TOKEN = 0123456789abcdef
API_PRIVATE_KEY = 01234567890abcdefghijklmnopqrstu

[osc] APIKEY = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

CIRCL also can use and authorization token. In that case, you should drop the USERNAME and PASSWORD options and change the section to something like the following:

[circl]
AUTH_TOKEN = 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

Getting Access

Usage

require 'passivedns/client'

c = PassiveDNS::Client.new(['riskiq','dnsdb'])
results = c.query("example.com")

Or use the included tool...

Usage: bin/pdnstool [-d [cdprv]] [-g|-v|-m|-c|-x|-y|-j|-t] [-os <sep>] [-f <file>] [-r#|-w#|-v] [-l <count>] [--config <file>] <ip|domain|cidr>
Passive DNS Providers
  -dcdprv uses all of the available passive dns database
  -dc use CIRCL
  -dd use DNSDB
  -dp use PassiveTotal
  -dr use RiskIQ
  -dv use VirusTotal
  -dvr uses VirusTotal and RiskIQ (for example)

Output Formatting
  -g link-nodal GDF visualization definition
  -z link-nodal graphviz visualization definition
  -m link-nodal graphml visualization definition
  -c CSV
  -x XML
  -y YAML
  -j JSON
  -t ASCII text (default)
  -s <sep> specifies a field separator for text output, default is tab

State and Recursion
  -f[file] specifies a sqlite3 database used to read the current state - useful for large result sets and generating graphs of previous runs.
  -r# specifies the levels of recursion to pull. **WARNING** This is quite taxing on the pDNS servers, so use judiciously (never more than 3 or so) or find yourself blocked!
  -w# specifies the amount of time to wait, in seconds, between queries (Default: 0)
  -l <count> limits the number of records returned per passive dns database queried.

Specifying a Configuration File
  --config <file> specifies a config file. default: /home/chris/.passivedns-client

Getting Help
  -h hello there.  This option produces this helpful help information on how to access help.
  -v debugging information

Writing Your Own Database Adaptor

module PassiveDNS #:nodoc: don't document this # The Provider module contains all the Passive DNS provider client code module Provider # Queries OSContext's passive DNS database class MyDatabaseAdaptor < PassiveDB # Sets the modules self-reported name to "OSC" def self.name "MyPerfectDNS" # short, proper label end #override def self.config_section_name "perfect" # very short label to use in the configuration file end #override def self.option_letter "p" # single letter to specify the option for the command line tool end

	    attr_accessor :debug

		def initialize(options={})
		  @debug = options[:debug] || false
		  # please include a way to change the base URL, HOST, etc., so that people can test
		  # against a test/alternate version of your service
	      @base = options["URL"] || "http://myperfectdns.example.com/pdns.cgi?query="
		  @apikey = options["APIKEY"] || raise("APIKEY option required for #{self.class}")
		end

		# override
		def lookup(label, limit=nil)
			$stderr.puts "DEBUG: #{self.class.name}.lookup(#{label})" if @debug
			recs = []
			Timeout::timeout(240) {
				t1 = Time.now
				# TODO: your code goes here to fetch the data from your service
				# TODO: don't forget to impose the limit either during the fetch or during the parse phase
				response_time = Time.now - t1
				# TODO: parse your data and add PDNSResult objects to recs array
				recs << PDNSResult.new(self.class.name, response_time, rrname ,
					rdata, rrtype, ttl, first_seen, last_seen, count )
			}
			recs
		rescue Timeout::Error => e # using the implied "begin/try" from the beginning of the function
			$stderr.puts "#{self.class.name} lookup timed out: #{label}"
		end
  end
	end
end

Passive DNS - Common Output Format

There is an RFC, Passive DNS - Common Output Format, and a proof of concept implementation, pdns-qof-server, that describes a recommened JSON format for passive DNS data. passivedns-client is very close to supporting it, but since I've never enteracted with a true implementation of this RFC, I can't attest that I could correctly parse it. I think they way that they can encode multiple results into one record would actually break what I have right now.

Right now, I'm in a wait and see mode with how this progresses before I start supporting yet another format or request that other providers start to adhere to a common output format. If you have thoughts on the matter, I would love to discuss.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

passivedns-client's People

Contributors

chrislee35 avatar crondaemon avatar cudeso avatar elhoim avatar pinowudi avatar silascutler avatar tresni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

passivedns-client's Issues

/usr/local/bin/pdnstool: invalid option -- e

uname -a
Linux remnux-virt 3.13.0-52-generic #86-Ubuntu SMP Mon May 4 04:32:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

remnux@remnux-virt:~$ pdnstool -d3 www.google.com
/usr/local/bin/pdnstool: invalid option -- e
/usr/lib/ruby/1.9.1/getoptlong.rb:394:in `set_error': invalid option -- e (GetoptLong::InvalidOption)
        from /usr/lib/ruby/1.9.1/getoptlong.rb:571:in `get'
        from /usr/lib/ruby/1.9.1/getoptlong.rb:602:in `block in each'
        from /usr/lib/ruby/1.9.1/getoptlong.rb:601:in `loop'
        from /usr/lib/ruby/1.9.1/getoptlong.rb:601:in `each'
        from /var/lib/gems/1.9.1/gems/passivedns-client-2.1.2/lib/passivedns/client/cli.rb:80:in `parse_command_line'
        from /var/lib/gems/1.9.1/gems/passivedns-client-2.1.2/lib/passivedns/client/cli.rb:256:in `run'
        from /var/lib/gems/1.9.1/gems/passivedns-client-2.1.2/bin/pdnstool:5:in `<top (required)>'
        from /usr/local/bin/pdnstool:23:in `load'
        from /usr/local/bin/pdnstool:23:in `<main>'
remnux@remnux-virt:~$

CertEE support broken

$ pdnstool -e 1.2.3.4
/usr/lib/ruby/1.8/date/format.rb:1055:in dup': can't dup NilClass (TypeError) from /home/foo/pdnstool/client.rb:56:injoin'
from /home/foo/pdnstool/client.rb:56:in query' from /home/foo/pdnstool/client.rb:55:ineach'
from /home/foo/pdnstool/client.rb:55:in query' from /home/foo/pdnstool/pdnstool.rb:15:inpdnslookup'
from /home/foo/pdnstool/state.rb:64:in each_query' from /home/foo/pdnstool/state.rb:59:ineach'
from /home/foo/pdnstool/state.rb:59:in each_query' from /home/foo/pdnstool/pdnstool.rb:14:inpdnslookup'
from /home/foo/pdnstool/pdnstool.rb:200

$ cat version.rb
module PassiveDNS
class Client
VERSION = "1.1.1"
end
end

BFK.de depricated

The BFK.de Passive DNS may be deprecated. When called, the following message is displayed:
Due to the EU GDPR policy, this service has been shut down until further notice.

Traceback (most recent call last):
        9: from /usr/local/bin/pdnstool:23:in `<main>'
        8: from /usr/local/bin/pdnstool:23:in `load'
        7: from /var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/bin/pdnstool:5:in `<top (required)>'
        6: from /var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/lib/passivedns/client/cli.rb:274:in `run'
        5: from /var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/lib/passivedns/client/cli.rb:274:in `new'
        4: from /var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/lib/passivedns/client.rb:80:in `initialize'
        3: from /var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/lib/passivedns/client.rb:80:in `each'
        2: from /var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/lib/passivedns/client.rb:82:in `block in initialize'
        1: from /var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/lib/passivedns/client.rb:82:in `new'
/var/lib/gems/2.5.0/gems/passivedns-client-2.1.11/lib/passivedns/client/provider/bfk.rb:41:in `initialize': Due to the EU GDPR policy, this service has been shut down until further notice. (RuntimeError)

It's recommended we remove this module.

DNSParse support broken

$ pdnstool -d 1.2.3.4

/usr/lib/ruby/1.8/net/http.rb:560:in initialize': Connection timed out - connect(2) (Errno::ETIMEDOUT) from /home/foo/pdnstool/client.rb:56:injoin'
from /home/foo/pdnstool/client.rb:56:in query' from /home/foo/pdnstool/client.rb:55:ineach'
from /home/foo/pdnstool/client.rb:55:in query' from /home/foo/pdnstool/pdnstool.rb:16:inpdnslookup'
from /home/foo/pdnstool/state.rb:64:in each_query' from /home/foo/pdnstool/state.rb:59:ineach'
from /home/foo/pdnstool/state.rb:59:in each_query' from /home/foo/pdnstool/pdnstool.rb:15:inpdnslookup'
from /home/foo/pdnstool/pdnstool.rb:201

pdnstool: letter_map used before being defined?

I don't have much ruby experience, so I could have done something wrong, but I can't get the pdnstool tool to work. I installed it today using gem install passivedns-client. It is version 2.0.0

It looks like letter_map is being defined in usage, but being referenced in the main body.

$ pdnstool -d3 www.google.com
/Library/Ruby/Gems/2.0.0/gems/passivedns-client-2.0.0/bin/pdnstool:127:in `block (2 levels) in <top (required)>': undefined local variable or method `letter_map' for main:Object (NameError)
    from /Library/Ruby/Gems/2.0.0/gems/passivedns-client-2.0.0/bin/pdnstool:124:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/passivedns-client-2.0.0/bin/pdnstool:124:in `block in <top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/getoptlong.rb:604:in `block in each'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/getoptlong.rb:601:in `loop'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/getoptlong.rb:601:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/passivedns-client-2.0.0/bin/pdnstool:117:in `<top (required)>'
    from /usr/bin/pdnstool:23:in `load'
    from /usr/bin/pdnstool:23:in `<main>'

My ruby version. Running on MacOS X.

$ ruby --version
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.