Class: Snackhack2::PhishingTlds

Inherits:
PhishingData show all
Defined in:
lib/snackhack2/phishing_tlds.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePhishingTlds

Returns a new instance of PhishingTlds.



51
52
53
# File 'lib/snackhack2/phishing_tlds.rb', line 51

def initialize
    @site = site
end

Instance Attribute Details

#siteObject

Returns the value of attribute site.



50
51
52
# File 'lib/snackhack2/phishing_tlds.rb', line 50

def site
  @site
end

Instance Method Details

#change_tld(no_tld: true) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/snackhack2/phishing_tlds.rb', line 157

def change_tld(no_tld: true)
  # This method will take the inputted site in @site and 
  # remove the TLDs and add a new TLDs to the domain. 
  # its uses the 'domain' method in the PhishingData class
  # which has an array of a bunch of different tlds. 
  

  # if the @site does not have a tlds
  if no_tld
    new_domains = []
    # loop through the tlds
    domains.each do |d|
      # combine the inputed @site
      # and the tlds 
      new_domains << "#{@site}#{d}"
    end
    new_domains
  else
    # If the @site does have a TLDs.
    
    # this is where the final results
    # are stored. 
    list_of_domains = []
    
    # removes .com, .org, etc
    ds = remove_tlds
  
    # join the elements together
    ds = ds.join(".")
    
    # loops through the tlds
    domains.each do |tlds|
        # adds the new domains to the array
        list_of_domains <<  ds + tlds
    end
  list_of_domains
  end
end

#check_domains(array: true) ⇒ Object



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
# File 'lib/snackhack2/phishing_tlds.rb', line 76

def check_domains(array: true)
  # The function of this method is to
  # check if the given domains are valid or not. 
  # By valid I mean resolvable and active. 
  
  
  # if domains is set to true, this array will hold the domains 
  domains_out = []
  
  # build the list of domains
  generated_tlds = change_tld
  
  valid_domains = []
  not_valid_domains = []
  
  generated_tlds.each do |domain|
    # if array is true; add the domains to array
    if array
      domains_out << domain
    else
      # if array is false print out the domains
      puts domain
    end
    domains_out if array
  end
end

#remove_letters(array_out: true) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/snackhack2/phishing_tlds.rb', line 102

def remove_letters(array_out: true)
  # This method will remove letters that 
  # occur more than once. For example:
  # google.com would become goggle.com
  
  # store the letter count in a hash. 
  letter_count = {}
  
  ds = remove_tlds
  
  # Creates an array with each character being
  # stored in a element. It will loop through the array 
  # and figure out the number of occurrences for each character
  ds.shift.split(//).each do |letter|
    if letter_count.has_key?(letter)
        letter_count[letter] += 1
    else
        letter_count[letter] = 1
    end
  end
  
  # After it creates the hash with the character and 
  # the number of time it cocures. This method 
  # will loop through the hash and check to see
  # if the value is greater than 1. If it is then the key ( the letter)
  # is added to the array named 'letters_with_more_than_one'
  letters_with_more_than_one = []
  letter_count.each do |key, value|
    if value > 1
        letters_with_more_than_one << key
    end
  end
  
  
  ds = remove_tlds
  new_ds = ds.shift
  
  # the final array with the duplicates letters removed
  remove_lettters_out = []
  
  # Loops through the 'letters_with_more_than_one'
  # array and uses 'sub' to remove the occurence
  # of one of the letters
  letters_with_more_than_one.each do |l|
      remove_lettters_out <<  new_ds.sub(l, "")
  end
  
  if array_out
      remove_lettters_out
  else
     # will print the contents of the array
     # instead of returning the array
     remove_lettters_out.each  { |a| puts a }
  end
end