Class: Ronin::Listener::DNS::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/listener/dns/query.rb

Overview

Represents a received DNS query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, label, source_addr) ⇒ Query

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the query.

Parameters:

  • type (:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS)

    The queried record type.

  • label (String)

    The queried domain label.

  • source_addr (Addrinfo)

    The remote IP address and port that sent the query.



63
64
65
66
67
68
# File 'lib/ronin/listener/dns/query.rb', line 63

def initialize(type,label,source_addr)
  @type  = type
  @label = label

  @source_addr = source_addr
end

Instance Attribute Details

#labelString (readonly) Also known as: name

The domain label (ex: example.com or www.example.com).

Returns:

  • (String)


40
41
42
# File 'lib/ronin/listener/dns/query.rb', line 40

def label
  @label
end

#source_addrAddrinfo (readonly)

The remote IP address and port that sent the query.

Returns:

  • (Addrinfo)


47
48
49
# File 'lib/ronin/listener/dns/query.rb', line 47

def source_addr
  @source_addr
end

#type:A, ... (readonly)

The desired record type.

Returns:

  • (:A, :AAAA, :ANY, :CNAME, :HINFO, :LOC, :MINFO, :MX, :NS, :PTR, :SOA, :SRV, :TXT, :WKS)


35
36
37
# File 'lib/ronin/listener/dns/query.rb', line 35

def type
  @type
end

Instance Method Details

#sourceString

The source of the query.

Returns:

  • (String)

    The source IP:port pair as a String.



94
95
96
# File 'lib/ronin/listener/dns/query.rb', line 94

def source
  "#{source_ip}:#{source_port}"
end

#source_ipString

The source IP address that sent the query.

Returns:

  • (String)


75
76
77
# File 'lib/ronin/listener/dns/query.rb', line 75

def source_ip
  @source_addr.ip_address
end

#source_portInteger

The source port the query was sent from.

Returns:

  • (Integer)


84
85
86
# File 'lib/ronin/listener/dns/query.rb', line 84

def source_port
  @source_addr.ip_port
end

#to_a(String, Integer, Symbol, String)

Converts the query into an Array.

Returns:



114
115
116
# File 'lib/ronin/listener/dns/query.rb', line 114

def to_a
  [source_ip, source_port, @type, @label]
end

#to_csvString

Converts the DNS query to a CSV row.

Returns:

  • (String)

    The CSV row.



140
141
142
# File 'lib/ronin/listener/dns/query.rb', line 140

def to_csv
  to_a.to_csv
end

#to_hHash{Symbol => String,Integer,Symbol} Also known as: as_json

Converts the query into a Hash.

Returns:



125
126
127
128
129
130
131
132
# File 'lib/ronin/listener/dns/query.rb', line 125

def to_h
  {
    source_ip:   source_ip,
    source_port: source_port,
    type:        @type,
    label:       @label
  }
end

#to_json(*args) ⇒ String

Converts the DNS query into JSON.

Parameters:

  • args (Array)

    Additional arguments for Hash#to_json.

Returns:

  • (String)

    The raw JSON string.



155
156
157
# File 'lib/ronin/listener/dns/query.rb', line 155

def to_json(*args)
  as_json.to_json(*args)
end

#to_sString

Converts the query to a String.

Returns:



104
105
106
# File 'lib/ronin/listener/dns/query.rb', line 104

def to_s
  "#{source} #{@type} #{@label}"
end