CN114547024A - SQL statement risk detection method, device, equipment and medium - Google Patents

SQL statement risk detection method, device, equipment and medium Download PDF

Info

Publication number
CN114547024A
CN114547024A CN202210119145.8A CN202210119145A CN114547024A CN 114547024 A CN114547024 A CN 114547024A CN 202210119145 A CN202210119145 A CN 202210119145A CN 114547024 A CN114547024 A CN 114547024A
Authority
CN
China
Prior art keywords
sql statement
binary file
function
call
statement
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210119145.8A
Other languages
Chinese (zh)
Inventor
钟泽鑫
狄鹏
刘向阳
刘江潮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alipay Hangzhou Information Technology Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202210119145.8A priority Critical patent/CN114547024A/en
Publication of CN114547024A publication Critical patent/CN114547024A/en
Priority to PCT/CN2023/071226 priority patent/WO2023151436A1/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/55Detecting local intrusion or implementing counter-measures
    • G06F21/554Detecting local intrusion or implementing counter-measures involving event detection and direct action

Abstract

The embodiment discloses a risk detection method, a device, equipment and a medium for SQL sentences, wherein the risk detection method for the SQL sentences comprises the following steps: acquiring a binary file corresponding to a target object, and judging whether the binary file contains a call for a preset operation; the preset operation is an operation of deleting a data table or deleting data in the data table; if the binary file contains a call for a preset operation, judging whether an SQL statement for executing the preset operation has a conditional constraint statement; and if the SQL sentence for executing the preset operation does not have the conditional constraint sentence, judging that the SQL sentence has a risk.

Description

SQL statement risk detection method, device, equipment and medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a medium for risk detection of an SQL statement.
Background
Sql (structured Query language) is a database language with multiple functions such as data manipulation and data definition, and this language has interactive characteristics and can provide great convenience to users. Meanwhile, it is also a very important issue to improve the use security of SQL.
In view of the above, there is a need for a more efficient and effective risk detection scheme for SQL statements.
Disclosure of Invention
Embodiments of the present specification provide a method, an apparatus, a device, and a medium for risk detection of an SQL statement, so as to solve a technical problem how to perform risk detection of the SQL statement more effectively and more efficiently.
In order to solve the above technical problem, the embodiments of the present specification provide the following technical solutions:
an embodiment of the present specification provides a risk detection method for an SQL statement, including:
acquiring a binary file corresponding to a target object, and judging whether the binary file contains a call for a preset operation; the preset operation is an operation of deleting a data table or deleting data in the data table;
if the binary file contains a call for a preset operation, judging whether an SQL statement for executing the preset operation has a conditional constraint statement;
and if the SQL statement for executing the preset operation does not have the conditional constraint statement, judging that the SQL statement has risk.
An embodiment of the present specification provides an SQL statement risk detection apparatus, including:
the call analysis module is used for acquiring a binary file corresponding to the target object and judging whether the binary file contains a call to a preset operation; the preset operation is an operation of deleting a data table or deleting data in the data table;
the constraint analysis module is used for judging whether the SQL sentences used for executing the preset operation have conditional constraint sentences or not if the binary file contains calls for the preset operation;
and the risk analysis module is used for judging that the SQL statement has risk if the SQL statement for executing the preset operation does not have a conditional constraint statement.
An embodiment of the present specification provides an SQL statement risk detection device, including:
at least one processor;
and the number of the first and second groups,
a memory communicatively coupled to the at least one processor;
wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor, the instructions being executable by the at least one processor to enable the at least one processor to perform the SQL statement risk detection method described above.
Embodiments of the present specification provide a computer-readable storage medium, which stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the method for risk detection of SQL statements as described above is implemented.
The embodiment of the specification adopts at least one technical scheme which can achieve the following beneficial effects:
according to the technical scheme, the risk of the SQL statement can be detected in a static analysis mode under the condition that the program and the SQL statement are not operated, so that the risk detection effect and efficiency of the SQL statement are improved. Particularly, the technical scheme can detect whether the risk of deleting the data table or deleting the data in the data table (particularly deleting all the data in the data table) exists in the SQL sentence, and further improve the risk detection effect.
Drawings
In order to more clearly illustrate the embodiments of the present specification or the technical solutions in the prior art, the drawings used in the description of the embodiments of the present specification or the prior art will be briefly described below. It should be apparent that the drawings described below are only some of the drawings to which the embodiments described in the present specification may relate, and that other drawings may be derived from those drawings by those of ordinary skill in the art without inventive effort.
Fig. 1 is a schematic diagram of an execution subject of the SQL statement risk detection method in the first embodiment of the present specification.
Fig. 2 is a schematic flow chart of the SQL statement risk detection method in the first embodiment of the present specification.
Fig. 3 is a schematic view of an intermediate representation in the first embodiment of the present specification.
Fig. 4 is a diagram illustrating a function call diagram in the first embodiment of the present specification.
Fig. 5 is a data flow diagram in the first embodiment of the present specification.
Fig. 6 is a schematic structural diagram of an SQL statement risk detection apparatus in a second embodiment of the present specification.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present specification, the technical solutions in the embodiments of the present specification will be clearly and completely described below with reference to the drawings of the embodiments of the present specification. It is to be understood that the embodiments described herein are only some embodiments of the application and not all embodiments. All other embodiments, which can be obtained by a person skilled in the art without making any inventive step based on the embodiments of the present disclosure, shall fall within the scope of protection of the present application.
Sql (structured Query language) is a database language with multiple functions such as data manipulation and data definition, and this language has interactive characteristics and can provide great convenience to users.
However, in the conventional single system application, the call of the SQL statement can only be triggered in the system by the application itself, and cannot be triggered by an external request or an external call, so that the call of the SQL statement in the single system application is relatively controllable. As such, risk detection for SQL statements is long-term ignored.
In addition, in order to meet the needs of increasing the scale and complexity of internet services and adapting to the rapid construction and deployment of systems, the traditional single system architecture is gradually replaced by a micro-service architecture. The microservice architecture typically supports service registration as well as RPC (remote call). A single microservice application may register a service with the registry and allow other microservice applications to trigger corresponding operations using their exposed interfaces over RPC. Therefore, the call of the SQL statement can be triggered not only in the application, but also by the external application at any time through the RPC interface exposed outside by the application. It can be seen that, because there is an externally exposed interface in the micro service system, the invocation of the SQL statement becomes uncontrollable, and the risk of the SQL statement may be accompanied by the exposure of the externally exposed interface to the client.
In particular, some SQL statements have a function of deleting a data table or data of a data table in a database. Once the SQL statement is improperly called, part or all of the data in the data table or the data table may be deleted, the database may not respond to the data query request for the data table, the security and integrity of the data stored in the database may be seriously affected, and the stability and reliability of the application associated with the data table may be seriously threatened.
In addition, in the prior art, the detection of the SQL statement is usually limited to detecting common problems such as syntax of the SQL statement and SQL implantation, and cannot detect the data deletion function of the data table of the SQL statement.
A first embodiment (hereinafter, referred to as "embodiment one") of this specification provides a method for risk detection of an SQL statement, where an execution subject in the embodiment one may be a terminal (including but not limited to a mobile phone, a computer, a pad, and a television), or a server, or an operating system, or an application program, or an SQL statement risk detection platform, or an SQL statement risk detection system, and the like, that is, the execution subject may be various, and may be set, used, or transformed as needed. In addition, a third party application may assist the execution principal in executing embodiment one. For example, as shown in fig. 1, the SQL statement risk detection method in the first embodiment may be executed by a server, and an application corresponding to the server (held by a user) may be installed on a terminal (held by the user), so that data transmission may be performed between the terminal or the application and the server, and data collection or input or output or page or information processing may be performed by the terminal or the application (to the user), thereby assisting the server in executing the SQL statement risk detection method in the first embodiment.
As shown in fig. 2, a risk detection method for an SQL statement provided in an embodiment includes:
s01: the method comprises the steps that (an execution main body) a binary file corresponding to a target object is obtained, and whether the binary file contains calling of a preset operation or not is judged; the preset operation is an operation of deleting a data table or deleting data in the data table;
in one embodiment, the target object may be a variety of applications (including but not limited to applets, microserver applications).
The execution subject of the first embodiment may obtain the binary file corresponding to the target object in a suitable manner. The user may import the binary file corresponding to the target object into the execution main body of the first embodiment, or the execution main body of the first embodiment may obtain the binary file corresponding to the target object from itself or another main body according to the user operation, or the user may send the binary file corresponding to the target object to the execution main body of the first embodiment through another main body.
Generally, the binary file is a file that can be executed by a computer to provide the function of the target object. The binary file can be source code, an installation package, a jar package and the like.
After obtaining the binary file corresponding to the target object, the execution main body of the first embodiment may determine whether the binary file includes a call to a preset operation. The preset operation may be an operation of deleting a data table or deleting data in the data table.
In the first embodiment, the data table is a common form of data storage, and is an essential element constituting a database, and the definition of the data table can refer to the prior art.
In an embodiment, the determining whether the binary file includes a call to a preset operation may include:
s011: judging whether the binary file contains the call to the target SQL statement; the target SQL statement is an SQL statement used for executing preset operation;
the execution of the first embodiment may determine whether the binary file includes a call to a target SQL statement, that is, determine whether the binary file can call the target SQL statement, where the target SQL statement is an SQL statement for executing the preset operation.
In the first embodiment, the determination of whether the binary file includes the call to the target SQL statement does not require running the binary file, but instead, a static analysis manner is used to determine whether the binary file includes the call to the target SQL statement.
In an embodiment, the determining whether the binary file includes a call to a target SQL statement may include:
s0111: judging whether a function in the binary file calls a target SQL statement or not;
in the first embodiment, determining whether the function in the binary file calls the target SQL statement may include: for any function in the binary file, determining the SQL call ID (namely the ID of the called SQL statement) corresponding to the function; and positioning the SQL sentence corresponding to the SQL calling ID, and judging whether the function in the binary file calls the target SQL sentence or not according to whether the SQL sentence corresponding to the SQL calling ID is the target SQL sentence or not. That is, for any function in the binary file, if the SQL statement corresponding to the "SQL call ID corresponding to the function" is the target SQL statement, it is determined that the function calls the target SQL statement.
In order to determine whether a function in the binary file calls a target SQL statement and also determine an SQL call ID corresponding to the function, in the first embodiment, determining whether a function in the binary file calls a target SQL statement may include: establishing a database calling model, wherein the database calling model is used for representing the calling relation of the function in the binary file to the SQL statement, namely the database calling condition existing in the target object; and judging whether the function in the binary file calls a target SQL statement or not according to the database calling model (or judging the SQL calling ID corresponding to the function).
Specifically, the establishing of the database call model may include: and scanning all xml files related to orm frameworks (such as ibatis and mybatis) in the binary file, and performing table field modeling on all SQL (structured query language) contained in the xml files so as to establish a database calling model. The database call model includes one or more of:
the type of the SQL statement called in the binary file;
the SQL call ID of the SQL statement called in the binary file;
database table information corresponding to the called SQL statement in the binary file;
database field information corresponding to the called SQL statement in the binary file;
and program variable field information corresponding to the called SQL statement in the binary file.
By establishing a database call model, the association between the 'call to the SQL statement' in the binary file and the SQL statement can be established, that is, the call relationship of the function in the binary file to the SQL statement, and the association relationship between the database field in the SQL and the data variable and field in the program are established. For example, for "getSqlMapClientTemplate (),. queryForObject (" MS-LOAD-USER-DETAILS ", param)", it is recognized that the loaduserdeail function calls the SQL statement bound by "MS-LOAD-USER-DETAILS", and it is also determined that the three fields of the incoming variables id, name, email in the SQL statement originate from the local variable param in loaduserdeail, and the result of the SQL statement query is returned to the phone field and address field information that are eligible, and the information is encapsulated in the USER type object and returned to the application (i.e., the target object). That is, through the database call model, the call relationship of the function to the SQL statement can be obtained, that is, what SQL statement the function calls is determined, and the SQL call ID corresponding to the function can also be determined, so as to determine whether the function calls the target SQL statement.
In addition, the execution subject of embodiment one may create an intermediate representation of the binary file in advance, for example, as shown in fig. 3. The intermediate representation is an intermediate representation (i.e. an intermediary for translation) between the source code and the target code of the application program, and by the intermediate representation, knowledge/information and other related program behaviors and information in the application program (i.e. a target object) can be represented in the form of a graph (i.e. nodes and edges) through a corresponding algorithm, so that the program behaviors can be abstracted and understood, and efficient specified analysis and operation can be performed directly on the graph in sequence. In one embodiment, the database call model may be established via an intermediate representation and static program analysis.
In the first embodiment, if the SQL statement corresponding to the "SQL call ID corresponding to the function" is not the target SQL statement, it may be determined that the function indirectly calls the target SQL statement through the call relationship between the functions. Namely, determining whether the function in the binary file calls the target SQL statement, the method may further include: (the execution subject of embodiment one) establishing a call relationship between functions in the binary file (i.e. a mutual call relationship between functions); for any function in the binary file, determining a lower function of the function according to the call relation between the functions; the lower function of the function is the function called by the function;
if the lower function of the function calls the target SQL statement, judging that the function calls the target SQL statement. That is, for any function in the binary file, since the function calls its lower function, if the lower function of the function calls the target SQL statement, it is equivalent to the function indirectly calling the target SQL statement.
In an embodiment, establishing a call relationship between functions in the binary file may include: creating an intermediate representation of the binary file (as described above); and establishing the calling relation among the functions in the binary file by combining a static program analysis algorithm based on the intermediate representation. Specifically, the execution subject according to the first embodiment may establish a function call graph (for example, as shown in fig. 4, a node "function" in fig. 4 represents a function, and edges between nodes represent a call relation or a control dependency relation) based on the intermediate representation, so as to determine a context call relation between functions of inter-process analysis (inter-function analysis) through the function call graph, that is, a call relation between functions, and obtain a more accurate inter-function call analysis result.
The intermediate representation can be divided into linear IR (intermediate representation), graph IR and hybrid IR according to their structures, and an appropriate intermediate representation can be selected in the first embodiment.
S0113: and judging whether the binary file contains the call to the target SQL statement or not according to whether the function in the binary file calls the target SQL statement or not.
If a function in the binary file calls a target SQL statement, judging that the binary file contains the call of the target SQL statement; or, if no function calls the target SQL statement in the binary file, determining that the binary file does not include a call to the target SQL statement.
S013: and judging whether the binary file contains the call to the preset operation or not according to whether the binary file contains the call to the target SQL statement or not.
If the binary file comprises the call to the target SQL statement, judging that the binary file comprises the call to a preset operation; or, if the binary file does not contain the call to the target SQL statement, judging that the binary file does not contain the call to the preset operation.
S03: (execution subject) if the binary file contains a call to a preset operation, judging whether a SQL statement for executing the preset operation has a conditional constraint statement;
if the binary file includes a call to a preset operation, the execution subject of the first embodiment may determine whether a conditional constraint statement exists in an SQL statement (i.e., a target SQL statement) for executing the preset operation.
In the first embodiment, the association between SQL statements may be determined through the database call model, and then whether any target SQL statement has a conditional constraint statement is determined.
S05: and (executing the main body) if the SQL sentence for executing the preset operation does not have the conditional constraint sentence, judging that the SQL sentence has risk.
For any target SQL statement, if the execution subject of the first embodiment determines that the target SQL statement does not have a conditional constraint statement, the execution subject of the first embodiment determines that the target SQL statement has a risk. That is, if the target SQL statement does not have a conditional constraint statement, the target SQL statement may be called (by the target object or other application) without constraints, so as to perform a preset operation (including an operation of deleting part or all of the data in the data table), that is, the risk of the target SQL statement is a call risk. If the target SQL statement is used for executing the SQL statement of 'operation for deleting data table', the target SQL statement is called without restriction, so that the data table can be deleted; if the target SQL statement is an SQL statement for executing the "delete operation of data in the data table," the target SQL statement is called without constraints, which may result in the deletion of data in the data table (including all data in the data table).
If the target SQL statement is judged to have the conditional constraint statement, the execution subject of the first embodiment judges whether the conditional constraint statement of the target SQL statement has a permanent situation. If the conditional constraint statement of the target SQL statement is judged to have a permanent true condition, the target SQL statement can still be called without constraint, and therefore the risk of calling without constraint is generated.
In the first embodiment, the determining whether the conditional constraint statement of the target SQL statement has a permanent condition may include: and establishing a data flow relation in the binary file, and judging whether the conditional constraint statement of the target SQL statement has a permanent situation or not according to the data flow relation.
Judging whether the conditional constraint statement of the target SQL statement has a permanent condition according to the data flow relation may include: determining data flow transfer information of a database field (in the binary file) corresponding to the conditional constraint statement of the target SQL statement according to the data flow relation; judging possible assignment information of the database field according to the data flow information; judging whether the database field corresponding to the conditional constraint statement of the target SQL statement has permanent assignment or not according to the assignment information; and judging whether the conditional constraint statement of the target SQL statement has a permanent condition according to whether the database field corresponding to the conditional constraint statement of the target SQL statement has a permanent assignment. Namely, if the conditional constraint statement of the target SQL statement has permanent assignment, judging that the conditional constraint statement of the target SQL statement has permanent condition; or, if the conditional constraint statement of the target SQL statement does not have the permanent assignment, judging that the conditional constraint statement of the target SQL statement does not have the permanent condition.
In an embodiment, establishing a data flow relationship in the binary file may include: creating an intermediate representation of the binary file (as described above); establishing an inter-function call relation (namely a function call graph) in the binary file based on the intermediate representation; and establishing a data circulation relation in the binary file based on the call relation among the functions. The execution subject of the first embodiment generates a data flow transition graph (as shown in fig. 5, which illustrates a flow process of a database field x) based on the function call graph, where the data flow transition graph includes fields, nodes, and edges (i.e., data dependencies) describing data transfer relationships between the fields, and constraints (constraints) of the database field can be determined through the data flow transition graph. By solving the constraint, the data flow condition of any database field in the binary file or the target object can be determined, so that the assignment condition possibly existing in the database field is judged, and further, whether the permanent assignment (namely 1-1, a-a) exists is judged, namely, whether the permanent assignment exists is judged.
Of course, the data flow graph may be built by other data flow analysis algorithms, such as a field-based algorithm.
In one embodiment, the database call model may be used to supplement db call nodes associated with database operations on the function call graph, and may also be used to convert data flows associated with db operations on the graph using the database call model data flow.
In the first embodiment, for any function, if the function calls (including indirect call) a target SQL statement, it may be determined whether the target SQL statement called by the target has a conditional constraint statement; if the target SQL statement called by the target does not have the conditional constraint statement, the risk exists in the target SQL statement called by the target; if the target SQL statement called by the target has the conditional constraint statement, judging whether the conditional constraint statement of the target SQL statement called by the target has a permanent situation; if the conditional constraint statement of the target SQL statement called by the target has a permanent situation, the target SQL statement called by the target has the risk; or, if the conditional constraint statement of the target SQL statement called by the target does not have a permanent condition, the target SQL statement called by the target does not have the risk.
For any target SQL statement, if it is determined that the target SQL statement is at risk, the execution main body of the first embodiment may locate and highlight the target SQL statement, and may locate and highlight a function that calls the target SQL statement.
In the first embodiment, the binary file can be analyzed by static program analysis means such as syntax analysis, function call modeling, field data flow and the like without actually running the application program or the target object or the SQL statement, so as to determine whether the target SQL statement has the conditional constraint statement and whether the conditional constraint statement is possible to be solved forever, thereby accurately detecting the risk of the SQL statement, improving the risk detection effect and efficiency of the SQL statement, and ensuring the security and integrity of the data stored in the database and the reliability and stability of the target object. In this regard, all references to "invoke" above are intended to mean capable of being invoked, not actually already invoked, i.e., without actually running an application or target object or SQL statement.
In particular, the first embodiment creatively provides that whether the SQL statement has a risk of deleting the data table or deleting data in the data table (particularly deleting all data in the data table) is detected, so that the risk detection effect and the pertinence are further improved.
The SQL language and the language in the binary file (i.e., the programming language, such as the Java language) are different languages, in the first embodiment, the database call model can be used for establishing a data flow transfer diagram based on both the programming language analysis and the data call and data flow related to the programming (or Java) and the SQL language analysis and the field transfer information related to the SQL, and the database call model is further used for establishing the data flow transfer diagram.
The execution main body in the first embodiment may be a block chain node, and the intermediate representation diagram, the function call modeling, the function call diagram, the data flow transition diagram, and the like established in the first embodiment may be identified by the block chain and then stored in the same block chain node of the execution main body in the first embodiment, so that the execution main body is prevented from being tampered in the risk detection process applied to the SQL statement, and the reliability of the risk detection result is improved.
As shown in fig. 6, a second embodiment of the present disclosure provides an SQL statement risk detection apparatus corresponding to the SQL statement risk detection method according to the first embodiment, including:
the call analysis module 202 is configured to obtain a binary file corresponding to a target object, and determine whether the binary file includes a call to a preset operation; the preset operation is an operation of deleting a data table or deleting data in the data table;
a constraint analysis module 204, configured to determine whether a conditional constraint statement exists in an SQL statement used for executing a preset operation if the binary file includes a call to the preset operation;
and the risk analysis module 206 is configured to determine that the SQL statement has a risk if the SQL statement for executing the preset operation does not have a conditional constraint statement.
Optionally, the constraint analysis module 204 is configured to, if a conditional constraint statement exists in the SQL statement for executing the preset operation, determine whether the conditional constraint statement exists in a perpetuality condition;
the risk analysis module 206 is configured to determine that the SQL statement has a risk if the conditional constraint statement has a permanent true condition.
Optionally, the determining whether the binary file includes a call to a preset operation includes:
judging whether the binary file contains the call to the target SQL statement; the target SQL statement is used for executing preset operation;
and judging whether the binary file contains the call to the preset operation or not according to whether the binary file contains the call to the target SQL statement or not.
Optionally, the determining whether the binary file contains a call to the target SQL statement includes:
judging whether a function in the binary file calls a target SQL statement or not;
and judging whether the binary file contains the call to the target SQL statement or not according to whether the function in the binary file calls the target SQL statement or not.
Optionally, the determining whether the function in the binary file calls the target SQL statement includes:
for any function in the binary file, determining the SQL call ID corresponding to the function;
and judging whether the function in the binary file calls the target SQL statement or not according to whether the SQL statement corresponding to the SQL calling ID is the target SQL statement or not.
Optionally, the determining whether the function in the binary file calls the target SQL statement includes:
establishing a database calling model corresponding to the binary file, wherein the database calling model is used for representing the calling relation of the function in the binary file to the SQL statement;
and judging whether the function in the binary file calls a target SQL statement or not according to the database calling model.
Optionally, the database call model includes one or more of the following:
the type of the SQL statement called in the binary file;
the SQL call ID of the SQL statement called in the binary file;
database table information corresponding to the called SQL statement in the binary file;
database field information corresponding to the called SQL statement in the binary file;
and program variable field information corresponding to the called SQL statement in the binary file.
Optionally, the determining whether the function in the binary file calls the target SQL statement further includes:
establishing a calling relation among functions in the binary file;
for any function in the binary file, determining a lower function of the function according to the call relation among the functions; the lower function of the function is the function called by the function;
if the lower function of the function calls the target SQL statement, judging that the function calls the target SQL statement.
Optionally, the establishing of the inter-function call relationship in the binary file includes:
establishing an intermediate representation of the binary file;
and establishing an inter-function calling relationship in the binary file based on the intermediate representation.
Optionally, the determining whether the conditional constraint statement has a perpetuality condition includes:
and establishing a data flow relation in the binary file, and judging whether the conditional constraint statement has a permanent situation according to the data flow relation.
Optionally, judging whether the conditional constraint statement has a persistent condition according to the data flow relationship includes:
determining data flow information of a database field corresponding to the conditional constraint statement according to the data flow relation;
judging possible assignment information of the database field according to the data flow information;
judging whether the database field has permanent assignment according to the assignment information;
and judging whether the conditional constraint statement has a permanent true condition or not according to whether the database field has a permanent true assignment or not.
Optionally, the establishing a data flow relationship in the binary file includes:
establishing an intermediate representation of the binary file;
establishing an inter-function calling relationship in the binary file based on the intermediate representation;
and establishing a data circulation relation in the binary file based on the call relation among the functions.
Optionally, the risk existing in the SQL statement is a call risk.
Optionally, the risk analysis module 206 is configured to, if it is determined that the SQL statement has a risk, position and highlight the SQL statement having the risk.
A third embodiment of the present specification provides an SQL statement risk detection device, including:
at least one processor;
and the number of the first and second groups,
a memory communicatively coupled to the at least one processor;
wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the SQL statement risk detection method according to the first embodiment.
A fourth embodiment of the present specification provides a computer-readable storage medium, where computer-executable instructions are stored, and when executed by a processor, implement the SQL statement risk detection method according to the first embodiment.
The above embodiments may be used in combination, and the modules having the same name between different embodiments or within the same embodiment may be the same or different modules.
While certain embodiments of the present disclosure have been described above, other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily have to be in the particular order shown or in sequential order to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, device, and non-volatile computer-readable storage medium embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and in relation to the description, reference may be made to some portions of the description of the method embodiments.
The apparatus, the device, the nonvolatile computer readable storage medium, and the method provided in the embodiments of the present specification correspond to each other, and therefore, the apparatus, the device, and the nonvolatile computer storage medium also have similar advantageous technical effects to the corresponding method.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually making an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Hardware Description Language), traffic, pl (core universal Programming Language), HDCal (jhdware Description Language), lang, Lola, HDL, laspam, hardward Description Language (vhr Description Language), vhal (Hardware Description Language), and vhigh-Language, which are currently used in most common. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be regarded as a hardware component and the means for performing the various functions included therein may also be regarded as structures within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functions of the various elements may be implemented in the same one or more software and/or hardware implementations of the present description.
As will be appreciated by one skilled in the art, the present specification embodiments may be provided as a method, system, or computer program product. Accordingly, embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
The description has been presented with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the description. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices, or any other non-transmission medium which can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
This description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present specification, and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement or the like made within the spirit and principle of the present application shall be included in the scope of the claims of the present application.

Claims (17)

1. A risk detection method for SQL sentences comprises the following steps:
acquiring a binary file corresponding to a target object, and judging whether the binary file contains a call for a preset operation; the preset operation is an operation of deleting a data table or deleting data in the data table;
if the binary file contains a call for a preset operation, judging whether an SQL statement for executing the preset operation has a conditional constraint statement;
and if the SQL statement for executing the preset operation does not have the conditional constraint statement, judging that the SQL statement has risk.
2. The method of claim 1, further comprising:
if the SQL sentence for executing the preset operation has the conditional constraint sentence, judging whether the conditional constraint sentence has a permanent condition;
and if so, judging that the SQL statement has risks.
3. The method of claim 1, determining whether the binary file contains a call for a preset operation, comprising:
judging whether the binary file contains the call to the target SQL statement; the target SQL statement is used for executing preset operation;
and judging whether the binary file contains the call to the preset operation or not according to whether the binary file contains the call to the target SQL statement or not.
4. The method of claim 3, determining whether the binary file contains a call to a target SQL statement, comprising:
judging whether a function in the binary file calls a target SQL statement or not;
and judging whether the binary file contains the call to the target SQL statement or not according to whether the function in the binary file calls the target SQL statement or not.
5. The method of claim 4, determining whether a function in the binary file calls a target SQL statement, comprising:
for any function in the binary file, determining the SQL call ID corresponding to the function;
and judging whether the function in the binary file calls the target SQL statement or not according to whether the SQL statement corresponding to the SQL calling ID is the target SQL statement or not.
6. The method of claim 4, determining whether a function in the binary file calls a target SQL statement, comprising:
establishing a database calling model corresponding to the binary file, wherein the database calling model is used for representing the calling relation of the function in the binary file to the SQL statement;
and judging whether the function in the binary file calls a target SQL statement or not according to the database calling model.
7. The method of claim 6, the database call model comprising one or more of:
the type of the SQL statement called in the binary file;
the SQL call ID of the SQL statement called in the binary file;
database table information corresponding to the called SQL statement in the binary file;
database field information corresponding to the called SQL statement in the binary file;
and program variable field information corresponding to the called SQL statement in the binary file.
8. The method of any of claims 1-7, determining whether a function in the binary file calls a target SQL statement, further comprising:
establishing a calling relation among functions in the binary file;
for any function in the binary file, determining a lower function of the function according to the call relation between the functions; the lower function of the function is the function called by the function;
if the lower function of the function calls the target SQL statement, judging that the function calls the target SQL statement.
9. The method of claim 8, establishing inter-function call relationships in the binary file, comprising:
establishing an intermediate representation of the binary file;
and establishing an inter-function calling relationship in the binary file based on the intermediate representation.
10. The method of claim 2, determining whether the conditionally constrained statement has a perpetual condition, comprising:
and establishing a data flow relation in the binary file, and judging whether the conditional constraint statement has a permanent situation according to the data flow relation.
11. The method of claim 10, determining whether the conditionally constrained statement has a plausible condition according to the data flow relationship, comprising:
determining data flow information of a database field corresponding to the conditional constraint statement according to the data flow relation;
judging possible assignment information of the database field according to the data flow information;
judging whether the database field has permanent assignment according to the assignment information;
and judging whether the conditional constraint statement has a permanent true condition or not according to whether the database field has a permanent true assignment or not.
12. The method of claim 10 or 11, establishing a data flow relationship in the binary file, comprising:
establishing an intermediate representation of the binary file;
establishing an inter-function calling relationship in the binary file based on the intermediate representation;
and establishing a data circulation relation in the binary file based on the call relation among the functions.
13. The method of claim 1 or 2, wherein the risk of the SQL statement is a call risk.
14. The method of claim 1 or 2, further comprising:
if the SQL statement is judged to have risk, the SQL statement with the risk is positioned and highlighted; or, positioning and highlighting the function calling the SQL statement with the risk.
15. An SQL statement risk detection device comprises:
the call analysis module is used for acquiring a binary file corresponding to the target object and judging whether the binary file contains a call to a preset operation; the preset operation is an operation of deleting a data table or deleting data in the data table;
the constraint analysis module is used for judging whether the SQL sentences used for executing the preset operation have conditional constraint sentences or not if the binary file contains calls for the preset operation;
and the risk analysis module is used for judging that the SQL statement has risk if the SQL statement for executing the preset operation does not have a conditional constraint statement.
16. An SQL statement risk detection device comprises:
at least one processor;
and the number of the first and second groups,
a memory communicatively coupled to the at least one processor;
wherein, the first and the second end of the pipe are connected with each other,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the SQL statement risk detection method of any of claims 1 to 14.
17. A computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the SQL statement risk detection method of any of claims 1-14.
CN202210119145.8A 2022-02-08 2022-02-08 SQL statement risk detection method, device, equipment and medium Pending CN114547024A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202210119145.8A CN114547024A (en) 2022-02-08 2022-02-08 SQL statement risk detection method, device, equipment and medium
PCT/CN2023/071226 WO2023151436A1 (en) 2022-02-08 2023-01-09 Sql statement risk detection

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210119145.8A CN114547024A (en) 2022-02-08 2022-02-08 SQL statement risk detection method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN114547024A true CN114547024A (en) 2022-05-27

Family

ID=81673061

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210119145.8A Pending CN114547024A (en) 2022-02-08 2022-02-08 SQL statement risk detection method, device, equipment and medium

Country Status (2)

Country Link
CN (1) CN114547024A (en)
WO (1) WO2023151436A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115729530A (en) * 2022-11-22 2023-03-03 壹沓科技(上海)有限公司 Cross-system logic statement generation method, device, storage medium and equipment
WO2023151436A1 (en) * 2022-02-08 2023-08-17 支付宝(杭州)信息技术有限公司 Sql statement risk detection

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117591542B (en) * 2024-01-18 2024-03-22 准检河北检测技术服务有限公司 Intelligent detection method for database software data security

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160004517A1 (en) * 2014-07-01 2016-01-07 Bank Of America Corporation SOFTWARE DEVELOPMENT IMPROVEMENT TOOL - iREVIEW
CN110795450A (en) * 2019-09-12 2020-02-14 连连银通电子支付有限公司 SQL processing method and device
CN112395305B (en) * 2020-11-11 2024-04-16 中国人寿保险股份有限公司 SQL sentence analysis method and device, electronic equipment and storage medium
CN113722347A (en) * 2021-02-10 2021-11-30 京东数字科技控股股份有限公司 Database management method and device, electronic equipment and storage medium
CN113792340B (en) * 2021-09-09 2023-09-05 烽火通信科技股份有限公司 Method and device for auditing logical logs of database
CN114547024A (en) * 2022-02-08 2022-05-27 支付宝(杭州)信息技术有限公司 SQL statement risk detection method, device, equipment and medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023151436A1 (en) * 2022-02-08 2023-08-17 支付宝(杭州)信息技术有限公司 Sql statement risk detection
CN115729530A (en) * 2022-11-22 2023-03-03 壹沓科技(上海)有限公司 Cross-system logic statement generation method, device, storage medium and equipment
CN115729530B (en) * 2022-11-22 2023-07-04 壹沓科技(上海)有限公司 Cross-system logic statement generation method, device, storage medium and equipment

Also Published As

Publication number Publication date
WO2023151436A1 (en) 2023-08-17

Similar Documents

Publication Publication Date Title
CN107545030B (en) Method, device and equipment for processing data blood relationship
CN114547024A (en) SQL statement risk detection method, device, equipment and medium
CN107045438B (en) Application top view processing method, device and component
CN110245468B (en) Compiling method, compiling device, compiling equipment and compiling system
CN109947643B (en) A/B test-based experimental scheme configuration method, device and equipment
CN111400681B (en) Data authority processing method, device and equipment
CN107479868B (en) Interface loading method, device and equipment
CN107038058B (en) Code processing method and device
US9454382B2 (en) Verification of UML state machines
CN109284222B (en) Software unit, project testing method, device and equipment in data processing system
CN110941443B (en) Method and device for modifying file name in SDK (software development kit) and electronic equipment
CN116402165B (en) Operator detection method and device, storage medium and electronic equipment
CN113556260A (en) Flow monitoring method and device, storage medium and electronic equipment
CN111797387A (en) Method and device for intercepting plug-in
CN111078435A (en) Service processing method and device and electronic equipment
CN115934161A (en) Code change influence analysis method, device and equipment
CN109032572B (en) Method for Java program method internal connection based on byte code
CN107239270B (en) Code processing method and device
CN114064114A (en) Dynamic library generation method and device
CN109947420B (en) Method for realizing shortcut key mechanism of code editor and electronic equipment
CN113176988A (en) Data recording method and device
CN112925527B (en) Calling method, calling device, storage medium and electronic equipment
CN110688430A (en) Method and device for obtaining data bypass and electronic equipment
CN111090425B (en) Program packaging method and device and electronic equipment
CN116432185B (en) Abnormality detection method and device, readable storage medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination