Error handling method and device for PHP samples running in PHP sandbox
By collecting and modifying the errors of PHP programs, the detection interruption problem of PHP samples when running in the sandbox is solved, and the complete detection of PHP samples is achieved.
Patent Information
- Application Number
- CN202111614573.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2041-12-27
AI Technical Summary
When detecting PHP samples, existing dynamic detection technology is easy to cause operation errors and cause detection interruptions, resulting in missed reports due to the flexible PHP writing method and the difference in versions.
By collecting errors in PHP programs at runtime, designing corresponding modification methods, including version incompatibility errors and code logic errors, modifying PHP programs so that they can continue to run in the sandbox.
Ensure that the PHP samples can run in full in the sandbox, avoid detection interruptions, and improve detection coverage of PHP webshell.
Smart Images

Figure CN114462036B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network security, and in particular to an error handling method and device for PHP samples running in a PHP sandbox. Background Art
[0002] Existing dynamic detection technology is to run the target sample, track the behavior and actions of the sample during operation, and finally make a judgment on whether the sample is malicious based on a comprehensive analysis of the collected information.
[0003] Because PHP is very flexible and has incompatible version differences, the complete code logic implementation of a sample is diverse and complex. Even key points such as function names and variable values can be controlled by external input and may require a specific version of the language environment. This causes runtime errors when detecting target samples based on existing dynamic detection technology, resulting in detection interruptions and missed reports. Summary of the Invention
[0004] The present invention provides an error handling method and device for PHP samples running in a PHP sandbox, which are used to solve the defect in the prior art that the PHP sample stops running when the PHP program reports an error. It can ensure the running of sample data in the PHP program and facilitate comprehensive detection of PHP samples.
[0005] In a first aspect, an embodiment of the present invention provides an error handling method for a PHP sample running in a PHP sandbox, wherein the PHP sample is run by a PHP program, and the PHP program and the PHP sample exist in the PHP sandbox, comprising: if the PHP sample encounters an error during execution, collecting errors prompted by the PHP program; modifying the PHP program based on the collected errors to obtain a modified PHP program, so that the PHP sample running in the PHP sandbox based on the modified PHP program will not generate errors.
[0006] Furthermore, modifying the PHP program according to the collected errors includes: designing a modification method corresponding to the error according to the collected errors, the modification method including a modification method for version incompatibility errors or a modification method for code logic errors; and modifying the PHP program according to the modification method.
[0007] Furthermore, the modifying the PHP program according to the modification method includes: if the modification method is the modification method of the version incompatibility error, modifying the PHP program according to the modification method of the version incompatibility error.
[0008] Furthermore, the modifying the PHP program according to the modification method includes: if the modification method is the method for modifying the code logic error, modifying the code of the PHP program according to the method for modifying the code logic error.
[0009] Furthermore, if the modification method is the modification method for the version incompatibility error, the PHP program is modified according to the modification method for the version incompatibility error, including: if the modification method is the modification method for the version incompatibility error, the error targeted by the modification method for the version incompatibility error is that the function is not defined, and the function corresponding to the compatible version of the PHP program is obtained; according to the function corresponding to the compatible version of the PHP program, the function of the PHP program with the error of function not defined is redefined.
[0010] Furthermore, if the modification method is the modification method of the version incompatibility error, the function of the PHP program is modified according to the modification method of the version incompatibility error, including: if the modification method is the modification method of the version incompatibility error, the error targeted by the modification method of the version incompatibility error is undefined syntax usage, and the syntax usage of the compatible version of the PHP program is obtained; according to the syntax usage of the compatible version of the PHP program, the syntax usage of the PHP program with the error of undefined syntax usage is redefined.
[0011] Furthermore, if the modification method is the method for modifying the code logic error, the code of the PHP program is modified according to the method for modifying the code logic error, including: if the modification method is the method for modifying the code logic error, the error targeted by the method for modifying the code logic error is a code logic error, determining the code of the logic error in the PHP program; and replacing the code of the logic error according to the custom code.
[0012] In a second aspect, the present invention also provides an error handling device for a PHP sample running in a PHP sandbox, wherein the PHP sample is run by a PHP program, and the PHP program and the PHP sample exist in the PHP sandbox, comprising: a collection module for collecting errors prompted by the PHP program if an error is encountered during the running of the PHP sample; a modification module for modifying the PHP program according to the collected errors to obtain a modified PHP program, so that the PHP sample running in the PHP sandbox based on the modified PHP program will not generate errors.
[0013] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the error handling method for PHP samples running in a PHP sandbox as described in the first aspect are implemented.
[0014] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the error handling method for a PHP sample running in a PHP sandbox as described in the first aspect.
[0015] In a fifth aspect, an embodiment of the present invention further provides a computer program product having PHP instructions stored thereon, which, when executed by a processor, enables the processor to implement the steps of the error handling method for PHP samples running in a PHP sandbox as described in the first aspect.
[0016] The embodiments of the present invention provide an error handling method and device for PHP samples running in a PHP sandbox. If a PHP sample encounters an error during execution, the method collects errors prompted by the PHP program. The PHP program is modified based on the collected errors to obtain a modified PHP program, so that the PHP sample running in the PHP sandbox based on the modified PHP program will not generate errors. The PHP program is modified based on the collected errors to obtain a modified PHP program, so that the PHP sample can be fully run by the modified PHP program. Based on the designed and implemented PHP sandbox, the method adds sample execution error handling capabilities to avoid missed detections caused by the cessation of PHP sample execution, thereby achieving the purpose of detecting as many PHP webshells as possible. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 A flowchart of an embodiment of an error handling method for a PHP sample running in a PHP sandbox provided by the present invention;
[0019] Figure 2 A flow chart of an embodiment of a method for modifying a PHP program provided by the present invention;
[0020] Figure 3A flow chart of an embodiment of a method for modifying a function of a PHP program provided by the present invention;
[0021] Figure 4 A schematic diagram of an error example provided by the present invention;
[0022] Figure 5 A schematic flow chart of another embodiment of a method for modifying a function of a PHP program provided by the present invention;
[0023] Figure 6 A schematic diagram of another error example provided by the present invention;
[0024] Figure 7 A flow chart of an embodiment of a method for modifying the code of a PHP program provided by the present invention;
[0025] Figure 8 A schematic diagram of another error example provided by the present invention;
[0026] Figure 9 A flow chart illustrating another embodiment of an error handling method for a PHP sample running in a PHP sandbox provided by the present invention;
[0027] Figure 10 A flowchart of another embodiment of an error handling method for a PHP sample running in a PHP sandbox provided by the present invention;
[0028] Figure 11 A flowchart of another embodiment of an error handling method for PHP samples running in a PHP sandbox provided by the present invention;
[0029] Figure 12 A flowchart of an error handling method for a PHP sample running in a PHP sandbox provided by the present invention;
[0030] Figure 13 A schematic diagram of the structure of an embodiment of an error handling device for PHP samples running in a PHP sandbox provided by the present invention;
[0031] Figure 14 The following is a schematic diagram of the physical structure of an electronic device. DETAILED DESCRIPTION
[0032] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.
[0033] Figure 1 The present invention provides a flow chart of an embodiment of a method for handling errors in PHP samples running in a PHP sandbox. Figure 1 As shown, the PHP sample is run by a PHP program, and the PHP program and the PHP sample exist in a PHP sandbox. The error handling method for the PHP sample run in the PHP sandbox may include the following steps:
[0034] S101: If an error occurs during the execution of the PHP sample, the error prompted by the PHP program is collected.
[0035] In step 101, a sandbox, also known as a sandbox, is a virtual system program that allows browsers or other programs to be run in a sandbox environment, so that changes made during operation can be subsequently deleted. It creates an independent operating environment similar to a sandbox, in which programs running within it cannot have a permanent impact on the hard disk. In network security, a sandbox refers to a tool used to test the behavior of untrusted files or applications in an isolated environment. Classic sandbox systems are generally implemented by intercepting system calls, monitoring program behavior, and then controlling and restricting the program's use of computer resources based on user-defined policies, such as rewriting the registry and reading and writing disks.
[0036] PHP stands for Hypertext Preprocessor (PHP). PHP is an HTML-embedded language. It's similar to Microsoft's ASP, both being server-side scripting languages embedded within HTML documents. Its C-like syntax makes it widely used by many web programmers. PHP's unique syntax blends C, Java, Perl, and its own innovative syntax. It can execute dynamic web pages much faster than CGI or Perl.
[0037] A PHP sandbox is a PHP environment that can dynamically execute PHP samples with restricted permissions. It identifies malicious parts of PHP samples by running them. The malicious parts of the identified PHP samples are called "PHP webshells" - a type of malicious PHP script that integrates multiple functions such as file management and command execution.
[0038] When a PHP sample encounters an error while being run by a PHP program, the PHP program will prompt the error and the developer will collect the error.
[0039] S102, modifying the PHP program according to the collected errors to obtain a modified PHP program, so that the PHP sample running based on the modified PHP program in the PHP sandbox will not generate errors.
[0040] In step S102, the developer can modify the PHP program based on the errors prompted to ensure that the PHP sample can continue to run in the PHP program. The modifications to the PHP program may include modifications to the PHP program code or to functions within the PHP program. The modifications are determined by the collected errors, which is not limited in the present embodiment.
[0041] An embodiment of the present invention provides an error handling method for PHP samples running in a PHP sandbox. If a PHP sample encounters an error during execution, the method collects errors prompted by the PHP program. The method then modifies the PHP program based on the collected errors to obtain a modified PHP program, ensuring that the PHP sample running in the PHP sandbox based on the modified PHP program does not generate errors. The method also modifies the PHP program based on the collected errors to obtain a modified PHP program, ensuring that the PHP sample can be fully executed by the modified PHP program. Based on the designed and implemented PHP sandbox, a sample execution error handling capability is added to the sandbox to avoid missed detections caused by detection interruptions caused by the PHP sample ceasing to run, thereby achieving the goal of detecting as many PHP webshells as possible.
[0042] Figure 2 This is a flow chart of an embodiment of a method for modifying a PHP program provided by the present invention. Figure 2 As shown, the method for modifying the PHP program may include the following steps:
[0043] S201, designing corresponding error correction methods based on the collected errors, wherein the correction methods include correction methods for version incompatibility errors or correction methods for code logic errors.
[0044] S202: Modify the PHP program according to the modification method.
[0045] In steps S201 and S202, the developer designs corresponding correction methods for the errors prompted by the collected PHP programs. Among them, the correction methods are divided into two categories: one is the correction method for version incompatibility errors, and the other is the correction method for code logic errors.
[0046] The method for modifying a PHP program provided by an embodiment of the present invention can design a corresponding modification method based on the collected errors, and modify the PHP program according to the modification method corresponding to the errors, thereby ensuring that the errors are modified correctly and in a timely manner.
[0047] In some optional embodiments, modifying the PHP program according to the modification method may include: if the modification method is a modification method for a version incompatibility error, modifying the PHP program according to the modification method for the version incompatibility error. Modifying the PHP program may include redefining undefined functions or redefining undefined syntax usage, which is not limited in the embodiments of the present invention.
[0048] Modifying the PHP program according to the modification method may further include: if the modification method is a method for modifying a code logic error, modifying the code of the PHP program according to the method for modifying a code logic error. Modifying the PHP code may include replacing the code of the PHP program, which is not limited in the embodiment of the present invention.
[0049] In the embodiment provided by the present invention, the PHP program is modified accordingly according to different modification methods, which can ensure that errors are correctly corrected and the PHP sample continues to run.
[0050] Figure 3 The present invention provides a flow chart of a method for modifying a function of a PHP program. Figure 3 As shown, the method for modifying the function of the PHP program may include the following steps:
[0051] S301: If the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for a version incompatibility error is that the function is undefined, obtain a function corresponding to a compatible version of the PHP program.
[0052] S302: Redefine the function of the PHP program with the undefined function error according to the function of the compatible version of the PHP program.
[0053] In step S301 and step S302, the modification method is a modification method for version incompatibility errors. The error corresponding to this method is that the function is not defined. The corresponding function of the compatible version of the PHP program is obtained, and the function of the PHP program with the error of undefined function is redefined according to the corresponding function of the compatible version of the PHP program.
[0054] by Figure 4 The above steps are explained as an example. Figure 4As shown, the PHP7 program reports an error and prompts that the functions mysql_connect() and mysql_query() are not defined in the PHP7 program, while the above functions mysql_connect() and mysql_query() are used in the PHP5 program. Therefore, obtain the functions mysql_connect() and mysql_query() in the PHP5 program and redefine them in the PHP7 program.
[0055] The method for modifying the function of a PHP program provided in an embodiment of the present invention redefines the function of a PHP program with an error of undefined function by using the function of a compatible version of the PHP program. The PHP program with an error of undefined function can be modified, so that the PHP sample in the PHP program with an error of undefined function can continue to run.
[0056] Figure 5 The following is a flow chart of another embodiment of a method for modifying a function of a PHP program provided by the present invention. Figure 5 As shown, the method for modifying the function of the PHP program may include the following steps:
[0057] S501: If the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for the version incompatibility error is undefined syntax usage, obtain the syntax usage of the compatible version of the PHP program.
[0058] S502: Redefine the syntax usage of the PHP program with the syntax usage undefined error according to the syntax usage of the compatible version of the PHP program.
[0059] In step S501 and step S502, if the modification method is a modification method for version incompatibility error, the modification method for version incompatibility error targets an error of undefined syntax usage, obtains the corresponding syntax usage of the compatible version of the PHP program, and redefines the syntax usage of the PHP program with the undefined error according to the corresponding syntax usage of the compatible version of the PHP program.
[0060] by Figure 6 The above steps are explained as an example. Figure 6 As shown, PHP 7 does not support the " / e" mode of the grep_replace function, while PHP 5 allows this syntax usage. Therefore, the code definition of the " / e" mode syntax usage of the grep_replace function in the PHP 5 program is obtained and the above syntax usage is redefined in the PHP 7 program.
[0061] The method for modifying the functions of a PHP program provided in an embodiment of the present invention redefines the syntax usage of a PHP program with an error of undefined syntax usage through the syntax usage of a compatible version of the PHP program, and can modify the PHP program with an error of undefined syntax usage, so that the PHP sample in the PHP program with an error of undefined syntax usage continues to run.
[0062] Figure 7 The present invention provides a method for modifying the code of a PHP program. Figure 7 As shown, the method for modifying the code of the PHP program may include the following steps:
[0063] S701: If the modification method is a method for modifying a code logic error, and the error targeted by the method for modifying a code logic error is a code logic error, determine the code of the logic error in the PHP program.
[0064] S702: Replace the logic error code according to the custom code.
[0065] In step S701 and step S702, if the modification method is a method for modifying code logic errors, the error targeted by the method for modifying code logic errors is a code logic error, and the code and location of the logic error in the PHP program are determined. You can customize the code without logic errors and replace the code with the customized code.
[0066] by Figure 8 The above steps are explained as an example. Figure 8 As shown, the malicious code in line 6, the eval() function, is executed after the test() function in line 4. Running this PHP sample normally will generate a "Call to undefined function test()" error on line 4 and stop execution. If the PHP sample stops running, the sandbox cannot detect the malicious code in line 6, resulting in the threat in the PHP sample being missed.
[0067] When modifying the PHP program code, the PHP sample will indicate a logic error. Identify the logically incorrect code in the PHP program and replace it with custom code. This allows the PHP sample to continue running, and the sandbox can detect the malicious code on line 6.
[0068] The present invention provides a method for modifying the code of a PHP program. By replacing the logically erroneous code with a custom code, the method can ensure the continued operation of the PHP sample and facilitate comprehensive detection of the PHP sample.
[0069] Figure 9This is a flow chart of another embodiment of an error handling method for PHP samples running in a PHP sandbox provided by the present invention. Figure 9 The error handling method for the PHP sample running in the PHP sandbox may include the following steps:
[0070] S901: If an error occurs during the execution of the PHP sample, the error message prompted by the PHP program is collected.
[0071] The detailed description of step S901 is given in step S101 and will not be repeated here.
[0072] S902: If the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for a version incompatibility error is that the function is undefined, obtain the function corresponding to the compatible version of the PHP program.
[0073] The detailed description of step S902 is given in step S301 and will not be repeated here.
[0074] S903: Redefine the function of the PHP program with the undefined function error according to the function of the compatible version of the PHP program.
[0075] The detailed description of step S903 is given in step S302 and will not be repeated here.
[0076] Figure 10 This is a flow chart of another embodiment of an error handling method for PHP samples running in a PHP sandbox provided by the present invention. Figure 10 The error handling method for the PHP sample running in the PHP sandbox may include the following steps:
[0077] S1001: If an error occurs during the execution of the PHP sample, the error message prompted by the PHP program is collected.
[0078] The detailed description of step S1001 can be found in step S101 and will not be repeated here.
[0079] S1002: If the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for the version incompatibility error is undefined syntax usage, obtain the syntax usage of the compatible version of the PHP program.
[0080] The detailed description of step S1002 is given in step S501 and will not be repeated here.
[0081] S1003, redefine the syntax usage of the PHP program with the syntax usage undefined error according to the syntax usage of the compatible version of the PHP program.
[0082] The detailed description of step S1003 is given in step S502 and will not be repeated here.
[0083] Figure 11 This is a flow chart of another embodiment of an error handling method for PHP samples running in a PHP sandbox provided by the present invention. Figure 11 The error handling method for the PHP sample running in the PHP sandbox may include the following steps:
[0084] S1101: If an error occurs during the execution of the PHP sample, the error prompted by the PHP program is collected.
[0085] For detailed description of step S1101, please refer to step S101, which will not be repeated here.
[0086] S1102: If the modification method is a method for modifying a code logic error, and the error targeted by the method for modifying a code logic error is a code logic error, determine the code of the logic error in the PHP program.
[0087] The detailed description of step S1102 is given in step S601 and will not be repeated here.
[0088] S1103: Replace the logic error code according to the custom code.
[0089] The detailed description of step S1103 is given in step S602 and will not be repeated here.
[0090] Figure 12 The present invention provides a flow chart of an error handling method for a PHP sample running in a PHP sandbox. Figure 12 As shown, the PHP program runs in a sandbox, the PHP sample runs in the PHP program, and the sandbox performs threat detection on the running PHP sample. The error handling method for the PHP sample running in the PHP sandbox may include the following steps:
[0091] When a PHP sample encounters an error during runtime, the PHP program reports an error, and the developer modifies the PHP program according to the corresponding modification method. The modification method for version compatibility errors involves modifying functions within the PHP program's kernel, re-implementing them, and allowing the PHP sample to continue running. The modification method for logical code errors involves replacing the logically incorrect code within the PHP program, allowing the PHP sample to continue running.
[0092] Figure 13 This is a schematic diagram of the structure of an embodiment of an error handling device for PHP samples running in a PHP sandbox provided by the present invention. Figure 13As shown, the PHP sample is run by a PHP program. The PHP program and the PHP sample exist in a PHP sandbox. The error handling device for the PHP sample run in the PHP sandbox includes:
[0093] The acquisition module 1301 is used to collect errors prompted by the PHP program if an error occurs during the execution of the PHP sample;
[0094] The modification module 1302 is used to modify the PHP program according to the collected errors to obtain a modified PHP program so that the PHP sample running based on the modified PHP program in the PHP sandbox will not generate errors.
[0095] Optionally, the modification module 1302 includes:
[0096] An acquisition unit is used to design corresponding error correction methods based on the collected errors, including correction methods for version incompatibility errors or code logic errors;
[0097] The modification unit is used to modify the PHP program according to the modification method.
[0098] Optionally, the modification unit includes:
[0099] The modification subunit is used to modify the PHP program according to the modification method of the version incompatibility error if the modification method is the modification method of the version incompatibility error.
[0100] Optionally, the modification subunit is further used to modify the code of the PHP program according to the modification method for code logic errors if the modification method is a modification method for code logic errors.
[0101] Optionally, modify the subunits, including:
[0102] The first acquisition subunit is used to acquire a function corresponding to a compatible version of the PHP program if the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for the version incompatibility error is that the function is undefined;
[0103] The first modifying subunit is used to redefine the function of the PHP program with the error of undefined function according to the function corresponding to the compatible version of the PHP program.
[0104] Optionally, the modification subunit further includes:
[0105] The second acquisition subunit is used to acquire the syntax usage of the compatible version of the PHP program if the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for the version incompatibility error is undefined syntax usage;
[0106] The second modification subunit is used to redefine the syntax usage of the PHP program with the error of undefined syntax usage according to the syntax usage of the compatible version of the PHP program.
[0107] Optionally, the modification subunit further includes:
[0108] The third acquiring subunit is configured to, if the modification method is a method for modifying a code logic error, and the error targeted by the method for modifying a code logic error is a code logic error, determine the code of the logic error in the PHP program;
[0109] The third modification subunit is used to replace the code with logical errors according to the custom code.
[0110] Figure 14 An example of a physical structure diagram of an electronic device is shown below. Figure 14 As shown, the electronic device may include: a processor 1401, a communications interface 1402, a memory 1403, and a communications bus 1404, wherein the processor 1401, the communications interface 1402, and the memory 1403 communicate with each other via the communications bus 1404. The processor 1401 may call the logic instructions in the memory 1403 to execute the following method: if an error is encountered during the execution of the PHP sample, the error prompted by the PHP program is collected; the PHP program is modified based on the collected errors to obtain a modified PHP program, so that the PHP sample running in the PHP sandbox based on the modified PHP program will not generate errors.
[0111] In addition, the logic instructions in the above-mentioned memory 1403 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0112] On the other hand, an embodiment of the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the error handling method for PHP samples running in a PHP sandbox provided in the above embodiments, for example, including: if an error is encountered during the operation of the PHP sample, errors prompted by the PHP program are collected; the PHP program is modified according to the collected errors to obtain a modified PHP program, so that the PHP sample running in the PHP sandbox based on the modified PHP program will not generate errors.
[0113] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the error handling method for PHP samples running in a PHP sandbox provided in the above-mentioned embodiments, for example, including: if an error is encountered during the operation of the PHP sample, errors prompted by the PHP program are collected; the PHP program is modified according to the collected errors to obtain a modified PHP program, so that the PHP sample running in the PHP sandbox based on the modified PHP program will not generate errors.
[0114] The device embodiments described above are merely illustrative. Modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical modules, i.e., they may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0115] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus the necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or certain parts of the embodiment.
[0116] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. An error handling method for a PHP sample running in a PHP sandbox, wherein the PHP sample is run by a PHP program, and the PHP program and the PHP sample exist in the PHP sandbox, characterized in that: include: If the PHP sample encounters an error during execution, collect the error prompted by the PHP program; Modifying the PHP program according to the collected errors to obtain a modified PHP program, so that the PHP sample running based on the modified PHP program in the PHP sandbox will not generate errors; The modifying of the PHP program according to the collected errors includes: Designing corresponding correction methods based on the collected errors, including correction methods for version incompatibility errors or code logic errors; Modify the PHP program according to the modification method; The step of modifying the PHP program according to the modification method includes: If the modification method is the modification method for the version incompatibility error, modify the PHP program according to the modification method for the version incompatibility error; If the modification method is the modification method for the version incompatibility error, modifying the PHP program according to the modification method for the version incompatibility error includes: If the modification method is a method for modifying a version incompatibility error, and the error targeted by the modification method is that the function is undefined, obtain the function corresponding to the compatible version of the PHP program; Redefine the function of the PHP program with the error of "undefined function" according to the function corresponding to the compatible version of the PHP program; The step of modifying the PHP program according to the modification method includes: If the modification method is the method for modifying the code logic error, modify the code of the PHP program according to the method for modifying the code logic error; If the modification method is the modification method for the version incompatibility error, modifying the PHP program according to the modification method for the version incompatibility error includes: If the modification method is a method for modifying a version incompatibility error, and the error targeted by the modification method is that the syntax usage is undefined, obtain the syntax usage of the compatible version of the PHP program; According to the grammatical usage of the compatible version of the PHP program, the grammatical usage of the PHP program with the error of undefined grammatical usage is redefined.
2. The error handling method for PHP samples running in a PHP sandbox according to claim 1, characterized in that: If the modification method is the method for modifying the code logic error, modifying the code of the PHP program according to the method for modifying the code logic error includes: If the modification method is a method for modifying a code logic error, and the error targeted by the modification method is a code logic error, determining the code of the logic error in the PHP program; Replace the code with the logical error with the custom code.
3. An error handling device for a PHP sample running in a PHP sandbox, wherein the PHP sample is run by a PHP program, and the PHP program and the PHP sample exist in the PHP sandbox, characterized in that: include: A collection module, configured to collect errors prompted by the PHP program if an error is encountered during the execution of the PHP sample; A modification module, configured to modify the PHP program according to the collected errors to obtain a modified PHP program, so that the PHP sample running based on the modified PHP program in the PHP sandbox will not generate errors; The modification module includes: An acquisition unit is used to design corresponding error correction methods based on the collected errors, including correction methods for version incompatibility errors or code logic errors; A modification unit, used for modifying the PHP program according to the modification method; The modification unit includes: a modification subunit, which is used to modify the PHP program according to the modification method of the version incompatibility error if the modification method is a modification method of the version incompatibility error; The modification subunit includes: The first acquisition subunit is used to acquire a function corresponding to a compatible version of the PHP program if the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for the version incompatibility error is that the function is undefined; The first modifying subunit is used to redefine the function of the PHP program with the error of "function not defined" according to the function corresponding to the compatible version of the PHP program; The modification subunit is further configured to modify the code of the PHP program according to the modification method for the code logic error if the modification method is a modification method for the code logic error; The modification subunit further includes: The second acquisition subunit is used to acquire the syntax usage of the compatible version of the PHP program if the modification method is a modification method for a version incompatibility error, and the error targeted by the modification method for the version incompatibility error is undefined syntax usage; The second modification subunit is used to redefine the syntax usage of the PHP program with the error of undefined syntax usage according to the syntax usage of the compatible version of the PHP program.
4. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the error handling method for a PHP sample running in a PHP sandbox are implemented as described in any one of claims 1 to 2.
5. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the error handling method for a PHP sample running in a PHP sandbox are implemented as described in any one of claims 1 to 2.
6. A computer program product having executable instructions stored thereon, characterized in that: When the instruction is executed by the processor, the processor implements the steps of the error handling method for PHP samples running in a PHP sandbox as described in any one of claims 1 to 2.
Citation Information
Patent Citations
Test method and device for application programs
CN103377120A
Backdoor detection method and device, electronic equipment and medium
CN112182561A