Executar análise estática (SAST) na base de código à procura do padrão inseguro no fluxo de dados.
Improper Address Validation in IOCTL with METHOD_NEITHER I/O Control Code
This vulnerability occurs when a Windows driver defines an IOCTL using METHOD_NEITHER but fails to properly check the user-supplied memory addresses before using them.
What is CWE-781?
Real-world CVEs caused by CWE-781
-
Driver for file-sharing and messaging protocol allows attackers to execute arbitrary code.
-
Anti-virus product does not validate addresses, allowing attackers to gain SYSTEM privileges.
-
DVD software allows attackers to cause a crash.
-
Personal firewall allows attackers to gain SYSTEM privileges.
-
chain: device driver for packet-capturing software allows access to an unintended IOCTL with resultant array index error.
Trajeto do atacante passo a passo
- 1
Identificar um caminho de código que trata input não confiável sem validação.
- 2
Criar um payload que explora o comportamento inseguro — injeção, traversal, overflow ou abuso de lógica.
- 3
Entregar o payload através de um pedido normal e observar a reação da aplicação.
- 4
Iterar até que a resposta exponha dados, execute código do atacante ou escale privilégios.
Vulnerable pseudo
A MITRE não publicou um exemplo de código para este CWE. O padrão abaixo é ilustrativo — consulte os Recursos para referências canónicas.
// Example pattern — see MITRE for the canonical references.
function handleRequest(input) {
// Untrusted input flows directly into the sensitive sink.
return executeUnsafe(input);
} Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} How to prevent CWE-781
- Implementation If METHOD_NEITHER is required for the IOCTL, then ensure that all user-space addresses are properly validated before they are first accessed. The ProbeForRead and ProbeForWrite routines are available for this task. Also properly protect and manage the user-supplied buffers, since the I/O Manager does not do this when METHOD_NEITHER is being used. See References.
- Architecture and Design If possible, avoid using METHOD_NEITHER in the IOCTL and select methods that effectively control the buffer size, such as METHOD_BUFFERED, METHOD_IN_DIRECT, or METHOD_OUT_DIRECT.
- Architecture and Design / Implementation If the IOCTL is part of a driver that is only intended to be accessed by trusted users, then use proper access control for the associated device or device namespace. See References.
How to detect CWE-781
Executar testes dinâmicos de segurança de aplicações (DAST) contra o endpoint em execução.
Monitorizar os registos em tempo de execução para traços de exceção invulgares, input malformado ou tentativas de contornar a autorização.
Revisão de código: sinalizar qualquer novo código que trate input desta superfície sem usar os ajudantes validados do framework.
O Plexicus deteta automaticamente o CWE-781 e abre um PR de correção em menos de 60 segundos.
O Codex Remedium analisa cada commit, identifica esta fraqueza exata e entrega um pull request pronto para revisão com o patch. Sem tickets. Sem transferências.
Frequently asked questions
O que é o CWE-781?
This vulnerability occurs when a Windows driver defines an IOCTL using METHOD_NEITHER but fails to properly check the user-supplied memory addresses before using them.
Qual a gravidade do CWE-781?
A MITRE não publicou uma classificação de probabilidade de exploração para esta fraqueza. Trate-a como impacto médio até o seu modelo de ameaças provar o contrário.
Que linguagens ou plataformas são afetadas pelo CWE-781?
MITRE lists the following affected platforms: C, C++, Windows NT.
Como posso prevenir o CWE-781?
If METHOD_NEITHER is required for the IOCTL, then ensure that all user-space addresses are properly validated before they are first accessed. The ProbeForRead and ProbeForWrite routines are available for this task. Also properly protect and manage the user-supplied buffers, since the I/O Manager does not do this when METHOD_NEITHER is being used. See References. If possible, avoid using METHOD_NEITHER in the IOCTL and select methods that effectively control the buffer size, such as…
Como é que o Plexicus deteta e corrige o CWE-781?
O motor SAST do Plexicus correlaciona a assinatura de fluxo de dados do CWE-781 em cada commit. Quando é encontrada uma correspondência, o nosso agente Codex Remedium abre um PR de correção com o código corrigido, testes e um resumo de uma linha para o revisor.
Onde posso saber mais sobre o CWE-781?
A MITRE publica a definição canónica em https://cwe.mitre.org/data/definitions/781.html. Pode também consultar a documentação da OWASP e do NIST para orientações adjacentes.
Weaknesses related to CWE-781
Improper Validation of Specified Index, Position, or Offset in Input
This vulnerability occurs when software accepts user input to determine a location—like an array index, file position, or memory…
Improper Validation of Array Index
This vulnerability occurs when software uses unverified, external input to calculate or access an array index, without properly checking…
Untrusted Pointer Dereference
This vulnerability occurs when software takes a value from an untrusted source, treats it as a memory address (a pointer), and then…
Further reading
- MITRE — CWE-781 oficial https://cwe.mitre.org/data/definitions/781.html
- Exploiting Common Flaws in Drivers http://reversemode.com/index.php?option=com_content&task=view&id=38&Itemid=1
- Remote and Local Exploitation of Network Drivers https://www.blackhat.com/presentations/bh-usa-07/Bulygin/Presentation/bh-usa-07-bulygin.pdf
- Windows driver vulnerabilities: the METHOD_NEITHER odyssey http://www.net-security.org/dl/insecure/INSECURE-Mag-18.pdf
- Buffer Descriptions for I/O Control Codes https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/buffer-descriptions-for-i-o-control-codes
- Using Neither Buffered Nor Direct I/O https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/using-neither-buffered-nor-direct-i-o
- Securing Device Objects https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/controlling-device-access
Pare de pagar por desenvolvedor.
Comece a fechar o ciclo.
O Plexicus é o ASPM nativo de IA que verifica, filtra, corrige, pentesta e explica — de forma autónoma. Programadores ilimitados, repos ilimitados, ações de IA de utilização justa. Nível gratuito real, €269/mo anual quando estiver pronto.