CWE-123 Base Borrador High likelihood

Write-what-where Condition

A write-what-where condition occurs when an attacker can control both the data written and the exact memory location where it's written, often due to a severe memory corruption flaw like a buffer…

Definición

What is CWE-123?

A write-what-where condition occurs when an attacker can control both the data written and the exact memory location where it's written, often due to a severe memory corruption flaw like a buffer overflow.
This vulnerability is one of the most dangerous memory corruption issues. It gives an attacker near-total control over a program's execution by allowing them to overwrite critical data or code pointers in memory. Think of it as an attacker having a precise remote control to edit the program's own instruction manual while it's running, which can directly lead to arbitrary code execution. For developers, this highlights the critical importance of secure memory management. Preventing this condition requires rigorous bounds checking, using safe functions that limit write lengths, and employing modern security features like address space layout randomization (ASLR) and stack canaries. It's often the final, exploitable result of simpler bugs like buffer overflows, making those initial flaws far more severe.
Impacto en el mundo real

Real-world CVEs caused by CWE-123

  • Chain: Python library does not limit the resources used to process images that specify a very large number of bands (CWE-1284), leading to excessive memory consumption (CWE-789) or an integer overflow (CWE-190).

  • Chain: 3D renderer has an integer overflow (CWE-190) leading to write-what-where condition (CWE-123) using a crafted image.

Cómo lo explotan los atacantes

Ruta del atacante paso a paso

  1. 1

    The classic example of a write-what-where condition occurs when the accounting information for memory allocations is overwritten in a particular fashion. Here is an example of potentially vulnerable code:

  2. 2

    Vulnerability in this case is dependent on memory layout. The call to strcpy() can be used to write past the end of buf1, and, with a typical layout, can overwrite the accounting information that the system keeps for buf2 when it is allocated. Note that if the allocation header for buf2 can be overwritten, buf2 itself can be overwritten as well.

  3. 3

    The allocation header will generally keep a linked list of memory "chunks". Particularly, there may be a "previous" chunk and a "next" chunk. Here, the previous chunk for buf2 will probably be buf1, and the next chunk may be null. When the free() occurs, most memory allocators will rewrite the linked list using data from buf2. Particularly, the "next" chunk for buf1 will be updated and the "previous" chunk for any subsequent chunk will be updated. The attacker can insert a memory address for the "next" chunk and a value to write into that memory address for the "previous" chunk.

  4. 4

    This could be used to overwrite a function pointer that gets dereferenced later, replacing it with a memory address that the attacker has legitimate access to, where they have placed malicious code, resulting in arbitrary code execution.

Ejemplo de código vulnerable

Vulnerable C

The classic example of a write-what-where condition occurs when the accounting information for memory allocations is overwritten in a particular fashion. Here is an example of potentially vulnerable code:

Vulnerable C
#define BUFSIZE 256
  int main(int argc, char **argv) {
  	char *buf1 = (char *) malloc(BUFSIZE);
  	char *buf2 = (char *) malloc(BUFSIZE);
  	strcpy(buf1, argv[1]);
  	free(buf2);
  }
Ejemplo de código seguro

Secure pseudo

Seguro pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de prevención

How to prevent CWE-123

  • Architecture and Design Use a language that provides appropriate memory abstractions.
  • Operation Use OS-level preventative functionality integrated after the fact. Not a complete solution.
Señales de detección

How to detect CWE-123

SAST High

Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.

DAST Moderate

Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.

Runtime Moderate

Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.

Code review Moderate

Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-123 y abre un PR de corrección en menos de 60 segundos.

Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.

Preguntas frecuentes

Frequently asked questions

¿Qué es CWE-123?

A write-what-where condition occurs when an attacker can control both the data written and the exact memory location where it's written, often due to a severe memory corruption flaw like a buffer overflow.

¿Qué gravedad tiene CWE-123?

MITRE califica la probabilidad de explotación como Alta — esta debilidad se explota activamente en la práctica y debe priorizarse para su remediación.

¿Qué lenguajes o plataformas se ven afectados por CWE-123?

MITRE lists the following affected platforms: C, C++.

¿Cómo puedo prevenir CWE-123?

Use a language that provides appropriate memory abstractions. Use OS-level preventative functionality integrated after the fact. Not a complete solution.

¿Cómo detecta y corrige Plexicus CWE-123?

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-123 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.

¿Dónde puedo aprender más sobre CWE-123?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/123.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.

Listo cuando tú lo estés

Deja de pagar por desarrollador.
Empieza a cerrar el bucle.

Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.