@@ -63,14 +63,15 @@ def flowise_requires_auth?(version = nil)
6363 #
6464 # @param email [String] The email address for authentication
6565 # @param password [String] The password for authentication
66- # @return [Boolean] true if authentication succeeds, false otherwise
66+ # @return [Boolean] true if authentication succeeds
67+ # @raise [Msf::Exploit::Failed] if authentication fails or credentials are invalid
6768 #
6869 # @example
69- # if flowise_login('admin@example.com', 'password')
70- # print_good('Logged in successfully')
71- # end
70+ # flowise_login('admin@example.com', 'password')
7271 def flowise_login ( email , password )
73- return false if email . blank? || password . blank?
72+ if email . blank? || password . blank?
73+ fail_with ( Msf ::Exploit ::Failure ::BadConfig , 'Email and password are required for authentication' )
74+ end
7475
7576 login_url = normalize_uri ( target_uri . path , 'api' , 'v1' , 'auth' , 'login' )
7677 res = send_request_cgi ( {
@@ -88,16 +89,23 @@ def flowise_login(email, password)
8889 } . to_json
8990 } )
9091
91- return false unless res
92+ unless res
93+ fail_with ( Msf ::Exploit ::Failure ::TimeoutExpired , 'No response from server during login attempt' )
94+ end
9295
93- if res . code == 200 || res . code == 201
96+ case res . code
97+ when 200 , 201
9498 print_good ( 'Authentication successful' )
9599 return true
100+ when 401
101+ fail_with ( Msf ::Exploit ::Failure ::NoAccess , 'Authentication failed - invalid credentials' )
102+ when 404
103+ # Flowise returns 404 with "User Not Found" when the user doesn't exist
104+ fail_with ( Msf ::Exploit ::Failure ::NoAccess , 'Authentication failed - user not found' )
105+ else
106+ fail_with ( Msf ::Exploit ::Failure ::UnexpectedReply , "Login failed with HTTP #{ res . code } " )
96107 end
97-
98- fail_with ( Msf ::Exploit ::Failure ::NoAccess , 'Authentication failed - invalid credentials' ) if res . code == 401
99-
100- fail_with ( Msf ::Exploit ::Failure ::UnexpectedReply , "Login failed with HTTP #{ res . code } " )
108+ >>>>>>> fe127778c8 ( Apply review suggestions : use case /when , improve error handling , simplify code )
101109 end
102110
103111 # Sends a request to the customMCP endpoint
@@ -142,28 +150,23 @@ def flowise_send_custommcp_request(payload_data, opts = {})
142150 return true
143151 end
144152
145- if res . code == 200
153+ case res . code
154+ when 200
146155 vprint_status ( 'Command sent successfully (HTTP 200)' )
147156 return true
148- end
149-
150- if res . code == 401
157+ when 401
151158 vprint_error ( 'Authentication required - check credentials' )
152159 return false
153- end
154-
155- if res . code == 404
160+ when 404
156161 vprint_error ( 'Endpoint not found - target may not be vulnerable' )
157162 return false
158- end
159-
160- if res . code == 500
163+ when 500
161164 vprint_error ( 'Server error - command may have failed to execute' )
162165 return true
166+ else
167+ vprint_warning ( "Unexpected HTTP response code: #{ res . code } " )
168+ return true
163169 end
164-
165- vprint_warning ( "Unexpected HTTP response code: #{ res . code } " )
166- return true
167170 end
168171 end
169172 end
0 commit comments