Method for generating computer code resistant to SQL injection attacks
An AI-driven method automates the conversion of unprepared queries to prepared queries, addressing resource and complexity issues in SQL injection prevention, enhancing software security and performance.
Patent Information
- Application Number
- FR2023003484
- Authority / Receiving Office
- FR · FR
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-04-07
- Publication Date
- 2024-10-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing methods for preventing SQL injection attacks, such as filtering requests and using prepared queries, are resource-intensive, complex, and not exhaustive, while current automated solutions are cumbersome for complex and distributed software development environments.
An automated method using artificial intelligence to identify and convert unprepared queries to prepared queries within software code, involving decompression, analysis, and modification of methods in batches using a neural network or web service, ensuring secure code transfer.
Enhances software security by automatically converting unprepared queries to prepared queries, reducing vulnerabilities and improving performance without excessive resource consumption.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Title of the invention: Method for generating computer code resistant to SQL injection attacks Technical field of the invention
[0001] The present invention relates to software security and more particularly, this invention relates to comprehensive techniques for identifying software security vulnerabilities during software development, testing and deployment.
[0002] In Europe, it is estimated that 70% of computer attacks use the SQL injection method.
[0003] This is explained by the ubiquity of developments based on the SQL language. Regardless of the field of activity, most IT developments implement databases, and the most widespread computer language for manipulating data is SQL (acronym for Structured Query Language). This language is used by most IT solutions to organize the storage, manipulation and search of data. It also allows you to perform queries, update data, reorganize it, or even create and modify the schema and structure of a database system and control access to its data.
[0004] SQL is used in all areas where databases are used. In other words, it is found in virtually every area where data is generated and analyzed.
[0005] In the financial industry, banking and payment processing applications store data about financial transactions and users. These systems rely on complex databases and therefore require the use of SQL.
[0006] Similarly, music streaming applications like Spotify or Deezer make intensive use of databases, for example to store the vast catalogs of music files from different albums by different artists.
[0007] Social networks such as Facebook™ or Instagram™ use SQL language to store information about a user's profile such as their biography or geographic location. Each time a user creates a publication or shares content, SQL language allows the database to be updated.
[0008] Due to this omnipresence in most IT developments, attacks using the opportunities offered by the SQL language represent a major source of vulnerability and prized by hackers.
[0009] One of the most used methods by hackers to gain access to a Database injection is referred to as "SQL Injection." It involves inserting malicious code into an SQL query via a form or other input field in a web application, in order to obtain sensitive information or perform malicious actions on the database. The consequences can be very serious, ranging from the disclosure of confidential information to complete takeover of the database.
[0010] To combat these attacks, one solution is to filter queries by analyzing user input to verify that they match what is expected. And do not contain special characters or character sequences that could be used to inject SQL code. This filtering consumes computing resources and degrades performance, and above all is never exhaustive because the variants of sequences and characters allowing SQL injection are infinite, and excessive filtering can cause malfunctions.
[0011] Another solution is to limit user privileges based on their needs. Users should only have access to the resources they need to perform their work. This reduces the risk of SQL injection attacks. However, administering privileges is a tedious and complex task.
[0012] Another solution is to plan upstream, during the development of the application, exclusively prepared queries: Prepared queries allow to separate the data provided by the user from SQL statements. This prevents attackers from injecting malicious code into SQL queries.
[0013] A prepared query in SQL language is a method of processing queries that allows for improved performance and security of database operations.
[0014] When a query is sent to the database server, the SQL query engine must first parse the query, compile it, and execute it. With prepared statements, this step is performed only once, and the compiled query is stored in cache. Thus, when a prepared statement is executed again, the database server can simply retrieve the compiled query from cache, improving performance.
[0015] Additionally, prepared statements help to better secure database operations by preventing SQL injection attacks. This is because the query parameters are passed separately from the query itself, preventing attackers from injecting malicious SQL code into the query.
[0016] Developers may notably use database management libraries providing functions that protect against SQL injection attacks, as proposed by US patent US7653620.
[0017] To protect against SQL injection attacks, it is essential to implement secure code development practices, regularly test applications for vulnerabilities, and use SQL injection attack prevention tools.
[0018] However, information systems are becoming increasingly complex, increasingly powerful, interconnected, and freely accessible to partners and customers over widely distributed networks with largely anonymous electronic interactions. Software development itself is increasingly distributed through development agreements with independent contractors and the use of collaborative development. These trends are placing a strain on organizations' ability to secure and protect digital data from misuse or unauthorized access and to ensure that the code is free of vulnerabilities, not to mention that coding with prepared statements is tedious.
[0019] Unprepared queries can be identified by the presence of character strings containing SQL statements directly embedded in the code.
[0020] Using these methods, one can detect queries that are not prepared and implement measures to replace them with prepared queries in order to improve database performance and security. State of the art
[0021] Known in the state of the art is the article Raymond Mui et al. in "Preventing SQL injection by automatic query sanitization with ASSIST" - Electronic Proceedings in Theoretical Computer Science, vol. 35, September 17, 2010, pp27-38, which describes a method for preventing SQL injection, which is caused when a user transmits incorrect input to a database. The technique provides automatic sanitization of SQL queries through the use of static analysis and program transformation.
[0022] Also known is the article Baratloo et. Al. in "Transparent run-time defense against smashing attack" - Proceedings of the USENIX 2000 Annual Technical Conference - June 18-23, 2000 - San Diego, CA, USA, pp251-262, which describes the mitigation of attacks against process stacks with a first method that intercepts all calls to library functions known to be vulnerable and a second method uses binary modification of process memory to force verification of critical elements of the stacks before use.
[0023] Known in the state of the art is the American patent issued under number US9298924 describing a computer-implemented method for automatically correcting a security vulnerability in a source code of a computer program, the method comprising the following steps: - Identification, in a source code of a computer program, of a security vulnerability in the form of a portion of code that sends corrupted data to the corresponding receiving code in the source code; - Search for the part of code that sends the tainted data containing the instruction creation; - Search for the corresponding code that creates a query with the tainted data; - Replaced a variable in the portion of code that sends the corrupted data with a placeholder; - Replaced by a “prepareStatement” call a “createStatement” call corresponding to the portion of code which sends the tainted data; - Added a "setString" call corresponding to the portion of code that sends the tainted data; - Removed the query argument from an "execute / executeQuery" in the code portion; - Determining whether the output of the portion of code that contains the instruction creation dominates the input to the receiving code that creates the request; and - if the output does not dominate the input, automatic correction of the security vulnerability by automatically performing the code modification by performing at least one of the - Moving part of the code portion to a different location in the source code and - Copying a portion of the code to a different location in the source code as part of modifying the source code to cause the source code to sanitize corrupted data before the corrupted data reaches the corresponding receiving code.
[0024] Also known is the European patent granted under No. EP2092424 proposing a computer-implemented method for detecting security vulnerabilities in a computer program, comprising the steps of: - receiving in a memory the source code of said computer program to be analyzed, said source code comprising code elements and instructions, at least part of said instructions referencing variables, in which said variables comprise data structures having member variables, said member variables having the names of the members; - constructing, using a source code analyzer running on a processor, an object-oriented model of said source code, in which said code elements are represented by respective objects, wherein said constructing an object-oriented model includes assigning a unique instance of the identifiers for each of said member variables; and - using said model, constructing at least one control flow graph representing a flow of said computer program, - store the object-oriented model in an object-oriented database; - receive a source code database query, in a language of predefined code graph query, regarding a security vulnerability in which a member name of a predetermined member variable is identical to said member name of another member variable; - analyzing said at least one control flow graph in response to said query in the source code database in order to identify a portion of said source code having said security vulnerability by identifying references to said predetermined member variable using said unique instance identifiers thereof; and
[0025] report said security breach.
[0026] The European patent granted under number EP3049988 describes a method for automatically remedying security breaches, the method comprising the steps consisting of: - receiving, in memory, a static binary analysis report for a binary file that corresponds to an application, the report identifying a security vulnerability in a section of the binary file; - identifying, by a processor, based at least in part on the received report, the section of the binary file that corresponds to the security vulnerability, the identified section comprising a first segment of binary code that provides functionality in an insecure manner; - locating a matching binary patch that includes a second binary code segment that provides functionality in a secure manner and that matches the functionality that is provided by the first binary code segment in the identified section, within a patch library; - determining whether or not the replacement, within the binary file, of the section identified by the matching binary patch should lead to a modification at the level of a function of the binary file; - if no change in function is determined to occur, replacing the identified section of the binary file with the matching patch; and - otherwise, generating a notification that the replacement should modify the function.
[0027] Disadvantages of the prior art Statement of the invention
[0028] The present invention aims to address these drawbacks. To this end, the invention relates, in its most general scope, to a method for generating a computer development resistant to SQL injection attacks from a pre-existing development, characterized in that it comprises the following steps: a. On an application executed on a terminal, recover a .zip archive provided by the user from said pre-existing development b. Transfer of said compressed files to a shared processing server via an encrypted session c. Execution by a program installed on the server for i. Decompressing each of said files transferred into the tree structure described in the compressed file d. characterize the queries of a first file by an analyzer which consists of extracting from each of the files the methods in order to identify and characterize the queries according to whether they are already prepared statements or not, by loop processing to successively browse the successive models constituting the source code of the file being processed, and for each of the models, a nested secondary loop to successively extract and characterize all the sequences of the model being processed in the main loop, before incrementing the main loop to move on to the next model, e. The next step concerning the modification by an artificial intelligence engine of the recorded methods; consisting of constituting N batches of M methods to be processed, N being greater than 1 and NxM corresponding to the nearest integer greater than the number of methods recorded in said temporary memory: i. Parallel processing of a first batch of N methods by said artificial intelligence engine to replace the values of the method body with a prepared query explicitly defining the value and typing of each parameter of the original method ii. Replacement in said temporary file in a temporary FTM file of the contents of the original method with the contents of the method modified in the previous step iii. In the event of failure to modify, recording of the unmodified method in the said table of unprocessed methods iv. Saving a modified file from the file saved in the MTFM memory corresponding to the saved code with replacement of said markers by the new content of the methods modified during the processing step of the batch considered v. Update of the table of files processed by taking into account the timestamped methods processed in the batch considered vi. Return to the processing step for the next batch, up to the last method to be processed f. Compression of the code stored in the MTFM memory, and made available to the user via a link for secure transfer to the client terminal.
[0029] The subject matter of the present invention may also have one or a compatible combination of the following characteristics:
[0030] Said step of characterizing the requests comprises the following steps: a. Processing a first file by an analyzer to extract a first method present in said file and retrieving information comprising the start line, the end line, the name and the declaration information and the body of said method i. Syntax analysis to check if the said method contains a prepared statement 1. If the method does not contain a prepared statement, the name and declaration information are stored in a table of unprocessed methods, and return to the previous step for parsing the next method in said file 2. Failing that, scanning the entire source file, up to the start line of the method being analyzed, recording (a) in a temporary memory MTFM (temporary memory of marked files) the code preceding said start line, inserting a marker with the identification of said method in place of said first line, omitting all the code up to the end line of the method, and recording in said temporary memory, after said marker, all the rest of the code of said file in said temporary memory, and (b) recording the body of said method in a temporary file FTM with a unique name corresponding to the name of the file, the name of the method and the information defined declaration and return to the previous step for the syntactic analysis of the next method of said file.
[0031] 3. After processing all methods in a file, return to step for the analysis of the next file, up to the last file to constitute a memory containing the list of all the methods to be processed pointing to the bodies recorded in said temporary file.
[0032] Description of non-limiting examples of embodiment
[0033] The present invention will be better understood on reading the following description, concerning a non-limiting example of embodiment illustrated by the appended drawings where:
[0034] [Fig-1] [Fig.l] represents a schematic view of the hardware architecture for the automatic modification of a computer development
[0035] [Fig.2] [Fig.2] represents a Java / JDBC method before processing
[0036] [Fig.3] [Fig.3] represents a Java / JDBC method after processing by the engine artificial intelligence.
[0037] General principle of the invention
[0038] The purpose of the invention is to provide an automatic method for modifying a computer development to make it invulnerable to SQL injection attacks that affect websites exploiting databases. These attacks occur when a malicious person executes an SQL query on the database via the incoming data from the client to the server. SQL commands are inserted into the data plane entry (for example, in place of the username or password) in order to execute predefined SQL commands. A successful SQL injection exploit can read sensitive data from the database, modify (insert, update or delete) the data in the database, execute database administration operations (for example, close it), retrieve the contents of a specific file, and, in some cases, send commands to the operating system.
[0039] For example, a website's web form might ask for a user's account name and then send it to the database to retrieve the associated account information using dynamic SQL, like this:
[0040] “SELECT * FROM users WHERE account = + userProvidedAccountNumber
[0041] While this works for users who enter their account number correctly, it leaves a gap for attackers. If, for example, someone decided to provide an account number “' or '1' = '1'”, it would result in a query string like this:
[0042] “SELECT * FROM users WHERE account = '' or '1' = '1'
[0043] Since '1' = '1' always evaluates to TRUE, the database returns the data from all users instead of just one.
[0044] The vulnerability to this type of computer attack is related to the fact that SQL makes no real distinction between the control plane and the data plane. For this reason, SQL injections work especially if a website uses dynamic SQL. In addition, SQL injections are very common with PHP, Python, J2EE / JDBC and ASP.NET applications, despite the nature of programmatic interfaces that allow for the creation of prepared statements, but these interfaces are not systematically used.
[0045] In order to protect a computer development against SQL injection attacks, one solution is to exclude all procedures using a dynamic SQL type query) to use only prepared queries (parameterized queries or in English "prepared statements").
[0046] Glossary
[0047] The following terms shall have the following meaning in this patent:
[0048] “Method” means in the context of object-oriented programming (OOP), a member routine of a class, for example an instance method, acting on only one object (instance of the class) at a time or a static method or class method, independent of any instance of the class (object).
[0049] "Query" means a functional character sequence, called in English "Statement"
[0050] “memory” means a space allowing writing, modification and reading in a physical medium, for example a hard drive or flash memory.
[0051] Hardware architecture
[0052] [Fig.l] represents a schematic view of the hardware architecture of the system intended for the automatic modification of a computer development according to the invention. The user uses a computer terminal (10) which exchanges data under a secure protocol with a server (20), by Https type sessions for example. The server (20) is for example a distributed server in the cloud ("Cloud" in English), exchanging data with an artificial intelligence engine (30).
[0053] This artificial intelligence engine (30) can be constituted by a pre-trained neural network executed by the server, or an external web service which is not pre-trained.
[0054] Processing on the computer terminal (10)
[0055] The computer terminal executes a computer application (11) specific to the invention controlling the user interface to select the file (12) corresponding to the original development presenting potential security flaws by SQL Injection attack and transfer it to the processing server (20) via a secure protocol.
[0056] The original file (12) is generally a compressed file of type .zip or tar.gz which contains C++, C#, GoLang, Java, JavaScript, Python or PHP source code. Optionally, the application (11) decompresses the original file (12), checks whether the code it contains is compatible with the processing applied by the server (20), for example by a semantic analysis to check whether the computer code corresponds to a language taken into account by these processings, before recompiling the original file (12).
[0057] The original file (12) is then transferred to the software application (21), executed on the server (20) in the Cloud, via a software interface under Windows™, macOS™ and Linux™.
[0058] After processing by the server (20), the secure file (13) is transmitted to the terminal (10) and saved to allow its use instead of the original file (12).
[0059] Processing on the server (20)
[0060] The application (11) decompresses the file and extracts all the source programs to save a set of files (22) in a temporary memory of the server (20). This temporary memory will be erased at the end of the processing and after the transfer of the processed file to the terminal (10).
[0061] The application (22) then commands a succession presented below.
[0062] decomposition into methods
[0063] A first step in characterizing the queries consists of extracting the methods from each of the files in order to identify and characterize the queries according to whether they are already prepared statements or not.
[0064] This first step of characterizing the requests consists of applying loop processing to successively browse the successive models constituting the source code of the file being processed, and for each of the models, a nested secondary loop to successively extract and characterize all the sequences of the model being processed in the main loop, before incrementing the main loop to move on to the next model.
[0065] Main loop for analyzing models
[0066] In this main loop, the computer code of a file being processed is analyzed to identify patterns, i.e., portions of computer code defining a routine.
[0067] This analysis is done by a semantic analyzer of known type, to: a. recognize in the code the series of lines of code corresponding to a method and b. detect if the method being processed contains a prepared statement c. perform processing to save a record in a table EM; of an entry corresponding to the information of interest of the model considered, in particular:
[0068] - the starting line of code of said method considered
[0069] - the end code line of said method considered
[0070] - the name and declaration information and the body of said method considered
[0071] - the body of said method.
[0072] If the method being analyzed does not contain a prepared query, the name and declaration information are recorded in a table of unprocessed methods, and return to the previous step for the syntactic analysis of the next method of said file.
[0073] Secondary loop for recording requests to be processed
[0074] If the method being analyzed contains a query of a type other than a prepared query, the application commands the execution of a secondary loop, to prepare a temporary file of the marked code, corresponding to the code from which the body of the unprepared queries is extracted to replace them with a temporary marker, and a table of the bodies of the queries which will then be processed to be reintroduced into the marked body to replace these temporary markers.
[0075] This processing of the request consists of: a. isolate the part of the code before and after the body of the identified query, to record a temporary code in which the body of the query is temporarily replaced by a temporary marker MARQj allowing the subsequent reintroduction of a prepared query fulfilling the same functionalities. This marker MARQj is a sequence with the identification of the associated method. b. Furthermore, the body of this method is recorded in a temporary FTM file with a unique name corresponding to the file name, the method name and the declaration information and return to the previous step for the syntactic analysis of the next method of said file, and the link with the MARQj marker. c. Recording in a temporary memory MTFM (temporary memory of marked files) all the lines of code of the file preceding said start line followed by a marker inserted after these lines, the marker being a sequence with the identification of said method in place of said first line, omitting all the code up to the end line of the method, and recording in said temporary memory, after said marker, all the rest of the code of said file in said temporary memory MTFM (temporary memory of marked files).
[0076] We thus process recursively all the requests of a method by the loop secondary and all the methods of each of the files by the main loop.
[0077] After processing all the methods of a file, return to the step for analyzing the next file, up to the last file to constitute a memory containing the list of all the methods to be processed pointing to the bodies recorded in said temporary file.
[0078] Processing of isolated methods
[0079] The bodies of the methods to be processed recorded in the temporary file are then processed by an artificial intelligence engine to produce a file comprising the bodies of methods reconstructed in prepared query mode.
[0080] For example, a Java / JDBC method before processing illustrated by [Fig.2] would become after processing by the artificial intelligence engine a method illustrated by [Fig.3].
[0081] However, the size of the file does not allow processing of all the methods by a single processing, and the invention provides for the extraction of subsets of methods to be processed, for processing by the same artificial intelligence engine in serial-parallel mode, by N batches comprising M methods each, N and M being integers greater than 1, with NxM corresponding to the nearest integer greater than the number of methods recorded in said temporary memory such that the last processing relates to a number of methods corresponding to the rest of the methods to be processed.
[0082] The method provides: a. the parallel processing of a first batch of N methods by said artificial intelligence engine to replace the values of the body of the method with a prepared query explicitly defining the value and typing of each parameter of the original method. b. The replacement in said temporary file in a temporary FTM file of the contents of the original method by the contents of the method modified in the previous step c. In case of modification failure, recording of the unmodified method in the said table of unprocessed methods d. Saving a modified file from the file saved in the MTFM memory corresponding to the saved code with replacement of said markers by the new content of the methods modified during the processing step of the batch in question e. Updating the table of processed files by taking into account the timestamped methods processed in the batch considered f. Return to the processing step for the next batch, up to the last method to be processed.
[0083] Transfer of secure code
[0084] The modified code stored in the MTFM memory is then compressed and made available to the user via a link for secure transfer to the client terminal.
Claims
Claims
1. Method for generating a computer development resistant to SQL injection attacks from a pre-existing development characterized in that it comprises the following steps: a. On an application running on a terminal, retrieve a user-supplied .zip archive from said pre-existing development b. Transfer of said compressed files to a shared processing server via an encrypted session c. Execution by a program installed on the server for i. Decompression of each of said files transferred into the tree structure described in the compressed file a. characterize the queries of a first file by an analyzer which consists of extracting from each of the files the methods in order to identify and characterize the queries according to whether they are already prepared statements or not, by loop processing to successively browse the successive models constituting the source code of the file being processed, and for each of the models, a nested secondary loop to successively extract and characterize all the sequences of the model being processed in the main loop, before incrementing the main loop to move on to the next model, b. The next step concerning the modification by an artificial intelligence engine of the recorded methods; consisting of constituting N batches of M methods to be processed, N being greater than 1 and NxM corresponding to the nearest integer greater than the number of methods recorded in said temporary memory: i. Parallel processing of a first batch of N methods by said artificial intelligence engine to replace the values of the method body by a prepared statement explicitly defining the value and typing of each parameter of the original method ii. Replacement in said temporary file in a temporary FTM file of the contents of the original method with the contents of the method modified in the previous step iii. In the event of failure to modify, recording of the unmodified method in the said table of unprocessed methods iv. Saving a modified file from the file saved in the MTFM memory corresponding to the saved code with replacement of said markers by the new content of the methods modified during the processing step of the batch considered v. Update of the table of files processed by taking into account the timestamped methods processed in the batch considered vi. Return to the processing step for the next batch, up to the last method to be processed a. Compression of the code stored in the MTFM memory, and made available to the user via a link for secure transfer to the client terminal.
2. Method for generating a computer development resistant to SQL injection attacks from a pre-existing development according to claim 1 characterized in that said step of characterizing the requests comprises the following steps: a. Processing a first file by a parser to extract a first method present in said file and retrieving information including the start line, the end line, the name and the declaration information and the body of said method i. Syntax analysis to check if the said method contains a prepared statement 1. If the method does not contain a prepared statement, the name and declaration information are stored in a table of unprocessed methods, and return to the previous step for parsing the next method in said file 2. Failing that, scanning the entire source file, up to the start line of the method being analyzed, recording (a) in a temporary memory MTFM (temporary memory of marked files) the code preceding said start line, inserting a marker with the identification of said method in place of said first line, omitting all the code up to the end line of the method, and recording in said temporary memory, after said marker, all the rest of the code of said file in said temporary memory, and (b) recording the body of said method in a temporary file FTM with a unique name corresponding to the name of the file, the name of the method and the declaration information and returning to the previous step for the syntactic analysis of the next method of said file 3. After processing all the methods in a file, return to the step for analyzing the next file, up to the last file to create a memory containing the list of all the methods to be processed pointing to the bodies recorded in said temporary file.
Citation Information
Patent Citations
Locating security vulnerabilities in source code
EP2092424A2
A system and method for automated remedying of security vulnerabilities
EP3049988A1
Dynamic optimization of prepared statements in a statement pool
US7653620B2
Fixing security vulnerability in a source code
US9298924B2
