Publicado el 13/09/2023 12:09:00 en Hacking General.
Author: Maese | Total de votos: 4 Vote
Algunas vulnerabilidades son invisibles, en el caso de Trojan-Source, lo que hacen es utilizar caracteres de contról Unicode para reordenar el código y así esconder códigos maliciosos, condicionales defectuosos y demás, en código aparentemete seguro e inofensivo.
El ataque
El ataque consiste en utilizar caracteres de control incrustados en comentarios y cadenas para reordenar los caracteres del código fuente de una manera que cambie su lógica.
Por ejemplo, el siguiente código parece funcional e inofensivo:
/* begin admins only */ if (isAdmin) {
Sin embargo, al tener escondidos caracteres de control Unicode para reordenar el flujo de los datos, en realidad el código está totalmente comentado y la validación nunca ocurre:
/* if (isAdmin) { begin admins only */
Esta vulnerabilidad está registrada en el CVE-2021-42574 y dice en su explicación:
An issue was discovered in the Bidirectional Algorithm in the Unicode Specification through 14.0. It permits the visual reordering of characters via control sequences, which can be used to craft source code that renders different logic than the logical ordering of tokens ingested by compilers and interpreters. Adversaries can leverage this to encode source code for compilers accepting Unicode such that targeted vulnerabilities are introduced invisibly to human reviewers. NOTE: the Unicode Consortium offers the following alternative approach to presenting this concern. An issue is noted in the nature of international text that can affect applications that implement support for The Unicode Standard and the Unicode Bidirectional Algorithm (all versions). Due to text display behavior when text includes left-to-right and right-to-left characters, the visual order of tokens may be different from their logical order. Additionally, control characters needed to fully support the requirements of bidirectional text can further obfuscate the logical order of tokens. Unless mitigated, an adversary could craft source code such that the ordering of tokens perceived by human reviewers does not match what will be processed by a compiler/interpreter/etc. The Unicode Consortium has documented this class of vulnerability in its document, Unicode Technical Report #36, Unicode Security Considerations. The Unicode Consortium also provides guidance on mitigations for this class of issues in Unicode Technical Standard #39, Unicode Security Mechanisms, and in Unicode Standard Annex #31, Unicode Identifier and Pattern Syntax. Also, the BIDI specification allows applications to tailor the implementation in ways that can mitigate misleading visual reordering in program text; see HL4 in Unicode Standard Annex #9, Unicode Bidirectional Algorithm.
La vulnerabilidad en cuestión se presenta gracias al fallo de aplicaciones como VSCode, al hacer invisibles dichos caracteres. A continuación dejo una tabla de apps vulnerables y parcialmente parcheadas.

Un paper técnico muy completo se puede leer en el siguiente PDF:
trojan-source.pdf