[IEEE 2011 18th Working Conference on Reverse Engineering (WCRE) - Limerick, Ireland (2011.10.17-2011.10.20)] 2011 18th Working Conference on Reverse Engineering - Reverse Engineering of Protocols from Network Traces

Download [IEEE 2011 18th Working Conference on Reverse Engineering (WCRE) - Limerick, Ireland (2011.10.17-2011.10.20)] 2011 18th Working Conference on Reverse Engineering - Reverse Engineering of Protocols from Network Traces

Post on 01-Mar-2017

216 views

Category:

Documents

4 download

Embed Size (px)

TRANSCRIPT

  • Reverse Engineering of Protocols from Network Traces

    Joo Antunes Nuno Neves Paulo VerissimoLASIGE, Faculty of Sciences, University of Lisboa, Portugal

    {jantunes,nuno, pjv}@di.fc.ul.pt

    AbstractCommunication protocols determine how networkcomponents interact with each other. Therefore, the ability toderive a specification of a protocol can be useful in variouscontexts, such as to support deeper black-box testing or effectivedefense mechanisms. Unfortunately, it is often hard to obtainthe specification because systems implement closed (i.e., undoc-umented) protocols, or because a time consuming translation hasto be performed, from the textual description of the protocolto a format readable by the tools. To address these issues, wepropose a new methodology to automatically infer a specificationof a protocol from network traces, which generates automata forthe protocol language and state machine. Since our solution onlyresorts to interaction samples of the protocol, it is well-suitedto uncover the message formats and protocol states of closedprotocols and also to automate most of the process of specifyingopen protocols. The approach was implemented in a tool andexperimentally evaluated with publicly available FTP traces. Ourresults show that the inferred specification is a good approximationof the reference specification, exhibiting a high level of precisionand recall.

    I. INTRODUCTIONNetwork protocols regulate the communication among en-

    tities by defining the syntax and semantics of the messages,and the order in which they need to be exchanged. Theability to obtain a protocol specification can, therefore, playan important role in several contexts. For example, it canhelp on the implementation of effective defense mechanisms,such as firewalls and intrusion detection systems, that use thespecifications of the protocols to accurately identify malicioustraffic by performing deep packet inspection [1]. Testing toolscan take as input a protocol specification to generate test casesthat cover the protocol space for conformance testing [2] or toverify if a server is vulnerable to remote attacks [3].However, it is typically hard to produce protocol specifi-

    cations. Closed (or undocumented) protocols require reverseengineering the seemingly arbitrary set of bytes that composeeach message in order to determine their meaning and structure.Open protocols, on the other hand, are well documented andtheir (textual) specification is readily available (e.g., IETFprotocols), but obtaining their specification is also difficult andtime consuming because developers have to carefully analyzethe textual description of the protocol and translate it into theformat supported by the tools.Automatic protocol reverse engineering can address most of

    these difficulties by deducing an approximate specification of aprotocol from information about its operation and with minorassumptions about its structure. In this paper, we present amethodology for automatically inferring the language and statemachine of the protocol.This approach constructs two automata(one for the language and the other for the protocol state

    machine) from the sequences of messages and protocol sessionsthat were observed in network traces, and then, generalizesand reduces them in order to create a concise specification.The methodology can be used both to extract a specificationof closed protocols and to automate most of the manualtranslation of open protocols. Our solution is focussed on clear-text protocols, often used on network servers. By noticing thatmany of these server protocols are text-based (e.g., HTTP, SIP,IMAP, FTP, Microsoft Messenger), we decided to explore in ourapproach the way text fields are usually organized and delimitedin a message. We also include in the paper a brief discussionon how to extend the approach to binary-based protocols.The methodology was implemented in ReverX, a tool that

    infers the protocol specification from a network trace containinga sample of protocol interactions. An experimental evaluationof the tool was carried out using publicly available networktraces, to determine if an inferred specification can capturethe main characteristics of a protocol. For this experiment,we chose the FTP protocol for two main reasons. First, it isa non-trivial protocol with a reasonable level of complexitythat is well-known to most readers, and therefore, it becomessimpler to provide examples in the text. Second, since FTP isdocumented in an IETF RFC [4], it facilitates the assessmentof the results and allows an intuitive comparison between theinferred automata and the ones manually produced from thetextual description. The experiments show that the generatedautomata can recognize the FTP protocol with a high level ofprecision, recall, and f-measure, even with training sets with arelatively small number of messages (around 1000 packets).

    II. REVERX

    A protocol is a set of rules that dictates the communicationbetween two or more entities. It defines message types (orformats) that are composed of a sequence of fields organizedwith certain rules and that can take values from a given domain.Therefore, a protocol can been seen as a formal languagewhose syntax rules are specified through a grammar, describinghow symbols of an alphabet can be combined to form validwords. Grammars can be represented by deterministic FiniteState Machine (FSM) automata, which are commonly usedto describe language recognizers, i.e., computational functionsthat determine whether a sequence of symbols belongs to thelanguage. Likewise, the network protocol also identifies theorder in which the messages can be transmitted while programsexecute, and consequently, a FSM can also be utilized torepresent the relations among the different types of messages.We call this second automaton the protocol state machine. It isthus the goal of our methodology to obtain the specification of

    2011 18th Working Conference on Reverse Engineering

    1095-1350/11 $26.00 2011 IEEEDOI 10.1109/WCRE.2011.28

    169

  • Network

    Traces

    Partial

    Language

    (+ labeling)

    Sequences

    of Message

    Types

    Sessions of

    Messages

    Partial

    State

    Machine

    Protocol

    Language (Generalized)

    Protocol

    State Machine (Reduced)

    Phase 1: Protocol Language Phase 2: Protocol State Machine

    Figure 1. ReverX overview.

    the protocol by inferring two FSM, which define the languageand the state machine of the protocol.The problem of grammar inference, or automata induction,

    refers to the process of learning a language L (or obtainingthe FSM that recognizes L) from a set of sample sequences.If the sequences given to infer the language are exhaustiveand complete, constructing a FSM that accepts all sequencescan be a simple task. However, several problems arise whenthe language is complex and the alphabet is rich, such as innetwork protocols. First, if the language defines words thatcan contain arbitrary values, such a message containing severalfields for variable-data arguments, it denotes an alphabet withconsiderable size (given the combinations of possible valuesthat each field can have). Also, it is quite difficult to producea representative set of sample sequences for languages withlarge alphabets, since this would imply that one must obtain acomplete set of network traces containing all the messages ofthe protocol with all possible variations and combinations ofparameter data1. If the set of sample sequences is incomplete,the problem of grammar inference consists in generalizing fromthe given set to obtain a FSM that also accepts the missingsequences, without over-generalizing.Therefore, network protocols are characterized by complex

    languages and large alphabets, and as a result they are difficultto reverse engineer. Some solutions have nevertheless beencreated that take advantage of some particular characteristicof the network protocols [5], [6]. Some works also resortto positive and negative examples to learn a grammar froma set of sample sequences [7], [8]. Our approach resorts tonetwork traces that can be easily obtained by intercepting thecommunication between regular clients and servers and thatare expected to contain only positive examples. As in any otherlearning-based approach, the quality of the derived specificationwill depend on the correctness and coverage of the samplesequences. Therefore, the network traces should provide a goodprotocol coverage and must not have any illegal or malformedmessages (as they would introduce incorrect message formatsor corrupt existing ones). Only messages of the protocol areconsidered, therefore the traces are previously filtered to selectonly packets to and from a specific UDP/TCP port number. Inaddition, to simplify the presentation, we assume that protocolmessages are not fragmented in several packets and that noencryption is performed.Figure 1 depicts an overview of the methodology imple-

    mented in the ReverX tool. Since the parties involved in the

    1This is unreasonable to obtain, for example, in a text field with a variablesize of 1 to 256 characters, since there can be over 1089 different values.

    IP1: USER clark

    IP1: PASS kent

    IP1: QUIT

    IP2: USER bruce

    IP2: PASS wayne

    IP3: USER peter

    IP3: PASS parker

    IP3: CWD /home/peter

    IP2: CWD /home/bruce

    IP2: RNFR cave

    IP2: RNTO batcave

    IP2: QUIT

    IP3: CWD daily

    IP3: CDUP

    IP3: RNFR news

    IP3: RNTO journal

    IP3: QUIT

    IP1: USER clark

    IP1: PASS kent

    IP1: CWD /home/clark

    IP1: CDUP

    IP1: QUIT

    IP2: USER bruce

    IP2: PASS wayne

    IP2: QUIT

    Session 1

    Session 2

    Session 3

    Session 4

    Session 5

    Figure 2. Example FTP network trace.

    communication can play distinct roles (e.g., client or server),which restricts the allowed message types that each one cansend or receive, we derive separate specifications for each roleby looking at the direction of the traffic. The methodology isorganized in two phases: In the first phase, ReverX constructs aPrefix Tree Acceptor (PTA) from the protocol messages of thenetwork traces (Partial Language), which is then generalizedwith the intention of producing a FSM that can accept the samemessage types with different payloads (Protocol Language). Inthe second phase, the tool deduces the protocol state machinefrom the causal relations among the different messages presentin the network traces. ReverX extracts individual protocolsessions, which are converted into sequences of message types,to build a PTA that accepts those sessions (Partial StateMachine). The tool then resorts to a more aggressive statemerging algorithm to reduce the automaton (Protocol StateMachine).

    A. Inferring the Language

    The methodology for deriving the protocol language consistsof two parts: the construction of a FSM that accepts only themessages present in the traces, extended with frequency labels,and the generalization of the automaton to accept differentinstances of the same types of messages. The automatonL = (Q,, , , q0, F ) is defined as:Q is a finite, non-empty set of states, is the input alphabet, i.e., a finite set of fields extracted

    from all messages, is the state-transition function: : Q Q, is the labeling-transition function: : Q N,q0 is the initial state, andF is the set of final states.In this context, the alphabet of the automaton, i.e., the set

    of symbols, is the set of message field payloads observed.Transitions from a given state define the message fields thatare accepted by that state. Algorithm 1 depicts the method forobtaining the FSM that recognizes the language of the protocol.1) Construction of the Partial Language Automaton with

    Frequency Labels: A PTA is built so that it accepts every

    170

  • 1 Function inferProtocolLanguage2 Input: NetworkTraces : Messages of the protocol3 T1 : Minimum ratio of unique instances (0 T1 1)4 T2 : Minimum number of transitions (T2 > 0)5 Output: Automaton L (Q,, , , q0, F )67 q0 NewState()8 Q {q0}9 10 (q, s) UNDEFINED for all domain11 (q, s) 0 for all domain12 F 13 L (Q,, , , q0, F )1415 // Construction of the partial language (PTA)16 foreach m NetworkTraces do17 q q018 foreach m1i|m| do // for each message field19 if (q,mi) = UNDEFINED then20 p (q,mi)21 (q,mi) (q,mi) + 1 // inc. frequency22 q p23 else24 p NewState()25 Q Q {p} // add new state to Q26 {mi} // add symbol to alphabet27 (q,mi) p // add transition28 (q,mi) 1 // initial frequency label29 q p30 F F {q} // add final state3132 // generalize the automaton33 MinimizeFSM(L)34 generalized TRUE35 while generalized is TRUE do36 {ANY }37 (q, s) UNDEFINED for all domain38 (q, s) 0 for all domain39 LN (Q,, , , q0, F ) // nondeterministic FSM40 generalized FALSE41 foreach q Q do42 #transq |{(q, s) = UNDEFINED , s }|43 freqq

    s (q, s)

    44 if #transq/freqq > T1 or #transq > T2 then45 // transitions are set with symbol ANY46 foreach s : (q, s) = UNDEFINED do47 (q, ANY ) (q, ANY ) {(q, s)}48 (q, ANY ) (q, ANY ) {(q, s)}49 generalized TRUE50 else51 // transitions keep the same symbol52 foreach s : (q, s) = UNDEFINED do53 {s}54 (q, s) {(q, s)}55 (q, s) {(q, s)}56 L DeterminizeFSM(LN ) // converts to deterministic FSM57 MinimizeFSM(L)58 return L

    Algorithm 1. Infer the message formats of the protocol.

    message in the network trace (Lines 1630 in Algorithm 1).The PTA is a FSM where each common prefix of the messagesis accepted by the same states and transitions and each uniquesuffix is accepted by a branchless path in the automaton. Wecreate the PTA from the positive examples of the network traceas follows: Each network message is composed of an arbitrarysequence of bytes, however, text-based protocols usually resortto a fixed delimiter character to separate the message fields,such as a space or a tab. Therefore, by providing a regularexpression that defines the field delimiter, we decompose eachmessage as a sequence of fields and separators (abstracted inLine 18). Whenever a symbol (field payload or delimiter) isrejected by the PTA, a new set of states and transitions isadded in order to create a path that accepts the entire message.

    Furthermore, all transitions are labeled with the number oftimes they were visited (Lines 2128) to keep track of thefrequency that each payload has been observed in that potentialfield. The resulting frequency-labeled FSM is similar to aprobabilistic automaton, where instead of a probability value,each transition has associated an absolute frequency.Figure 3 displays a simple example of inferring the protocol

    message formats from a network trace of Figure 2. The tracewas obtained from five simple FTP sessions, just to elucidatethe process of deriving a protocol specification using ourmethodology. To infer the protocol language recognized bythe server, the trace was filtered so that it contains only FTPmessages sent by the client. Each message is delimited by acarriage return and a line feed characters, and each field isseparated by the space character, as specified by RFC 959 [4].Figure 3(a) shows the partial language PTA derived at the endof this phase, where and depict...

Recommended

View more >