spinal_tap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +55 -0
- data/Rakefile +34 -0
- data/lib/spinal_tap/client_helpers.rb +9 -0
- data/lib/spinal_tap/server.rb +108 -0
- data/lib/spinal_tap/version.rb +3 -0
- data/lib/spinal_tap.rb +25 -0
- data/spec/spec_helper.rb +23 -0
- data/spinal_tap.gemspec +23 -0
- metadata +145 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Chad Remesch
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# SpinalTap
|
2
|
+
|
3
|
+
Spinal tap lets you easily connect to running Ruby processes such as daemons and cron scripts.
|
4
|
+
Once connected, you can execute arbitrary commands inside of your process.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'spinal_tap'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install spinal_tap
|
19
|
+
|
20
|
+
## Basic Usage
|
21
|
+
|
22
|
+
Start spinal at the beginning of your long running process:
|
23
|
+
|
24
|
+
SpinalTap.start
|
25
|
+
|
26
|
+
By default it will listen for TCP connections on 127.0.0.1:9000.
|
27
|
+
You can then telnet into your process and type 'help' to view the default list of commands.
|
28
|
+
Spinal Tap uses threads to run in the background of your process.
|
29
|
+
|
30
|
+
SpinalTap.start accepts the following options:
|
31
|
+
|
32
|
+
:host => The address to listen on (default: 127.0.0.1).
|
33
|
+
:port => The port to listen on (default: 9000).
|
34
|
+
|
35
|
+
You can stop the spinal tap server at any time:
|
36
|
+
|
37
|
+
SpinalTap.stop
|
38
|
+
|
39
|
+
## Security
|
40
|
+
|
41
|
+
With great power comes great responsibility.
|
42
|
+
Currently no authentication exists so anyone who can connect to Spinal Tap has complete control over your process.
|
43
|
+
This includes changing memory, reloading classes, killing the process, and pretty much any other nasty thing you can with Ruby's 'eval' method.
|
44
|
+
Use at your own risk! You have been warned!
|
45
|
+
|
46
|
+
# Contributing to Spinal Tap:
|
47
|
+
|
48
|
+
1. Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
49
|
+
2. Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
50
|
+
3. Fork the project.
|
51
|
+
4. Start a feature/bugfix branch.
|
52
|
+
5. Commit and push until you are happy with your contribution.
|
53
|
+
6. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
54
|
+
7. Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
55
|
+
8. Create a new Pull Request.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :spec
|
15
|
+
|
16
|
+
desc 'Start an IRB console with offier loaded'
|
17
|
+
task :console do
|
18
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
19
|
+
|
20
|
+
require 'spinal_tap'
|
21
|
+
require 'irb'
|
22
|
+
|
23
|
+
ARGV.clear
|
24
|
+
|
25
|
+
IRB.start
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Run all specs'
|
29
|
+
task :spec do
|
30
|
+
puts 'Running rspec:'
|
31
|
+
system 'rspec spec'
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :spec
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module SpinalTap
|
4
|
+
|
5
|
+
class Server
|
6
|
+
def initialize(params = {})
|
7
|
+
@host = params[:host] || '127.0.0.1'
|
8
|
+
@port = params[:port] || 9000
|
9
|
+
|
10
|
+
@run = false
|
11
|
+
@workers = {}
|
12
|
+
@workers_lock = Mutex.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
return false if @running
|
17
|
+
|
18
|
+
@running = true
|
19
|
+
|
20
|
+
@listener_thread = Thread.new do
|
21
|
+
@server_sock = TCPServer.new(@host, @port)
|
22
|
+
|
23
|
+
while true
|
24
|
+
Thread.new(@server_sock.accept) do |client|
|
25
|
+
begin
|
26
|
+
@workers_lock.synchronize do
|
27
|
+
@workers[Thread.current] = client
|
28
|
+
end
|
29
|
+
|
30
|
+
client.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
31
|
+
client.extend(SpinalTap::ClientHelpers)
|
32
|
+
|
33
|
+
process(client)
|
34
|
+
rescue Exception => e
|
35
|
+
puts("WORKER DIED: #{exception_to_s(e)}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
def stop
|
45
|
+
return false unless @running
|
46
|
+
|
47
|
+
Thread.kill(@listener_thread)
|
48
|
+
@server_sock.close
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def workers
|
54
|
+
@workers_lock.synchronize do
|
55
|
+
return @workers.clone
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def process(client)
|
62
|
+
client.prompt
|
63
|
+
|
64
|
+
while(line = client.gets)
|
65
|
+
line.chomp!
|
66
|
+
|
67
|
+
tokens = line.split(' ')
|
68
|
+
command = tokens.first
|
69
|
+
|
70
|
+
case command
|
71
|
+
when 'help' then exec_help(client)
|
72
|
+
when 'eval' then exec_eval(client, tokens[1..-1].join(' '))
|
73
|
+
when 'quit'
|
74
|
+
client.close
|
75
|
+
break
|
76
|
+
else
|
77
|
+
client.puts('Unknown command')
|
78
|
+
end
|
79
|
+
|
80
|
+
client.prompt
|
81
|
+
end
|
82
|
+
|
83
|
+
ensure
|
84
|
+
client.close unless client.closed?
|
85
|
+
|
86
|
+
@workers_lock.synchronize do
|
87
|
+
@workers.delete(Thread.current)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def exec_help(client)
|
92
|
+
client.puts('Commands: help quit eval')
|
93
|
+
end
|
94
|
+
|
95
|
+
def exec_eval(client, code)
|
96
|
+
begin
|
97
|
+
result = eval(code)
|
98
|
+
client.puts(result.to_s)
|
99
|
+
rescue Exception => e
|
100
|
+
client.puts(exception_to_s(e))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def exception_to_s(e)
|
105
|
+
"#{e.message}\r\n#{e.backtrace.join("\r\n")}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/spinal_tap.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spinal_tap/version'
|
2
|
+
require 'spinal_tap/server'
|
3
|
+
require 'spinal_tap/client_helpers'
|
4
|
+
|
5
|
+
module SpinalTap
|
6
|
+
def self.start(params = {})
|
7
|
+
return false if @server
|
8
|
+
|
9
|
+
@server = SpinalTap::Server.new(params)
|
10
|
+
@server.start
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.stop
|
14
|
+
return false unless @server
|
15
|
+
|
16
|
+
result = @server.stop
|
17
|
+
@server = nil
|
18
|
+
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.server
|
23
|
+
@server
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler'
|
6
|
+
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'benchmark'
|
16
|
+
require 'spinal_tap'
|
17
|
+
|
18
|
+
# Requires supporting files with custom matchers and macros, etc,
|
19
|
+
# in ./support/ and its subdirectories.
|
20
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
end
|
data/spinal_tap.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/spinal_tap/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Chad Remesch"]
|
6
|
+
gem.email = ["chad@remesch.com"]
|
7
|
+
gem.description = %q{Backdoor into your long running ruby processes.}
|
8
|
+
gem.summary = %q{Spinal tap lets you easily connect into running ruby processes such as daemons and cron scripts. With great power comes great responsibility.}
|
9
|
+
gem.homepage = "http://github.com/chadrem/spinal_tap"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "spinal_tap"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SpinalTap::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency('rake', ['= 0.9.2.2'])
|
19
|
+
gem.add_development_dependency('rspec', ['= 2.11'])
|
20
|
+
gem.add_development_dependency('guard', ['= 1.2.3'])
|
21
|
+
gem.add_development_dependency('guard-rspec', ['= 1.2.0'])
|
22
|
+
gem.add_development_dependency('growl', ['= 1.0.3'])
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spinal_tap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chad Remesch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.2.2
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.2.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.11'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.11'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.2.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.2.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: growl
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.0.3
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.3
|
94
|
+
description: Backdoor into your long running ruby processes.
|
95
|
+
email:
|
96
|
+
- chad@remesch.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- Guardfile
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/spinal_tap.rb
|
108
|
+
- lib/spinal_tap/client_helpers.rb
|
109
|
+
- lib/spinal_tap/server.rb
|
110
|
+
- lib/spinal_tap/version.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spinal_tap.gemspec
|
113
|
+
homepage: http://github.com/chadrem/spinal_tap
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: 4269159806787806500
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
hash: 4269159806787806500
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.24
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: Spinal tap lets you easily connect into running ruby processes such as daemons
|
143
|
+
and cron scripts. With great power comes great responsibility.
|
144
|
+
test_files:
|
145
|
+
- spec/spec_helper.rb
|