Table 2: Example of information in the Operands table for
the queries in Table. 1.
CrudID Position Name Type
2 1 @CustomerId nchar(5)
2 2 @ShipCountry nvarchar(15)
the Queries table and the ’Position’ column denotes
the parameter position in the CRUD Expression that
the operand refers to and is used for performance op-
timization purposes. The ’Name’ column indicates
the name of the parameter used in the CRUD ex-
pression and the ’Type’ column indicates the operand
type, which follows the database management sys-
tem’s supported data types.
When a DIA initiates a new session with permis-
sion to use both CRUD expressions shown in Table.
1, it is assigned a random SessionID (12345678 in the
example) and the following information is appended
to the SessionQueries table:
Table 3: Example of the generated identifiers for a DIA ses-
sion in the SessionQueries table.
SessionID CrudSRID CrudRID
12345678 13572468 1
12345678 24681357 2
The information in Table. 3 shows us that the ses-
sion with the SessionID 12345678 can execute two
queries (i.e. the CRUD expressions with the CrudRID
1 and 2). Additionally, the DIA using that session has
to use the CrudSRIDs 13572468 and 24681357 to-
gether with its SessionID to execute each respective
query successfully.
5.2 RemoteCall Stored Procedure
Having the database tables created, we now require a
way to execute the queries using the SessionID and
the CrudSRID tokens. To achieve this we chose to
use a stored procedure, which we called RemoteCall.
Stored procedures are able to take parameters as in-
puts and output the result of queries back to the DIA,
which is precisely the functionality we require. Since
we have the queries stored in a table, we can eas-
ily obtain the CRUD expression too, but the question
is how to get the DBMS to execute it. The process
varies from DBMS to DBMS and it must be done
carefully. Since the CRUD expression is a simple
string, appending the parameters received and execut-
ing it without any parameter validation is dangerous
because of attacks such as SQL Injection.
The DBMS used, i.e. SQL Server 2010, offered
two options to execute queries defined in strings:
the EXEC and the sp executesql commands(IETF,
2008). The EXEC command allows executing CRUD
expressions stored in strings, but does not support
parametrization, which leaves it vulnerable to SQL
Injection attacks if used with parametrized queries.
On the other hand, the sp executesql command takes a
CRUD expression and a list of parameters. Not only
it is resilient against SQL Injection attacks by treat-
ing the parameters differently from the CRUD expres-
sion, even if they are strings themselves, but it also
enables the DBMS to perform optimizations.
The sp executesql command always receives a
statement, which is the CRUD expression to execute.
It also received two optional arguments, of which the
first contains some metadata about the parameters of
the statement to execute, i.e. their names and data
types, and the other contains the parameters’ values.
A query that selects data from a table where a column
value is less than 10 would be executed as follows:
EXEC sp executesql N’SELECT * FROM table
WHERE col > @Param’, N’@Param int’, N’@Param
= 10’;
In the example above, the query retrieved from the
Queries table remains untouched, but the other pa-
rameters still need to be created by the RemoteCall
stored procedure prior to the execution of the query
per se. The result of the RemoteCall stored procedure
is exactly the same as if the CRUD expression had
been executed, therefore no changes are required in
DIA’s source code that handles it. Hence, the Remote-
Call stored procedure requires three arguments: the
SessionID, the CrudSRID, and a string called Params,
which by default is empty and contains the values of
the parameters needed to execute the CRUD expres-
sion.
Fig. 10 shows a block diagram of the RemoteCall
stored procedure implementation. The RemoteCall
stored procedure, upon being executed, retrieves the
CrudRID associated to the SessionID and the Crud-
SRID from the SessionQueries table. This is part
of the validation process of the tokens. If the Ses-
sionID or CrudSRID are not valid, i.e. if there is no
CrudRID associated with the token pair received, the
execution ends at this point, an error raised and the
session terminated. Then it retrieves the CRUD ex-
pression to execute from the Queries table, using the
CrudRID obtained initially. Next, the parameter defi-
nition string is built from the information stored in the
Operands table. Finally, it executes the sp executesql
command with the CRUD expression retrieved, pass-
ing the parameter definition string and the parameter’s
values received from the DIA. Instead of the usual
CRUD expressions, for the DIA to pass the tokens
and the parameter values it executes the RemoteCall
stored procedure as follows:
EXEC PolicyServer2. remote.RemoteCall @Ses-
Protecting Databases from Schema Disclosure - A CRUD-Based Protection Model
299