@@ -26,85 +26,76 @@ def initialize
26
26
end
27
27
28
28
def run
29
- @wordlist = Rex ::Quickfile . new ( "jtrtmp" )
30
-
31
- @wordlist . write ( build_seed ( ) . flatten . uniq . join ( "\n " ) + "\n " )
32
- @wordlist . close
33
- crack ( "oracle" )
34
- crack ( "oracle11g" )
35
- end
36
-
37
- def report_cred ( opts )
38
- service_data = {
39
- address : opts [ :ip ] ,
40
- port : opts [ :port ] ,
41
- service_name : opts [ :service_name ] ,
42
- protocol : 'tcp' ,
43
- workspace_id : myworkspace_id
44
- }
45
-
46
- credential_data = {
47
- origin_type : :service ,
48
- module_fullname : fullname ,
49
- username : opts [ :user ] ,
50
- private_data : opts [ :password ] ,
51
- private_type : :nonreplayable_hash ,
52
- jtr_format : opts [ :format ]
53
- } . merge ( service_data )
54
-
55
- login_data = {
56
- core : create_credential ( credential_data ) ,
57
- status : Metasploit ::Model ::Login ::Status ::UNTRIED ,
58
- proof : opts [ :proof ]
59
- } . merge ( service_data )
60
-
61
- create_credential_login ( login_data )
62
- end
63
-
64
-
65
- def crack ( format )
29
+ cracker = new_john_cracker
30
+
31
+ # generate our wordlist and close the file handle
32
+ wordlist = wordlist_file
33
+ wordlist . close
34
+ print_status "Wordlist file written out to #{ wordlist . path } "
35
+ cracker . wordlist = wordlist . path
36
+ #cracker.hash_path = hash_file("des")
37
+
38
+ [ 'oracle' , 'oracle11' ] . each do |format |
39
+ cracker_instance = cracker . dup
40
+ cracker_instance . format = format
41
+
42
+ case format
43
+ when 'oracle'
44
+ cracker_instance . hash_path = hash_file ( 'des' )
45
+ when 'oracle11'
46
+ cracker_instance . hash_path = hash_file ( 'raw-sha1' )
47
+ end
66
48
67
- hashlist = Rex ::Quickfile . new ( "jtrtmp" )
68
- ltype = "#{ format } .hashes"
69
- myloots = myworkspace . loots . where ( 'ltype=?' , ltype )
70
- unless myloots . nil? or myloots . empty?
71
- myloots . each do |myloot |
72
- begin
73
- oracle_array = CSV . read ( myloot . path ) . drop ( 1 )
74
- rescue Exception => e
75
- print_error ( "Unable to read #{ myloot . path } \n #{ e } " )
76
- end
77
- oracle_array . each do |row |
78
- hashlist . write ( "#{ row [ 0 ] } :#{ row [ 1 ] } :#{ myloot . host . address } :#{ myloot . service . port } \n " )
79
- end
49
+ print_status "Cracking #{ format } hashes in normal wordlist mode..."
50
+ # Turn on KoreLogic rules if the user asked for it
51
+ if datastore [ 'KoreLogic' ]
52
+ cracker_instance . rules = 'KoreLogicRules'
53
+ print_status "Applying KoreLogic ruleset..."
54
+ end
55
+ print_status "Crack command #{ cracker_instance . crack_command . join ( ' ' ) } "
56
+ cracker_instance . crack do |line |
57
+ print_status line . chomp
80
58
end
81
- hashlist . close
82
59
83
- print_status ( "HashList: #{ hashlist . path } " )
84
- print_status ( "Trying Wordlist: #{ @wordlist . path } " )
85
- john_crack ( hashlist . path , :wordlist => @wordlist . path , :rules => 'single' , :format => format )
60
+ print_status "Cracking #{ format } hashes in single mode..."
61
+ cracker_instance . rules = 'single'
62
+ cracker_instance . crack do |line |
63
+ print_status line . chomp
64
+ end
86
65
87
- print_status ( "Trying Rule: All4..." )
88
- john_crack ( hashlist . path , :incremental => "All4" , :format => format )
66
+ print_status "Cracked passwords this run:"
67
+ cracker_instance . each_cracked_password do |password_line |
68
+ password_line . chomp!
69
+ next if password_line . blank?
70
+ fields = password_line . split ( ":" )
71
+ # If we don't have an expected minimum number of fields, this is probably not a hash line
72
+ next unless fields . count >=3
73
+ username = fields . shift
74
+ core_id = fields . pop
75
+ password = fields . join ( ':' ) # Anything left must be the password. This accounts for passwords with : in them
76
+
77
+ # Postgres hashes always prepend the username to the password before hashing. So we strip the username back off here.
78
+ password . gsub! ( /^#{ username } / , '' )
79
+ print_good "#{ username } :#{ password } :#{ core_id } "
80
+ create_cracked_credential ( username : username , password : password , core_id : core_id )
81
+ end
82
+ end
89
83
90
- print_status ( "Trying Rule: Digits5..." )
91
- john_crack ( hashlist . path , :incremental => "Digits5" , :format => format )
84
+ end
92
85
93
- cracked = john_show_passwords ( hashlist . path , format )
94
86
95
- print_status ( "#{ cracked [ :cracked ] } hashes were cracked!" )
96
- cracked [ :users ] . each_pair do |k , v |
97
- print_good ( "Host: #{ v [ 1 ] } Port: #{ v [ 2 ] } User: #{ k } Pass: #{ v [ 0 ] } " )
98
- report_cred (
99
- ip : v [ 1 ] ,
100
- port : v [ 2 ] ,
101
- service_name : 'oracle' ,
102
- user : k ,
103
- pass : v [ 0 ] ,
104
- format : format ,
105
- proof : cracked . inspect
106
- )
87
+ def hash_file ( format )
88
+ hashlist = Rex ::Quickfile . new ( "hashes_tmp" )
89
+ Metasploit ::Credential ::NonreplayableHash . joins ( :cores ) . where ( metasploit_credential_cores : { workspace_id : myworkspace . id } , jtr_format : format ) . each do |hash |
90
+ hash . cores . each do |core |
91
+ user = core . public . username
92
+ hash_string = "#{ hash . data . split ( ':' ) [ 1 ] } "
93
+ id = core . id
94
+ hashlist . puts "#{ user } :#{ hash_string } :#{ id } :"
107
95
end
108
96
end
97
+ hashlist . close
98
+ print_status "Hashes Written out to #{ hashlist . path } "
99
+ hashlist . path
109
100
end
110
101
end
0 commit comments