Codebase list twofi / f22e035
Merge tag 'upstream/2.0' Upstream version 2.0 Sophie Brun 9 years ago
4 changed file(s) with 153 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
0 # A sample Gemfile
1 source "https://rubygems.org"
2
3 gem "twitter"
0 , Twitter Words of Interest
0 twofi, Twitter Words of Interest
11 ================================
22
3 Copyright(c) 2012, Robin Wood <[email protected]>
3 Copyright(c) 2014, Robin Wood <[email protected]>
44
5 When attempting to crack passwords custom word lists are very useful additions to
6 standard dictionaries. An interesting idea originally released on the "7 Habits of
7 Highly Effective Hackers" blog was to use Twitter to help generate those lists
8 based on searches for keywords related to the list that is being cracked. I've
9 expanded this idea into which will take multiple search terms and return a
10 word list sorted by most common first.
5 When attempting to crack passwords custom word lists are very useful additions
6 to standard dictionaries. An interesting idea originally released on the "7
7 Habits of Highly Effective Hackers" blog was to use Twitter to help generate
8 those lists based on searches for keywords related to the list that is being
9 cracked. I've expanded this idea into twofi which will take multiple search
10 terms and return a word list sorted by most common first.
1111
1212 The original blog post is at:
1313
1616 A second option, suggested by @pentest4dummies, was to look at what specific
1717 users have been saying and use their own tweets to build up the list so I've
1818 added that as well. Given a list of twitter usernames the script will bring back
19 approximately the last 500 tweets for each user and use those to create the
19 as many tweets for each user as the API will allow and use those to create the
2020 list.
2121
22 Install
23 =======
22 Installation
23 ============
2424
25 The only ruby gem that probably isn't installed by default is the json one, to
25 The only ruby gem that probably isn't installed by default is the twitter one, to
2626 install this run:
2727
28 gem install json
28 bundle install
2929
30 Then you can run by either using ruby
30 Then you can run twofi by either using ruby
3131
32 ruby .rb
32 ruby twofi.rb
3333
3434 or making it executable then running it directly
3535
36 chmod a+x .rb
37 ./.rb
36 chmod a+x twofi.rb
37 ./twofi.rb
3838
39 Version 1 of Twofi used the now removed Twitter search feature which did not
40 require any authentication. Version 2 now uses the new API which requires you to
41 have a Twitter account and apply for API keys. The process is simple and
42 instant, no cash, no waiting for human approval, so no big deal. You need to go
43 to:
44
45 https://apps.twitter.com/
46
47 And fill in your details. This will give you a pair of keys which you then need
48 to put into the twofi.yml config file.
49
50
51 At the moment the script expects the config file to be in the same directory as
52 twofi is being ran from, if this is not the case you can tell it where the
53 config file is by using the --config parameter.
3954
4055 Usage
4156 =====
4257
43 Usage: [OPTIONS]
58 Usage: twofi [OPTIONS]
4459 --help, -h: show help
4560 --count, -c: include the count with the words
61 --config <file>: config file, default is twofi.yml
4662 --min_word_length, -m: minimum word length
47 --term_file, -T file: a file containing a list of terms
48 --terms, -t: comma separated usernames
63 --term_file, -T <file>: a file containing a list of terms
64 --terms, -t: comma separated search terms
4965 quote words containing spaces, no space after commas
50 --user_file, -U file: a file containing a list of users
66 --user_file, -U <file>: a file containing a list of users
5167 --users, -u: comma separated search terms
5268 quote words containing spaces, no space after commas
5369 --verbose, -v: verbose
7894 At the moment there is nothing for the script to be verbose about so the verbose
7995 flag does nothing. I've included it for future versions.
8096
97 Change Log
98 ==========
99
100 2.0-beta - Updated to use the new authenticated API
101 1.0 - Initial release
102
81103 Licence
82104 =======
83105 This project released under the Creative Commons Attribution-Share Alike 2.0
99 # http://7habitsofhighlyeffectivehackers.blogspot.com.au/2012/05/using-twitter-to-build-password.html
1010 #
1111 # Author:: Robin Wood ([email protected])
12 # Copyright:: Copyright (c) Robin Wood 2012
12 # Copyright:: Copyright (c) Robin Wood 2014
1313 # Licence:: Creative Commons Attribution-Share Alike 2.0
1414 #
1515
16 require 'rubygems'
17 require 'json'
18 require 'net/http'
16 require 'yaml'
17 require 'twitter'
1918 require 'getoptlong'
2019
2120 opts = GetoptLong.new(
2221 [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
22 [ '--config', GetoptLong::REQUIRED_ARGUMENT ],
2323 [ '--count', '-c', GetoptLong::NO_ARGUMENT ],
2424 [ '--min_word_length', "-m" , GetoptLong::REQUIRED_ARGUMENT ],
2525 [ '--term_file', "-T" , GetoptLong::REQUIRED_ARGUMENT ],
2929 [ '--verbose', "-v" , GetoptLong::NO_ARGUMENT ]
3030 )
3131
32 def sample_config
33 puts "The config file \"#{@config_file}\" is missing or invalid, please create a config file in the format:"
34 puts "options:
35 api_key: <YOUR KEY>
36 api_secret: <YOUR SECRET>
37
38 To get your keys you must register with Twitter at: https://apps.twitter.com/
39 "
40 exit
41 end
42
3243 def usage
33 puts 'twofi 1.0 Robin Wood ([email protected]) (www.digininja.org)
34 twofi - Twitter Words Of Interest
35
36 Usage: twofi [OPTIONS]
44 puts 'twoif 2.0-beta Robin Wood ([email protected]) (www.digininja.org)
45 twoif - Twitter Words of Interest
46
47 Usage: twoif [OPTIONS]
3748 --help, -h: show help
49 --config <file>: config file, default is twofi.yml
3850 --count, -c: include the count with the words
3951 --min_word_length, -m: minimum word length
40 --term_file, -T file: a file containing a list of terms
41 --terms, -t: comma separated usernames
52 --term_file, -T <file>: a file containing a list of terms
53 --terms, -t: comma separated search terms
4254 quote words containing spaces, no space after commas
43 --user_file, -U file: a file containing a list of users
44 --users, -u: comma separated search terms
55 --user_file, -U <file>: a file containing a list of users
56 --users, -u: comma separated usernames
4557 quote words containing spaces, no space after commas
4658 --verbose, -v: verbose
4759
4961 exit
5062 end
5163
52 def twitter_search(query, results=500)
53 url = "http://search.twitter.com/search.json?q=" + URI.encode(query) + "&rpp=" + results.to_s
54 resp = Net::HTTP.get_response(URI.parse(url))
55 data = resp.body
56
57 # Should probably do some error handling here but not really sure
58 # what errors could come back
59 result = JSON.parse(data)
60
61 return result
64 # Default this to nil and it is then created
65 # when first needed in the search
66
67 @twitter_client = nil
68
69 def twitter_search(query)
70 if @twitter_client.nil?
71 @twitter_client = Twitter::REST::Client.new do |config|
72 config.consumer_key = @api_key
73 config.consumer_secret = @api_secret
74 unless @bearer_token.nil?
75 config.bearer_token = @bearer_token
76 end
77 end
78 end
79
80 begin
81 data = @twitter_client.search(query, :result_type => "recent")
82 rescue Twitter::Error::Forbidden, Twitter::Error::Unauthorized
83 puts "The authentication with Twitter failed, please check your API keys."
84 puts "If there is a bearer_token entry in your config file try removing that.\n\n"
85 exit
86 end
87
88 return data
6289 end
6390
6491 users=[]
6592 terms=[]
6693 min_word_length=3
6794 show_count=false
95 @config_file = "twofi.yml"
6896
6997 begin
7098 opts.each do |opt, arg|
7199 case opt
100 when "--config"
101 @config_file = arg
72102 when '--count'
73103 show_count = true
74104 when '--help'
122152 usage
123153 end
124154
155 # Check the config file exits then parse out of it
156 # the stuff that we need
157
158 if File.exists?(@config_file)
159 config = YAML.load_file(@config_file)
160 if config == false
161 sample_config
162 end
163 else
164 sample_config
165 end
166
167 @api_key = nil
168 @api_secret = nil
169 @bearer_token = nil
170
171 if config.include?"options"
172 if config["options"].include?"api_key" and config["options"].include?"api_secret"
173 @api_key = config["options"]["api_key"]
174 @api_secret = config["options"]["api_secret"]
175 else
176 sample_config
177 end
178
179 if @api_key == "<YOUR KEY>"
180 sample_config
181 end
182
183 if config["options"].include?"bearer_token"
184 @bearer_token = config["options"]["bearer_token"]
185 else
186 @bearer_token = nil
187 end
188 else
189 sample_config
190 end
191
125192 results = []
126193
127 #puts terms.inspect
128194 terms.each do |term|
129 data = twitter_search(term, 500)
130 results += data['results']
195 data = twitter_search(term)
196 results += data.to_a
131197 end
132198
133199 if results.count == 0
135201 else
136202 wordlist = {}
137203 results.each do |result|
138 text = result['text']
204 # have to .dup the text as it comes in frozen
205 text = result.full_text.dup
139206 # Strip any non word type characters
140207 text.gsub!(/[^\w \s \d]/, ' ')
141208 words = text.split(/\s/)
161228 end
162229 end
163230 end
231
232 # Write out the bearer token, this saves making unnecessary
233 # requests next time
234 unless @twitter_client.bearer_token.nil?
235 config['options']["bearer_token"] = @twitter_client.bearer_token.to_s
236 File.open(@config_file,'w') do |h|
237 h.write config.to_yaml
238 end
239 end
0 ---
1 options:
2 api_key: <YOUR KEY>
3 api_secret: <YOUR SECRET>