2 research outputs found
A language-theoretic view on network protocols
Input validation is the first line of defense against malformed or malicious inputs. It is therefore critical that the validator (which is often part of the parser) is free of bugs. To build dependable input validators, we propose using parser generators for context-free languages. In the context of network protocols, various works have pointed at context-free languages as falling short to specify precisely or concisely common idioms found in protocols. We review those assessments and perform a rigorous, language-theoretic analysis of several common protocol idioms. We then demonstrate the practical value of our findings by developing a modular, robust, and efficient input validator for HTTP relying on context-free grammars and regular expressions
Languages and Security
Los analizadores sintácticos están presentes en la mayorÃa de los
sistemas informáticos y suponen una pieza fundamental en el proceso de
tratamiento de los datos entrantes. Al mismo tiempo, constituyen el punto de
entrada para muchos ataques pues, a menudo, estos analizadores son capaces
de procesar lenguajes mucho más expresivos de lo requerido por el protocolo
en cuestión. Al ser más complejos de lo requerido, mayor es la probabilidad de
contener errores que den lugar a importantes vulnerabilidades.
Para lidiar con este problema se han desarrollado diversas herramientas que
permiten la generación automática de estos analizadores para determinados tipos
de lenguajes. Este es el caso de Bison, que permite generar analizadores sintácticos
para lenguajes LALR(1); y ANTLR, para lenguajes LL(*). Sin embargo, estos
programas también permiten al usuario introducir código arbitrario como método
para aumentar la capacidad del analizador y es aquà donde surgen la mayorÃa de
las vulnerabilidades.
En ocasiones, este incremento de la capacidad del analizador podrÃa evitarse
llevando a cabo pequeñas modificaciones en el protocolo. En otros casos la
capacidad del lenguaje es suficiente y es la falta de conocimientos formales la que
lleva a una extensión innecesaria (y contraproducente desde el punto de vista de la
seguridad) de la capacidad del analizador.
Este es el caso de algunos aspectos comunes de los protocolos de red como
secuencias de datos cuya longitud viene indicada previamente o campos que
I
emplean un delimitador definido en otro. Sorprendentemente, para muchos de
estos aspectos, la literatura contiene aseveraciones vagas o incluso contradictorias
acerca de la capacidad requerida por parte del analizador.
En este documento afrontamos este problema desde el punto de vista de la
teorÃa de lenguajes formales. Definiremos lÃmites a nivel formal sobre la capacidad
requerida para analizar determinados lenguajes estableciendo asà el punto de
partida para futuras investigaciones. Los resultados positivos aportados están
respaldados por la implementación, empleando Flex y Bison, de un analizador
sintáctico para el protocolo HTTP, que será descrito al final de este trabajo.Parsers are a fundamental building block in the data processing
pipeline of software systems. At the same time, they are also an important entry
point for attacks, which is attributed to the fact that, very often, these parsers
are able to process languages that are more expressive than what is required by
the protocol. Since they are more complex than needed then the probability of
containing errors, which lead to important vulnerabilities, increases.
As an attempt of solving this problem tools for generating such parsers,
for certain languages, have been developed. This is the case of Bison, which
allows to generate parser for LALR(1) languages; and ANTLR, for LL(*) ones.
However, these programs allow the user to introduce handwritten code as a
mechanism to augment the capabilities of the parser and it is here where most of
the vulnerabilities rely on.
Sometimes, this increment of the parser’s capabilities could be avoided by
making small changes in the protocol. Others, the parser is already able to parse
the protocol and it is the lack of formal knowledge which leads to a unnecessary
(and counterproductive from the point of view of security) increase of the parser’s
capabilities.
This is the case of some common features in network protocols such as content
length fields or dynamically defined delimiters. Surprisingly, for a number of
idioms that are common in network protocols, the literature contains vague or
contradictory statements about what that required expressiveness would be.
In this document we approach this question from the point of view of formal
language theory, laying a foundation for further research on the parsing problem.
The positive results given on this work are backed up by the implementation of a
HTTP parser, using Flex and Bison, described at the end of this paper