database_sleuth 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +38 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/database_sleuth.rb +118 -0
- data/spec/database_sleuth_spec.rb +210 -0
- data/spec/drupal/sites/default/settings.php +240 -0
- data/spec/gallery/config.php +196 -0
- data/spec/joomla/configuration.php +107 -0
- data/spec/mediawiki/LocalSettings.php +124 -0
- data/spec/phpbb/config.php +18 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/wordpress/wp-config.php +76 -0
- data/spec/zencart/includes/configure.php +68 -0
- metadata +82 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Joel Watson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= database_sleuth
|
2
|
+
|
3
|
+
This library is designed to parse popular web application configuration files
|
4
|
+
to extract database connection information for use in other applications or
|
5
|
+
scripts.
|
6
|
+
|
7
|
+
To get started, simply require the library:
|
8
|
+
|
9
|
+
require 'database_sleuth'
|
10
|
+
|
11
|
+
Then, simply create a new instance of the class specifying which application
|
12
|
+
you're collecting information from (note that the library expects the config
|
13
|
+
file to be located in the directory the executing file is running from):
|
14
|
+
|
15
|
+
sleuth = DatabaseSleuth.new(:joomla)
|
16
|
+
sleuth.find_db_info
|
17
|
+
sleuth.dbhost #=> mysql.example.com
|
18
|
+
sleuth.dbname #=> somedbname
|
19
|
+
sleuth.dbuser #=> someusername
|
20
|
+
sleuth.dbpass #=> somepassword
|
21
|
+
|
22
|
+
sleuth.manual_connection_string #=> mysql -u someusername -psomepassword -h mysql.example.com somedbname
|
23
|
+
|
24
|
+
= Supported Applications
|
25
|
+
|
26
|
+
Currently, the following applications are supported:
|
27
|
+
|
28
|
+
* Drupal
|
29
|
+
* Gallery
|
30
|
+
* Joomla
|
31
|
+
* MediaWiki
|
32
|
+
* phpBB
|
33
|
+
* WordPress
|
34
|
+
* ZenCart
|
35
|
+
|
36
|
+
== Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2010 Joel Watson. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "database_sleuth"
|
8
|
+
gem.summary = %Q{Easily find database connection info from common web applications.}
|
9
|
+
gem.description = %Q{Easily find database connection info from common web applications.}
|
10
|
+
gem.email = "watsonian@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/watsonian/database_sleuth"
|
12
|
+
gem.authors = ["watsonian"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "database_sleuth #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,118 @@
|
|
1
|
+
class DatabaseSleuth
|
2
|
+
attr_accessor :application, :locations, :exists_at, :located_at, :regex, :dbname, :dbuser, :dbpass, :dbhost, :dbtableprefix
|
3
|
+
|
4
|
+
@@supported_applications = [:joomla, :wordpress, :drupal, :phpbb, :gallery, :zencart, :mediawiki]
|
5
|
+
|
6
|
+
@@app_metadata = {}
|
7
|
+
@@app_metadata[:drupal] = {
|
8
|
+
:locations => ["sites/default/settings.php"],
|
9
|
+
:regex => {
|
10
|
+
:dbname => Regexp.new("^\\$db_url.*?\\/\\/.*?\\/(.*?)'"),
|
11
|
+
:dbuser => Regexp.new("^\\$db_url.*?\\/\\/(.*)?:.*?'"),
|
12
|
+
:dbpass => Regexp.new("^\\$db_url.*?\\/\\/.*?:(.*)?@.*?'"),
|
13
|
+
:dbhost => Regexp.new("^\\$db_url.*?\\/\\/.*?@(.*)?\\/.*?'"),
|
14
|
+
},
|
15
|
+
}
|
16
|
+
@@app_metadata[:gallery] = {
|
17
|
+
:locations => ["config.php"],
|
18
|
+
:regex => {
|
19
|
+
:dbname => Regexp.new("\\$storeConfig\\['database'.*?'(.*?)'"),
|
20
|
+
:dbuser => Regexp.new("\\$storeConfig\\['username'.*?'(.*?)'"),
|
21
|
+
:dbpass => Regexp.new("\\$storeConfig\\['password'.*?'(.*?)'"),
|
22
|
+
:dbhost => Regexp.new("\\$storeConfig\\['hostname'.*?'(.*?)'"),
|
23
|
+
},
|
24
|
+
}
|
25
|
+
@@app_metadata[:joomla] = {
|
26
|
+
:locations => ["configuration.php"],
|
27
|
+
:regex => {
|
28
|
+
:dbname => Regexp.new("\\$db\\s*=\\s*'(.*?)'"),
|
29
|
+
:dbuser => Regexp.new("\\$user\\s*=\\s*'(.*?)'"),
|
30
|
+
:dbpass => Regexp.new("\\$password\\s*=\\s*'(.*?)'"),
|
31
|
+
:dbhost => Regexp.new("\\$host\\s*=\\s*'(.*?)'"),
|
32
|
+
},
|
33
|
+
}
|
34
|
+
@@app_metadata[:mediawiki] = {
|
35
|
+
:locations => ["LocalSettings.php"],
|
36
|
+
:regex => {
|
37
|
+
:dbname => Regexp.new("\\$wgDBname\\s*=\\s*['\"](.*?)['\"]"),
|
38
|
+
:dbuser => Regexp.new("\\$wgDBuser\\s*=\\s*['\"](.*?)['\"]"),
|
39
|
+
:dbpass => Regexp.new("\\$wgDBpassword\\s*=\\s*['\"](.*?)['\"]"),
|
40
|
+
:dbhost => Regexp.new("\\$wgDBserver\\s*=\\s*['\"](.*?)['\"]"),
|
41
|
+
},
|
42
|
+
}
|
43
|
+
@@app_metadata[:phpbb] = {
|
44
|
+
:locations => ["config.php"],
|
45
|
+
:regex => {
|
46
|
+
:dbname => Regexp.new("dbname\\s*=\\s*'(.*?)'"),
|
47
|
+
:dbuser => Regexp.new("dbuser\\s*=\\s*'(.*?)'"),
|
48
|
+
:dbpass => Regexp.new("dbpasswd\\s*=\\s*'(.*?)'"),
|
49
|
+
:dbhost => Regexp.new("dbhost\\s*=\\s*'(.*?)'"),
|
50
|
+
},
|
51
|
+
}
|
52
|
+
@@app_metadata[:wordpress] = {
|
53
|
+
:locations => ["wp-config.php"],
|
54
|
+
:regex => {
|
55
|
+
:dbname => Regexp.new("DB_NAME'.*?'(.*?)'"),
|
56
|
+
:dbuser => Regexp.new("DB_USER'.*?'(.*?)'"),
|
57
|
+
:dbpass => Regexp.new("DB_PASSWORD'.*?'(.*?)'"),
|
58
|
+
:dbhost => Regexp.new("DB_HOST'.*?'(.*?)'"),
|
59
|
+
:dbtableprefix => Regexp.new("\\$table_prefix\\s*=\\s*'(.*?)'"),
|
60
|
+
},
|
61
|
+
}
|
62
|
+
@@app_metadata[:zencart] = {
|
63
|
+
:locations => ["includes/configure.php"],
|
64
|
+
:regex => {
|
65
|
+
:dbname => Regexp.new("DB_DATABASE'.*?'(.*?)'"),
|
66
|
+
:dbuser => Regexp.new("DB_SERVER_USERNAME'.*?'(.*?)'"),
|
67
|
+
:dbpass => Regexp.new("DB_SERVER_PASSWORD'.*?'(.*?)'"),
|
68
|
+
:dbhost => Regexp.new("DB_SERVER'.*?'(.*?)'"),
|
69
|
+
},
|
70
|
+
}
|
71
|
+
|
72
|
+
def initialize(app)
|
73
|
+
@exists_at = []
|
74
|
+
@dbname = nil
|
75
|
+
@dbuser = nil
|
76
|
+
@dbpass = nil
|
77
|
+
@dbhost = nil
|
78
|
+
self.application = app
|
79
|
+
self.locations = @@app_metadata[@application][:locations]
|
80
|
+
@regex = @@app_metadata[@application][:regex]
|
81
|
+
end
|
82
|
+
|
83
|
+
def application=(app)
|
84
|
+
a = String(app).downcase.to_sym
|
85
|
+
if @@supported_applications.include?(a)
|
86
|
+
instance_variable_set(:@application, a)
|
87
|
+
else
|
88
|
+
raise "That application is not supported yet."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def find_db_info
|
93
|
+
locate_files
|
94
|
+
@exists_at.each do |file|
|
95
|
+
File.foreach(file) do |line|
|
96
|
+
@dbname ||= @regex[:dbname].match(line)[1] if @regex[:dbname] === line
|
97
|
+
@dbuser ||= @regex[:dbuser].match(line)[1] if @regex[:dbuser] === line
|
98
|
+
@dbpass ||= @regex[:dbpass].match(line)[1] if @regex[:dbpass] === line
|
99
|
+
@dbhost ||= @regex[:dbhost].match(line)[1] if @regex[:dbhost] === line
|
100
|
+
@dbtableprefix ||= @regex[:dbtableprefix].match(line)[1] if @regex[:dbtableprefix] === line && @regex.has_key?(:dbtableprefix)
|
101
|
+
@located_at = file if @dbname
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def manual_connection_string
|
107
|
+
"mysql -u #{@dbuser} -p#{@dbpass} -h #{@dbhost} #{@dbname}"
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
def locate_files
|
112
|
+
@locations.each do |loc|
|
113
|
+
if File.exists?(loc)
|
114
|
+
@exists_at << loc
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "DatabaseSleuth" do
|
4
|
+
context "when searching Drupal" do
|
5
|
+
before(:all) do
|
6
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "drupal")) do
|
7
|
+
@sleuth = DatabaseSleuth.new(:drupal)
|
8
|
+
@sleuth.find_db_info
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should find the database name" do
|
13
|
+
@sleuth.dbname.should == "putyourdbnamehere"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should find the username" do
|
17
|
+
@sleuth.dbuser.should == "usernamehere"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should find the user password" do
|
21
|
+
@sleuth.dbpass.should == "yourpasswordhere"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should find the hostname" do
|
25
|
+
@sleuth.dbhost.should == "localhost"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should produce a manual connection string" do
|
29
|
+
@sleuth.manual_connection_string.should == "mysql -u usernamehere -pyourpasswordhere -h localhost putyourdbnamehere"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when searching Gallery" do
|
34
|
+
before(:all) do
|
35
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "gallery")) do
|
36
|
+
@sleuth = DatabaseSleuth.new(:gallery)
|
37
|
+
@sleuth.find_db_info
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should find the database name" do
|
42
|
+
@sleuth.dbname.should == "putyourdbnamehere"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should find the username" do
|
46
|
+
@sleuth.dbuser.should == "usernamehere"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should find the user password" do
|
50
|
+
@sleuth.dbpass.should == "yourpasswordhere"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should find the hostname" do
|
54
|
+
@sleuth.dbhost.should == "localhost"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should produce a manual connection string" do
|
58
|
+
@sleuth.manual_connection_string.should == "mysql -u usernamehere -pyourpasswordhere -h localhost putyourdbnamehere"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when searching Joomla" do
|
63
|
+
before(:all) do
|
64
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "joomla")) do
|
65
|
+
@sleuth = DatabaseSleuth.new(:joomla)
|
66
|
+
@sleuth.find_db_info
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should find the database name" do
|
71
|
+
@sleuth.dbname.should == "putyourdbnamehere"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should find the username" do
|
75
|
+
@sleuth.dbuser.should == "usernamehere"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should find the user password" do
|
79
|
+
@sleuth.dbpass.should == "yourpasswordhere"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should find the hostname" do
|
83
|
+
@sleuth.dbhost.should == "localhost"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should produce a manual connection string" do
|
87
|
+
@sleuth.manual_connection_string.should == "mysql -u usernamehere -pyourpasswordhere -h localhost putyourdbnamehere"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when searching MediaWiki" do
|
92
|
+
before(:all) do
|
93
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "mediawiki")) do
|
94
|
+
@sleuth = DatabaseSleuth.new(:mediawiki)
|
95
|
+
@sleuth.find_db_info
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should find the database name" do
|
100
|
+
@sleuth.dbname.should == "putyourdbnamehere"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should find the username" do
|
104
|
+
@sleuth.dbuser.should == "usernamehere"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should find the user password" do
|
108
|
+
@sleuth.dbpass.should == "yourpasswordhere"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should find the hostname" do
|
112
|
+
@sleuth.dbhost.should == "localhost"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should produce a manual connection string" do
|
116
|
+
@sleuth.manual_connection_string.should == "mysql -u usernamehere -pyourpasswordhere -h localhost putyourdbnamehere"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when searching phpBB" do
|
121
|
+
before(:all) do
|
122
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "phpbb")) do
|
123
|
+
@sleuth = DatabaseSleuth.new(:phpbb)
|
124
|
+
@sleuth.find_db_info
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should find the database name" do
|
129
|
+
@sleuth.dbname.should == "putyourdbnamehere"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should find the username" do
|
133
|
+
@sleuth.dbuser.should == "usernamehere"
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should find the user password" do
|
137
|
+
@sleuth.dbpass.should == "yourpasswordhere"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should find the hostname" do
|
141
|
+
@sleuth.dbhost.should == "localhost"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should produce a manual connection string" do
|
145
|
+
@sleuth.manual_connection_string.should == "mysql -u usernamehere -pyourpasswordhere -h localhost putyourdbnamehere"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "when searching WordPress" do
|
150
|
+
before(:all) do
|
151
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "wordpress")) do
|
152
|
+
@sleuth = DatabaseSleuth.new(:wordpress)
|
153
|
+
@sleuth.find_db_info
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should find the database name" do
|
158
|
+
@sleuth.dbname.should == "putyourdbnamehere"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should find the username" do
|
162
|
+
@sleuth.dbuser.should == "usernamehere"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should find the user password" do
|
166
|
+
@sleuth.dbpass.should == "yourpasswordhere"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should find the hostname" do
|
170
|
+
@sleuth.dbhost.should == "localhost"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should find the database table prefix" do
|
174
|
+
@sleuth.dbtableprefix.should == "wp_"
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should produce a manual connection string" do
|
178
|
+
@sleuth.manual_connection_string.should == "mysql -u usernamehere -pyourpasswordhere -h localhost putyourdbnamehere"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when searching ZenCart" do
|
183
|
+
before(:all) do
|
184
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "zencart")) do
|
185
|
+
@sleuth = DatabaseSleuth.new(:zencart)
|
186
|
+
@sleuth.find_db_info
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should find the database name" do
|
191
|
+
@sleuth.dbname.should == "putyourdbnamehere"
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should find the username" do
|
195
|
+
@sleuth.dbuser.should == "usernamehere"
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should find the user password" do
|
199
|
+
@sleuth.dbpass.should == "yourpasswordhere"
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should find the hostname" do
|
203
|
+
@sleuth.dbhost.should == "localhost"
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should produce a manual connection string" do
|
207
|
+
@sleuth.manual_connection_string.should == "mysql -u usernamehere -pyourpasswordhere -h localhost putyourdbnamehere"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|