CWE-123 Base Brouillon 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…

Définition

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.
Impact réel

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.

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  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.

Exemple de code vulnérable

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:

Vulnérable 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);
  }
Exemple de code sécurisé

Secure pseudo

Sécurisé 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.
Liste de contrôle de prévention

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.
Signaux de détection

How to detect CWE-123

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

CWE-123

Don't catalog this weakness. Prove it's reachable.

Plexicus turns CWE catalogs into evidence: every CWE-pattern is matched against your real code graph, reach is proven on a sandbox clone, and verified findings ship as reviewed PRs.

Questions fréquentes

Frequently asked questions

Qu'est-ce que 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.

Quelle est la gravité de CWE-123 ?

MITRE évalue la probabilité d'exploitation comme Élevée — cette faiblesse est activement exploitée et doit être priorisée pour la remédiation.

Quels langages ou plateformes sont affectés par CWE-123 ?

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

Comment puis-je prévenir CWE-123 ?

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

Comment Plexicus détecte et corrige CWE-123 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-123 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.

Où puis-je en savoir plus sur CWE-123 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/123.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Prêt à valider l'essentiel ?

Prêt à valider ce qui compte.

Plexicus est Proof-Driven AppSec : findings validés, compréhension contextuelle et remédiation relue — ancrée dans la preuve, scopée avec vous.

Qualification

Vérifiez si l'AI Swarm Pentest convient à votre environnement.

Partagez le contexte minimum. Nous vérifierons le périmètre et indiquerons la prochaine étape commerciale.

Avant d'envoyer — vérifiez que vous correspondez

0 / 280

Sans engagement. Si vous ne correspondez pas, nous vous le dirons.

SAMPLE HANDOVER · ILLUSTRATIVE

Sample evidence handover

A trimmed view of what your team receives at the end of an AI Swarm Pentest engagement. Real engagements include full technical evidence, executive narrative, and a remediation plan.

VALIDATED FINDING Evidence attached

Server-Side Request Forgery in webhooks/receiver

demo-project/sample-app · src/webhooks/receiver.py:42

SeverityHigh CVSS 3.18.6 Priority79 Confirmedvia replay

Untrusted caller-supplied URLs reach an internal egress without an allowlist. Replayed in a sandbox against a fresh authorized target — the same control was validated to fail twice.

REVIEWER-READY REMEDIATION Merge-ready PR

Validate the target URL against an allowlist of permitted hostnames. Reject private/internal IP ranges. Enforce HTTPS only.

plexicus/remediation/webhooks-ssrf 3 changed · 0 new files
42resp = requests.get(target_url)
42+if not is_allowed_host(target_url):
43+  raise WebhookRejected(target_url)
44+resp = requests.get(target_url, timeout=5)
Every engagement hands over:
  • Executive briefing
  • Validated findings list
  • Merge-ready PRs
  • Compliance mapping (NIS2 · DORA · CRA)
Tour privé Pour les investisseurs