violent_ruby 1.0.4 → 1.0.5
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33a58cf1850ba7c2fe34a78184003df715f38d6e
|
4
|
+
data.tar.gz: '09cdc0184b90dd093962ce68fe70ee7dd25fdb11'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96e247c8c71dab2d7db255fd1c33c4f3e15c1e8059c1ea5d18d6b40a55d2667d2cf37aa3e489d0774af4c3f01742f8dc948b223cea650c42b65dff6b86d8464c
|
7
|
+
data.tar.gz: df39fec11d77efe459c475cfb85552c2808c6055933a64ce448cdc67f187896067e7c23d102c7ecf8b4fc7f56336465c4fa933c4cd76278d95657e4a356f9e0e
|
@@ -3,55 +3,77 @@ module ViolentRuby
|
|
3
3
|
# crack unix passwords. Because all hackers totes do this.
|
4
4
|
# @author Kent 'picat' Gruber
|
5
5
|
#
|
6
|
-
# == Create a new Unix Password Cracker
|
7
|
-
# In order for the password cracker to work, we're going to need a +dictionary+,
|
8
|
-
# and an /etc/passwd +file+ we want to crack.
|
9
|
-
#
|
10
6
|
# @example Basic Usage
|
11
|
-
# config = { file: "/etc/passwd",
|
7
|
+
# config = { file: "/etc/passwd", dictionary: "dictionary.txt" }
|
8
|
+
#
|
12
9
|
# upc = ViolentRuby::UnixPasswordCracker.new(config)
|
13
|
-
#
|
10
|
+
#
|
11
|
+
# upc.crack do |result|
|
12
|
+
# next unless result[:cracked]
|
13
|
+
# puts "Cracked #{result[:username]}'s password: #{result[:plaintext_password]}"
|
14
|
+
# end
|
15
|
+
#
|
14
16
|
class UnixPasswordCracker
|
15
|
-
#
|
17
|
+
# @!attribute file
|
18
|
+
# @return [String] Path to the /etc/passwd file.
|
16
19
|
attr_accessor :file
|
17
|
-
|
20
|
+
|
21
|
+
# @!attribute dictionary
|
22
|
+
# @return [String] Path to dictionary file.
|
18
23
|
attr_accessor :dictionary
|
19
24
|
|
25
|
+
alias etc file
|
26
|
+
|
20
27
|
# Create a new Unix Password Cracker.
|
28
|
+
#
|
29
|
+
# @param args [Hash] The options to create a new Unix Password Cracker.
|
30
|
+
# @option args [String] :file The path to an /etc/passwd file.
|
31
|
+
# @option args [String] :dictionary The path to a dictionry of passwords.
|
21
32
|
#
|
22
|
-
# @
|
23
|
-
# @param args [String] :file The path to an /etc/passwd file.
|
24
|
-
# @param args [String] :dictionary The path to a dictionry of passwords.
|
33
|
+
# @return [UnixPasswordCracker]
|
25
34
|
def initialize(args = {})
|
26
|
-
@file =
|
27
|
-
@dictionary =
|
28
|
-
if args[:file] && File.readable?(args[:file])
|
29
|
-
@file = args[:file]
|
30
|
-
@credentials = parse_etc_file(file: args[:file])
|
31
|
-
end
|
32
|
-
return unless args[:dictionary]
|
33
|
-
return unless File.readable?(args[:dictionary])
|
34
|
-
@dictionary = args[:dictionary]
|
35
|
+
@file = args[:file] if args[:file]
|
36
|
+
@dictionary = args[:dictionary] if args[:dictionary]
|
35
37
|
end
|
36
38
|
|
37
39
|
# Parse a unix /etc/passwd file into a more mangeable form.
|
38
40
|
#
|
39
|
-
# @
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
41
|
+
# @example Basic Usage
|
42
|
+
# upc = ViolentRuby::UnixPasswordCracker.new
|
43
|
+
# upc.parse_etc_file(file: 'passwords.txt')
|
44
|
+
# # {"victim" => "HX9LLTdc/jiDE", "root" => "DFNFxgW7C05fo"}
|
45
|
+
#
|
46
|
+
# @example Super Advanced Usage
|
47
|
+
# ViolentRuby::UnixPasswordCracker.new.parse_etc_file(file: 'passwords.txt') do |user, pass|
|
48
|
+
# puts user + ' ' + pass
|
49
|
+
# end
|
50
|
+
# # victim HX9LLTdc/jiDE
|
51
|
+
# # root DFNFxgW7C05fo
|
52
|
+
#
|
53
|
+
# @param args [Hash] The options when parsing the file.
|
54
|
+
# @option args [String] :file The path to an /etc/passwd file.
|
55
|
+
# @option args [Boolean] :users Specify that only users should be returned ( default: +false+ ).
|
56
|
+
# @option args [Boolean] :passwords Specify that only passwords should be returned ( default: +false+ ).
|
57
|
+
#
|
43
58
|
# @return [Hash]
|
44
59
|
def parse_etc_file(args = {})
|
45
|
-
|
46
|
-
raise "File #{args[:file]} not readable!" unless File.readable?(args[:file])
|
60
|
+
# Readlines from /etc/passwd file.
|
47
61
|
lines = File.readlines(args[:file]).collect do |line|
|
48
62
|
line unless line.split(':').first.chars.first.include?('#')
|
49
63
|
end
|
50
|
-
|
51
|
-
|
64
|
+
|
65
|
+
# Collect the users and passwords from the lines.
|
66
|
+
users = lines.collect { |x| x.split(':')[0] }.map(&:strip)
|
52
67
|
passwords = lines.collect { |x| x.split(':')[1] }.map(&:strip)
|
68
|
+
|
69
|
+
# Friendly behavior to return just users or passwords.
|
70
|
+
return users if args[:users]
|
53
71
|
return passwords if args[:passwords]
|
72
|
+
|
73
|
+
# Zip'm together into a hash.
|
54
74
|
users_passwords = Hash[users.zip(passwords)]
|
75
|
+
|
76
|
+
# Yield each pair when a block is given, or return all at once.
|
55
77
|
if block_given?
|
56
78
|
users_passwords.each do |user, password|
|
57
79
|
yield user, password
|
@@ -62,22 +84,35 @@ module ViolentRuby
|
|
62
84
|
end
|
63
85
|
|
64
86
|
# Crack unix passwords.
|
87
|
+
#
|
88
|
+
# @example Basic Usage
|
89
|
+
# ViolentRuby::UnixPasswordCracker.new(file: "passwords.txt", dictionary: "dictionary.txt").crack_passwords do |result|
|
90
|
+
# next unless result[:cracked]
|
91
|
+
# puts "Cracked #{result[:username]}'s password: #{result[:plaintext_password]}"
|
92
|
+
# end
|
65
93
|
#
|
66
|
-
# @param [Hash]
|
67
|
-
# @
|
68
|
-
# @
|
69
|
-
#
|
94
|
+
# @param args [Hash] The options when crack'n some passwords.
|
95
|
+
# @option args [String] :file The path to an /etc/passwd file.
|
96
|
+
# @option args [String] :dictionary The path to a dictionry of passwords.
|
97
|
+
#
|
98
|
+
# @yield [Hash]
|
70
99
|
def crack_passwords(args = {})
|
100
|
+
# Use the file and dictionry instance variables or the arguments.
|
71
101
|
file = args[:file] || @file
|
72
102
|
dict = args[:dictionary] || @dictionary
|
73
|
-
|
103
|
+
# Parse the given /etc/passwd file and compare with the dictionary.
|
74
104
|
parse_etc_file(file: file) do |user, password|
|
75
105
|
File.readlines(dict).map(&:strip).each do |word|
|
76
|
-
|
106
|
+
if cracked?(password, word)
|
107
|
+
yield format_result(user, password, word)
|
108
|
+
else
|
109
|
+
yield format_result(user, password)
|
110
|
+
end
|
77
111
|
end
|
78
112
|
end
|
79
|
-
results
|
80
113
|
end
|
114
|
+
|
115
|
+
alias crack crack_passwords
|
81
116
|
|
82
117
|
alias crack! crack_passwords
|
83
118
|
|
@@ -88,11 +123,25 @@ module ViolentRuby
|
|
88
123
|
# Check if a given encrypted password matches a given plaintext
|
89
124
|
# word when the same crytographic operation is performed on it.
|
90
125
|
#
|
91
|
-
# @
|
92
|
-
#
|
126
|
+
# @example Basic Usage
|
127
|
+
# ViolentRuby::UnixPasswordCracker.new.check_password('HX9LLTdc/jiDE', 'egg')
|
128
|
+
# # true
|
129
|
+
#
|
130
|
+
# @example Advanced Usage
|
131
|
+
# ViolentRuby::UnixPasswordCracker.new.check_password('HXA82SzTqypHA', 'egg ')
|
132
|
+
# # false
|
133
|
+
#
|
134
|
+
# ViolentRuby::UnixPasswordCracker.new.check_password('HXA82SzTqypHA', 'egg ', false)
|
135
|
+
# # true
|
136
|
+
#
|
137
|
+
# @param encrypted_password [String] The encrypted password to check against.
|
138
|
+
# @param plaintext_password [String] The plaintext password to check against.
|
139
|
+
# @param strip [Boolean] Strip trailing spaces and newlines from word ( default: +true+ )
|
140
|
+
#
|
93
141
|
# @return [Boolean]
|
94
|
-
def check_password(encrypted_password,
|
95
|
-
if
|
142
|
+
def check_password(encrypted_password, plaintext_password, strip = true)
|
143
|
+
plaintext_password.strip! if strip # sometimes passwords have trailing spaces
|
144
|
+
if plaintext_password.crypt(encrypted_password[0, 2]) == encrypted_password
|
96
145
|
true
|
97
146
|
else
|
98
147
|
false
|
@@ -106,12 +155,22 @@ module ViolentRuby
|
|
106
155
|
# @api private
|
107
156
|
# Format the results for the password crack'n.
|
108
157
|
#
|
109
|
-
# @param [String]
|
110
|
-
# @param [String]
|
111
|
-
# @param [String]
|
158
|
+
# @param user [String]
|
159
|
+
# @param encrypted_pass [String]
|
160
|
+
# @param plaintext_pass [String]
|
161
|
+
#
|
112
162
|
# @return [Hash]
|
113
|
-
def format_result(user, encrypted_pass, plaintext_pass)
|
114
|
-
|
163
|
+
def format_result(user, encrypted_pass, plaintext_pass = false)
|
164
|
+
result = {}
|
165
|
+
if plaintext_pass
|
166
|
+
result[:cracked] = true
|
167
|
+
else
|
168
|
+
result[:cracked] = false
|
169
|
+
end
|
170
|
+
result[:username] = user
|
171
|
+
result[:encrypted_password] = encrypted_pass
|
172
|
+
result[:plaintext_password] = plaintext_pass if plaintext_pass
|
173
|
+
result
|
115
174
|
end
|
116
175
|
end
|
117
176
|
end
|
data/lib/violent_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: violent_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kent Gruber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|