cookie_extractor 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -3
- data/bin/cookie_extractor +39 -15
- data/lib/cookie_extractor/browser_detector.rb +47 -0
- data/lib/cookie_extractor/version.rb +1 -1
- data/lib/cookie_extractor.rb +3 -0
- data/spec/browser_detector_spec.rb +37 -0
- metadata +6 -6
data/README.md
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
cookie_extractor
|
2
2
|
----------------
|
3
3
|
|
4
|
-
Extract cookies from Firefox
|
4
|
+
Extract cookies from Firefox, Chrome or Chromium sqlite cookie stores into a wget-compatible cookies.txt file.
|
5
5
|
|
6
6
|
### Install ###
|
7
7
|
|
8
|
-
gem install cookie_extractor
|
8
|
+
gem install cookie_extractor
|
9
9
|
|
10
10
|
### Usage ###
|
11
11
|
|
12
|
-
cookie_extractor /path/to/firefox/cookies.sqlite > cookies.txt
|
12
|
+
cookie_extractor /path/to/firefox/cookies.sqlite > cookies.txt
|
13
|
+
|
14
|
+
cookie_extractor --guess # Guess which browser to use and open corresponding file
|
15
|
+
|
16
|
+
cookie_extractor --browser chrome|chromium|firefox # Open corresponding DB
|
17
|
+
|
18
|
+
|
19
|
+
Typical locations for the cookies file on Linux are:
|
20
|
+
|
21
|
+
* Firefox: *~/.mozilla/firefox/(profile directory)/cookies.sqlite*
|
22
|
+
* Chrome: *~/.config/google-chrome/Default/Cookies*
|
23
|
+
* Chromium: *~/.config/chromium/Default/Cookies*
|
13
24
|
|
14
25
|
### License ###
|
15
26
|
|
data/bin/cookie_extractor
CHANGED
@@ -2,22 +2,46 @@
|
|
2
2
|
|
3
3
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "cookie_extractor"))
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
puts "Usage:
|
9
|
-
puts "
|
5
|
+
|
6
|
+
def usage msg=nil
|
7
|
+
puts msg if msg
|
8
|
+
puts "Usage: cookie_extractor /path/to/cookies.sqlite Open a DB file"
|
9
|
+
puts " cookie_extractor --guess Guess which browser to use and open corresponding file"
|
10
|
+
puts " cookie_extractor --browser chrome|chromium|firefox Open DB corresponding to a particular browser"
|
10
11
|
exit
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
|
15
|
+
begin
|
16
|
+
extractor =
|
17
|
+
case ARGV.first
|
18
|
+
when '--guess', '-g'
|
19
|
+
begin
|
20
|
+
CookieExtractor::BrowserDetector.guess()
|
21
|
+
rescue CookieExtractor::NoCookieFileFoundException
|
22
|
+
abort "Error: we couldn't find any supported broswer's cookies"
|
23
|
+
end
|
24
|
+
when '--browser', '-b'
|
25
|
+
browser = ARGV[1]
|
26
|
+
usage "Error: Please supply a browser name" unless browser
|
27
|
+
begin
|
28
|
+
CookieExtractor::BrowserDetector.browser_extractor(browser)
|
29
|
+
rescue CookieExtractor::InvalidBrowserNameException
|
30
|
+
abort "Error: '#{browser}' is not a valid browser name"
|
31
|
+
rescue CookieExtractor::NoCookieFileFoundException
|
32
|
+
abort "Error: Could not locate cookie file for browser #{browser}"
|
33
|
+
end
|
34
|
+
when nil
|
35
|
+
usage
|
36
|
+
else
|
37
|
+
filename = ARGV.first
|
38
|
+
abort "Error: #{filename} does not exist" unless File.exists?(filename)
|
39
|
+
CookieExtractor::BrowserDetector.new_extractor(filename)
|
40
|
+
end
|
41
|
+
puts extractor.extract.join("\n")
|
42
|
+
rescue SQLite3::NotADatabaseException,
|
43
|
+
CookieExtractor::BrowserNotDetectedException
|
44
|
+
abort "Error: File '#{filename}' is not a Firefox or Chrome cookie database"
|
23
45
|
end
|
46
|
+
|
47
|
+
|
@@ -1,7 +1,40 @@
|
|
1
1
|
module CookieExtractor
|
2
2
|
class BrowserNotDetectedException < Exception; end
|
3
|
+
class InvalidBrowserNameException < Exception; end
|
4
|
+
class NoCookieFileFoundException < Exception; end
|
3
5
|
|
4
6
|
class BrowserDetector
|
7
|
+
COOKIE_LOCATIONS = {
|
8
|
+
"chrome" => "~/.config/google-chrome/Default/Cookies",
|
9
|
+
"chromium" => "~/.config/chromium/Default/Cookies",
|
10
|
+
"firefox" => "~/.mozilla/firefox/*.default/cookies.sqlite"
|
11
|
+
}
|
12
|
+
|
13
|
+
# Returns the extractor of the most recently used browser's cookies
|
14
|
+
# or raise NoCookieFileFoundException if there are no cookies
|
15
|
+
def self.guess
|
16
|
+
most_recently_used_detected_browsers.each { |browser, path|
|
17
|
+
begin
|
18
|
+
extractor = self.browser_extractor(browser)
|
19
|
+
rescue BrowserNotDetectedException, NoCookieFileFoundException
|
20
|
+
# better try the next one...
|
21
|
+
else
|
22
|
+
return extractor
|
23
|
+
end
|
24
|
+
}
|
25
|
+
# If we make it here, we've failed...
|
26
|
+
raise NoCookieFileFoundException, "Couldn't find any browser's cookies"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Open a browser's cookie file using intelligent guesswork
|
30
|
+
def self.browser_extractor(browser)
|
31
|
+
raise InvalidBrowserNameException, "Browser must be one of: #{self.supported_browsers.join(', ')}" unless self.supported_browsers.include?(browser)
|
32
|
+
paths = Dir.glob(File.expand_path(COOKIE_LOCATIONS[browser]))
|
33
|
+
if paths.length < 1 or not File.exists?(paths.first)
|
34
|
+
raise NoCookieFileFoundException, "File #{paths.first} does not exist!"
|
35
|
+
end
|
36
|
+
self.new_extractor(paths.first)
|
37
|
+
end
|
5
38
|
|
6
39
|
def self.new_extractor(db_filename)
|
7
40
|
browser = detect_browser(db_filename)
|
@@ -12,6 +45,10 @@ module CookieExtractor
|
|
12
45
|
end
|
13
46
|
end
|
14
47
|
|
48
|
+
def self.supported_browsers
|
49
|
+
COOKIE_LOCATIONS.keys
|
50
|
+
end
|
51
|
+
|
15
52
|
def self.detect_browser(db_filename)
|
16
53
|
db = SQLite3::Database.new(db_filename)
|
17
54
|
browser =
|
@@ -27,5 +64,15 @@ module CookieExtractor
|
|
27
64
|
def self.has_table?(db, table_name)
|
28
65
|
db.table_info(table_name).size > 0
|
29
66
|
end
|
67
|
+
|
68
|
+
def self.most_recently_used_detected_browsers
|
69
|
+
COOKIE_LOCATIONS.select { |browser, path|
|
70
|
+
Dir.glob(File.expand_path(path)).any?
|
71
|
+
}.sort_by { |browser, path|
|
72
|
+
File.mtime(Dir.glob(File.expand_path(path)).first)
|
73
|
+
}.reverse
|
74
|
+
end
|
75
|
+
|
76
|
+
private_class_method :most_recently_used_detected_browsers
|
30
77
|
end
|
31
78
|
end
|
data/lib/cookie_extractor.rb
CHANGED
@@ -41,3 +41,40 @@ describe CookieExtractor::BrowserDetector, "determining the correct extractor to
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe CookieExtractor::BrowserDetector, "guessing the location of the cookie file" do
|
46
|
+
describe "when no cookie files are found in the standard locations" do
|
47
|
+
before :each do
|
48
|
+
Dir.stub!(:glob).and_return([])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise NoCookieFileFoundException" do
|
52
|
+
lambda { CookieExtractor::BrowserDetector.guess }.
|
53
|
+
should raise_error(CookieExtractor::NoCookieFileFoundException)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "when multiple cookie files are found in the standard locations" do
|
58
|
+
before :each do
|
59
|
+
cookie_locations = CookieExtractor::BrowserDetector::COOKIE_LOCATIONS
|
60
|
+
Dir.stub!(:glob).and_return([cookie_locations['chrome']],
|
61
|
+
[],
|
62
|
+
[cookie_locations['firefox']])
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "and chrome was the most recently used" do
|
66
|
+
before :each do
|
67
|
+
File.should_receive(:mtime).twice.and_return(
|
68
|
+
Time.parse("July 2 2013 00:00:00"),
|
69
|
+
Time.parse("July 1 2013 00:00:00"))
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should build a ChromeCookieExtractor" do
|
73
|
+
CookieExtractor::BrowserDetector.
|
74
|
+
should_receive(:browser_extractor).
|
75
|
+
once.with("chrome")
|
76
|
+
CookieExtractor::BrowserDetector.guess
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookie_extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &16244180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.8'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16244180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3-ruby
|
27
|
-
requirement: &
|
27
|
+
requirement: &16243580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '1.3'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *16243580
|
36
36
|
description: Extract cookies from Firefox, Chrome or Chromium sqlite databases into
|
37
37
|
a wget-compatible cookies.txt file.
|
38
38
|
email:
|