|
Hampi is a solver for string constraints. Hampi solves constraints that contain regular expressions and (fixed-size) context-free grammars. Example Standalone mode Server mode Input language Formal grammar Example (bounded CFG intersection) Example (bounded CFG / regexp intersection) System requirements ExampleThe following is an example Hampi constraint. The example illustrates how Hampi can be used in creating SQL injection attack strings. The constraint expresses the following: "find a 12-character string v such thatSELECT
msg FROM messages WHERE topicid='v'
is a valid SQL statement
that
contains a tautology in the OR condition".//string variable of fixed size 12 characters //simple SQL context-free grammar NOTES:
Running Hampi in standalone modePut the above constraint in a file a.hmp
and run ./hampi a.hmp Hampi outputs a result like this: {VAR(v)=b' OR '1'='1}
which means that Hampi found the value of v
that satisfies the
constraints.Running Hampi in server modeRunning Hampi in server mode improves solving time for small constraints.Run the server, (4444 is an available port on localhost), ./hampi_server.sh 4444 Run a query, ./hampi_client.sh 4444 a.hmp Shut down the server, ./hampi_client.sh 4444 SHUTDOWN Input languageA Hampi input (a Hampi constraint) consists of a variable declaration followed by a series of context-free grammar declarations, regular language declarations, temporary variables and constraints. See the formal grammar for the full description.String variableEach Hampi input must declare 1 string variable, of fixed size. The goal of Hampi is to find a string that, when assigned to the string variable, satisfies all the constraints. An example variable declaration is:var v:18; Context-free grammar declarationsContext-free grammars are defined using a notation similar to Extended Backus-Naur Form. Terminal symbols are quoted. Each nonterminal must be defined. Declarations may contain repetitions (+ and *), and options (?). Character ranges declare sets of terminals, e.g.,['a'-'z'],
and are syntactic shortcuts.Regular-expression declarationsRegular languages can be defined by regular expressions, e.g.,reg Bstar := star("b") // b*
Regular languages can also be defined by bounding context-free languages using the fix operator, e.g., cfg E := "()" | "(" E ")" | E E ; //all balanced parentheses
Temporary-variable declarationsTemporary variables are shortcuts that help to express constraints on expressions that are concatenations of the string variable and constants, e.g.,var v : 2;Now, you can put constraints on S, e.g., assert S contains ")(";
AssertionsAssertions specify membership of variables in regular languages, e.g.,assert v in R; //where R is a defined regular language Example (bounded CFG intersection)A Hampi input can declare more than one CFG, so it's easy to compute a string from a bounded intersection of two CFGs, e.g.,var v : 10;
Here is how you can find a string from the intersection of a bounded
context-free language and a regular language; |
|