The present invention relates to a software protection improvement, and more particularly related to a method and a system for hardening of control flow graph flattening.
In a Control Flow Graph (CFG) representing software, the nodes are some pieces of code called basic blocks; and edges correspond to jumps between basic blocks. A basic block (BB) has only one entry point and one exit point. There is no jump instruction to a destination anywhere in the program within a basic block; and only the last instruction can jump to another basic block. This representation is very useful to understand a program.
CFG flattening is an obfuscation transformation to increase the complexity of the code. The goal of CFG flattening is to hide the original layout of the CFG. To implement this, the program is modified in a way that each basic block jumps to a single function that computes the address of the next basic block.
This technique has been presented by Wang, C., Davidson, J., Hill, J., & Knight, J. (2001, July), Protection of software-based survivability mechanisms, In Dependable Systems and Networks, 2001. DSN 2001, International Conference on (pp. 193-202). IEEE. Usually using dynamic analysis it is quite easy to rebuild the original control flow graph. Indeed, it is possible to trace one or several executions of the protected software. Then an attacker sees that some Basic Blocks marked using their address are always executed after some others. Thus the attacker is able to rebuild the corresponding part of the CFG. This technique just allows rebuilding the part of the CFG that is executed using the parameters chosen by the attacker; however this is often enough to rebuild the interesting part of the CFG. There is therefore a need to prevent such an attacker from marking the basic blocks.
Another problem to solve is to resist to more advanced pattern matching attacks. Usually attackers use the start address of a basic block to mark them. Experimented hackers may find other techniques, like the signature of the basic block (ex: sha1). A problem to solve then is to use basic blocks that dynamically change in position and in content to resist to all kind of pattern matching.
According to an aspect of the present invention, it is provided a method for hardening of control flow graph flattening, wherein each Basic Block is stored on a slot and jumps to a single function that computes the address of the next Basic Block, comprising the steps of: each time after executing a Basic Block, copying the Basic Block at a start offset selected in an available slot; inserting at least one junk code at least one of before, after and inside the Basic Block on the basis of a reference image of the Basic Block; and updating a database including a current address and image of each Basic Block.
In a first preferred embodiment, the available slot and the start offset are selected randomly.
In a second preferred embodiment, the available slot and the start offset are selected on the basis of the database further including a list of possible successors.
In a third preferred embodiment, the reference image of the Basic Block is included in the database or computed on the basis of the current image of the Basic Block.
In a fourth preferred embodiment, a dispatcher, which is connected to all other Basic Blocks, jumps to any address between 0 and the start offset of a target slot when a Basic Block is executed.
According to an aspect of the present invention, it is provided a computer program product downloadable from a communication network and/or recorded on a medium readable by computer and/or executable by a processor, comprising program code instructions for implementing the steps of foregoing method.
According to an aspect of the present invention, it is provided non-transitory computer-readable medium comprising a computer program product recorded thereon and capable of being run by a processor, including program code instructions for implementing the steps of foregoing method.
According to another aspect of the present invention, it is provided a system for hardening of control flow graph flattening comprising a processor to implement the steps of: each time after executing a Basic Block, copying the Basic Block at a start offset selected in an available slot; inserting at least one junk code at least one of before, after and inside the Basic Block on the basis of a reference image of the Basic Block; and updating a database including a current address and image of each Basic Block, wherein each Basic Block is stored on a slot and jumps to a single function that computes the address of the next Basic Block.
In a first preferred embodiment, the available slot and the start offset are selected randomly.
In a second preferred embodiment, the available slot and the start offset are selected on the basis of the database further including a list of possible successors.
In a third preferred embodiment, the reference image of the Basic Block is included in the database or computed on the basis of the current image of the Basic Block.
In a fourth preferred embodiment, a dispatcher, which is connected to all other Basic Blocks, jumps to any address between 0 and the start offset of a target slot when a Basic Block is executed.
It is to be understood that more aspects and advantages of the invention will be found in the following detailed description of the present invention.
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, will be used to illustrate an embodiment of the invention, as explained by the description. The invention is not limited to the embodiment.
In the drawings:
In the following description, various aspects of an embodiment of the present invention will be described. For the purpose of explanation, specific configurations and details are set forth in order to provide a thorough understanding. However, it will also be apparent to one skilled in the art that the present invention may be implemented without the specific details present herein.
As described above,
The available slot and the random start offset, the junk code, and the position of the junk code may be selected on the basis of a database. They are also determined by computing according to a function or an algorithm stored on the database. In the step of inserting, some junk codes are also inserted inside the BB, in order to change its signature and detectability as shown in
It is important for a central actor to keep track of BB relocations. The central actor must store the address of each BB, e.g. its slot number and its offset inside the slot. A simple way to implement this protection is to use a data base containing for each BB its current address and the list of possible successors. The database also contains a reference image of the BB for next transformations, or a function or an algorithm to compute a reference image from the current BB image. One solution is to store in the database the address of dummy code insertions done on the reference image.
On the diagram, the top level BB that is connected to all others BBs is called a Dispatcher. Once a BB is executed, the database is updated and the Dispatcher is called. The next time when the dispatcher needs to execute the same BB, it can retrieve from the database its new address. When a Dispatcher jumps to a relocated BB, it can jump to any address in the first dummy code area, before the start of the BB. To implement that, it picks a random value between [0, Offset k] where Offset k is the relative offset of the BB in the target slot.
A number of implementations have been described. Nevertheless, it will be understood that various modifications may be made. For example, elements of different implementations may be combined, supplemented, modified, or removed to produce other implementations. Additionally, one of ordinary skill will understand that other structures and processes may be substituted for those disclosed and the resulting implementations will perform at least substantially the same function(s), in at least substantially the same way(s), to achieve at least substantially the same result(s) as the implementations disclosed. Accordingly, these and other implementations are contemplated by this application and are within the scope of the invention as defined by the appended claims.
Number | Date | Country | Kind |
---|---|---|---|
14305278.5 | Feb 2014 | EP | regional |