Research and Implementation of SQL Injection Prevention Method Based on ISR
Research and Implementation of SQL Injection Prevention Method Based on ISR
1154
Authorized licensed use limited to: Don Bosco Institute of Technology-Bengaluru. Downloaded on March 17,2025 at 07:13:29 UTC from IEEE Xplore. Restrictions apply.
completely transparent, the application is only connected to commands, or modification the original SQL command
the listener port of Proxy MySQL. request and submit the modified data packet to the server, or
b) Introduction of Lua return error message to the client.
When the server execute the SQL command and get the
Lua is an embedded, lightweight, fast, powerful scripting
results, the results will forward to MySQL proxy, at the same
language. Now the Lua language are widely apply to various
time, read_queryJesuit 0 function is called, the results will
fields, especially the fields of requiring an extensibility,
be processed through the Lua script, then return to the client.
portability and efficient script language, the Lua language
When the client needs to close the connection, the
will be the best choice, such as game development,
disconnect_client 0 function will be called, in this function,
independent application scripts, system security, expansion
MySQL Proxy can choose to close the current connection of
application fields .
the server, and can also put the connection to connection
Lua language script is very easy to be called by C/C++
pool.
code, and can also call the function of C/C++, which makes
Lua widely used in applications. Lua language and C d) The implement of DBMS proxy
language are very easy to integrate with each other, which MySQL Proxy as an agent, working between the Web
has brought a lot of benefits. Because Lua is a lightweight client and the database server, and are transparent to both.
scripting language, it does not have the good aspects of the C When MySQL proxy works, first accept client requests as
language, for example, C language has superb performance, the identity of the server, analysis and processing these
has a strong ability of the operating with the bottom of requests according to the configuration of for, then
system and a strong third party software interface, and so on. forwarding the request to the corresponding backend
Lua language can use the powerful features of the C database server as the identity of the client, finally accept the
language to complete these tasks, and Lua language has the server information and return to the client, so MySQL proxy
characteristics which C language is not good at, such as need to simultaneously achieve client and server protocol.
dynamic structure, no redundancy, simple testing and Because need to analysis the SQL statement sending from
debugging. the client, it also need to include a SQL parser. It can be said
Lua language, in addition to an extensible language, is a that MySQL Proxy is equivalent to a lightweight MySQL.
"glue language". Lua is a language based on components. MySQL proxy sits between the Web server and database
This feature can create new applications through the server as shown in Fig. 2, it can monitor and analyze or
adhesive of high-level components. These components can change the communication between them, when the MySQL
be written in other languages, or they can be compiled. Lua proxy works, it first acts as a server, receives the instructions
language can play the role of glue in the organization and from web server (as a client), analyze and process them
connection of each component. Generally speaking, the according to the configuration, then act as a client , send the
component represents a more specific and more low-level instruct to the backend database, and fmally accept the
concept, and the programmer can hardly modifY them in the results from the database, transmit to the web server.
process of program development. And in the final program
these components will occupy a large amount of CPU time,
connect_serverO
but Lua language can bind these components together to I I connect
connect
build an application. The difference between Lua language
and other "glue language" is that Lua's function is quite
complete, so that it can be used not only to agglutinate
components, but also can be used to the adapt and transform
components, even can construct a new component.
c) Execution process of Lua script in MySQL proxy Query result Query result
Every time when the client connects to the MySQL Figure 2. The main part of MYSQL Proxy
Proxy, the function connect_serverO will be called. The
function of connect_server 0 can decide whether to use a MySQL proxy's core functions are connect_serverO,
new connection, or the connection in the connection pool of read_queryO and read_queryJesultO, connect_serverO
MySQL Proxy . transmit the connection request, read_queryO transmit the
In the process of senting the initial handshake SQL statements, read_queryJesultO transmit the query
information to the server, the read_handshake 0 function results. So in order to realize the detection of SQL injection
will be called. When the client sends an authentication attack and derandomization of SQL statement, the SQL
package (including user name, password, etc.) to the backend statement should be intercepted before forwarding to
server, read_auth 0 will be called. MYSQL, which need rewrite the read_queryO. In MySQL
When the client sends SQL command requests to the proxy, we can modifY the startup configuration file mysql
MySQL proxy, read_queryO function will be called, by proxy.cnf to rewrite read_queryO, we should add the
using this function can increase the request of SQL following configuration items:
1155
Authorized licensed use limited to: Don Bosco Institute of Technology-Bengaluru. Downloaded on March 17,2025 at 07:13:29 UTC from IEEE Xplore. Restrictions apply.
the SQL injection prevention method based on ISR, we use
proxy-address = 192.168.1.1:4040
SQL injection testing tool sqlmap to detect the SQL injection
proxy-Iua-script C:/MySQLlmysql-proxy-
attacks. Due to the presence of the defense system, sqlmap
0.8.5/share/doc/mysql-proxy/suiji.lua
can not detect the SQL injection vulnerability in the 3 web
proxy-skip-profiling = true
applications.
proxy-backend-addresses=192.168.1.1:3306
Table I lists the page response time of non-protect system
and protected system, we can see that the defense system
The configuration item "proxy-lua-script" describe the only increase by about Is of additional processing time,
script file the proxy server will execute, in the script file, we which is in the scope of user can accept.
can rewrite read_query 0 function, adding the function of
TABLE I. THE PAGE RESPONSE TIME OF NON-PROTECT SYSTEM AND
SQL injection attack detection and the randomization, the
PROTECTED SYSTEM
main process is as follows:
page response time page response time
Gets the parameter packet Object of test -
(no protect) (protect by ISR)
of the read_query, which is
DVWA Web 703ms 1610ms
the SQL statement to be
BBSXP7. 3 1000ms 2003ms
processed
PHP-Nuke CMS 903ms I 580ms
V. CONCLUDTON
�:z;:�,-----
--- ----,
standard SQL keyword
ontains in pack t
SQL injection attacks
.IS detected
In this paper, we propose a method of preventing SQL
injection attacks by ISR (Instruction Set Randomization),
and build a prototype system based on this strategy. The
prototype system randomizes the SQL keywords in the
N application, because the SQL statement injected by the
attacker are not randomized , so the SQL injection can be
Get the system time T, key K, calculate
the random key MDS(T, K)mod 1000,
easily detected. Experimental results show that this system
remove the random key in the packet, has a good effect on preventing SQL injection and low
restore to the standard SQL running cost.
The defense prototype system is implemented in the form
of intermediate agent. In the case of the random key does not
add the modified packet leak, it is very difficult for the attacker to make a successful
into the proxy server's
SQL injection, and because of the secret key can be defmed
query queue
by the user, the brute force is also very difficult for attacker.
In the initial application of some practical projects, the
Figure 3. The function of MYSQL Proxy
defense system has a good effect of defending SQL injection
The example code of SQL injection attack detection is attacks, and has a practical value.
below:
REFERENCES
pos = string.find(pocket,"or") [I] Boyd S W, Kc G S, Locasto ME, et al. On the general applicability of
if pos then b = pocket.sub(strl,a+2,a+4) instruction set randomization. IEEE Transactions on Dependable and
Secure Computing, 2008, 7(3):225-270.
if b �= key then
[2] Zhao Wenlong, Zhu Junhu, Wang Qingxian. Analysis and Prevention
proxy.response.type = of SQL Injection. Computer engineering and design, 2006, 27(2).
proxy.MYSQLD]ACKET_ERR V. Benjamin Liv shits, Monica S. L am. Finding security vulner
[3]
proxy.response.errmsg = "SQL injection" abilities in Java applications with static analysis. Proceedings of the
return proxy.PROXY_SEND_RESULT 14th conference on USENIX Security Symposium Volume 14, U.S. A:
U SENIX Associatio n, 2005.
end
end [4] Yichen Xie, Alex Aiken. Static detection of securit y vulnerabilities
in scripting languages. Proceedings of the 15th conference on
USENIX Security Symposium. U. S.A: USENIX Association, 2006,
IV. THE PERFORMANCE ANALYSIS OF PROTOTYPE IS.
1156
Authorized licensed use limited to: Don Bosco Institute of Technology-Bengaluru. Downloaded on March 17,2025 at 07:13:29 UTC from IEEE Xplore. Restrictions apply.