Disclosure of Invention
The invention solves the problems in the prior art, and provides an optimized WEB backdoor detection device and method based on RCE loopholes, which are used for detecting whether a website has a remote code execution loophole or not, acquiring a webpage file source code of the website by utilizing the loophole and executing the code, and detecting the WEB backdoor by characteristic matching.
The invention adopts the technical scheme that a WEB backdoor detection method based on RCE vulnerability comprises the following steps:
step 1: initializing, collecting characteristics, and processing to obtain a characteristic library;
step 2: starting the device and issuing the task;
and step 3: executing a task, performing vulnerability identification, and detecting a WEB backdoor;
and 4, step 4: and outputting a detection result.
Preferably, in step 1, the feature collection and processing to obtain the feature library includes the following steps:
step 1.1: downloading known WEB backdoor source codes, and adding the collected source codes into a source code feature matching set A;
step 1.2: acquiring a known RCE vulnerability, and adding the known RCE vulnerability into a vulnerability library B;
step 1.3: acquiring corresponding vulnerability Poc based on the RCE vulnerability, and generating a vulnerability Poc library C;
step 1.4: formulating a corresponding vulnerability Ext based on the RCE vulnerability and the corresponding vulnerability Poc, and generating a vulnerability Ext library D;
step 1.5: and adding a matching rule based on the RCE vulnerability to form a fingerprint rule base E.
Preferably, in step 2, the task is a URL connection of the normalized website.
Preferably, in step 2, the task is text input or file input.
Preferably, the step 3 comprises the steps of:
step 3.1: calling a fingerprint rule base E to identify the task;
step 3.2: matching the RCE loopholes Poc corresponding to the identified fingerprints, if the matching is successful, performing the next step, otherwise, judging that the RCE loopholes Poc are not WEB backdoors, and performing the step 4;
step 3.3: executing the vulnerability Poc, if judging that the vulnerability exists, performing the next step, otherwise, judging that the vulnerability does not exist, and performing the step 4;
step 3.4: matching the identified fingerprints with corresponding vulnerability Ext, executing the vulnerability Ext, and acquiring source codes of all webpages of the task;
step 3.5: carrying out feature recognition on any source code by using the source code feature matching set A, if the recognition is successful, judging the source code as a WEB backdoor, and outputting, otherwise, discarding a page corresponding to the current source code; and (4) until the source codes of all the web pages of the task are identified.
Preferably, in step 3.1, the identifying comprises the steps of:
step 3.1.1: accessing a website corresponding to the task to obtain a response message;
step 3.1.2: constructing response message characteristics F based on server field characteristics, X-Powered-By field characteristics and page related characteristics pages in the response message, and matching the response message characteristics F with a fingerprint rule base E;
step 3.1.3: and if the E is matched with the F, and the E belongs to the E and the F belongs to the F, judging that the website fingerprint of the task is the fingerprint corresponding to the E.
A detection device adopting the RCE vulnerability-based WEB backdoor detection method comprises the following steps:
the characteristic collection module is used for collecting the existing WEB backgate source codes and RCE code execution vulnerabilities Poc and vulnerabilities Ext and corresponding fingerprint characteristics to construct a characteristic library;
the task receiving module is used for receiving webpage information needing to detect a WEB backdoor;
the task execution module is used for carrying out WEB backdoor detection on the basis of the feature library of the feature collection module and the webpage information received by the task receiving module;
and the result output module is used for receiving and outputting the feedback result of the task execution module.
Preferably, the task execution module includes:
the detection module is used for carrying out fingerprint identification and vulnerability detection on the received task;
and the characteristic identification module is used for finding out a source file matched with the webpage corresponding to the task and outputting a file path.
Preferably, the detection module comprises:
the fingerprint identification module is used for accessing the URL of the website to acquire page resources and carrying out fingerprint identification based on the characteristic matching of the Http response message;
the loophole detection module is used for finding out Poc of the corresponding REC loophole through the identified fingerprint and verifying the Poc;
and the vulnerability utilization module is used for executing the corresponding vulnerability Ext aiming at the vulnerability and obtaining all source files and paths of the website.
The invention relates to an optimized WEB backdoor detection device and a detection method based on RCE loopholes.
By utilizing RCE loopholes, the invention can remotely detect the directory tree of the website and the source files of all the webpage files, and then carry out feature recognition on the webpage and detect the WEB backdoor existing in an isolated chain, thereby realizing the remote static detection of the WEB backdoor of the website and the searching and killing.
Detailed Description
The present invention is described in further detail with reference to the following examples, but the scope of the present invention is not limited thereto.
The invention relates to a WEB backdoor detection method based on RCE vulnerabilities, which comprises the following steps.
Step 1: initializing, collecting the characteristics, and processing to obtain a characteristic library.
In the step 1, the characteristic collection and processing to obtain the characteristic library comprises the following steps:
step 1.1: downloading known WEB backdoor source codes, and adding the collected source codes into a source code feature matching set A;
step 1.2: acquiring a known RCE vulnerability, and adding the known RCE vulnerability into a vulnerability library B;
step 1.3: acquiring corresponding vulnerability Poc based on the RCE vulnerability, and generating a vulnerability Poc library C;
step 1.4: formulating a corresponding vulnerability Ext based on the RCE vulnerability and the corresponding vulnerability Poc, and generating a vulnerability Ext library D;
step 1.5: and adding a matching rule based on the RCE vulnerability to form a fingerprint rule base E.
In the invention, a source code feature matching set A refers to a WEB backdoor feature library, and is used for collecting published webpage source codes of a WEB backdoor and generating a source code feature library for file feature matching; generally, the WEB backdoor source code can be downloaded from a related forum, or downloaded from a related code hosting platform of an open source, such as a github website, searching for a "WEB backdoor", and downloading the WEB backdoor source code.
In the invention, the remote code execution vulnerability refers to website software defects, and an attacker can construct an attack packet remote execution code; the remote command execution vulnerability means that an attacker can construct an attack packet to remotely execute a system command.
In the invention, the data of the vulnerability database can be obtained from a vulnerability publishing platform, for example, the publicly published vulnerability is collected in the CNNVD, and RCE type vulnerabilities in the vulnerability database are screened, and the vulnerability Poc database and the vulnerability Ext database are treated in the same way.
In the invention, the matching rule of the fingerprint rule base can be added manually, for example, apache ═ in ("Server", "apache") indicates that apache exists in the Server field of the response header, and then the Server of the website is the apache.
Step 2: starting the device and issuing the task.
In the step 2, the task is the URL connection of the normalized website.
In the step 2, the task is text input or file input.
In the invention, irregular URL links are removed, and the irregular URL generally refers to wrong URL or URL without protocol and the link does not conform to the rule of URL, such as: "http: www.aa.com", "http: www.aa.com", "http:// www.aa.com: aa", shall be "http:// www.aa.com", "http:// www.aa.com: 80", "http:// www.aa.com/aa/", respectively.
And step 3: and executing the task, performing vulnerability identification, and detecting a WEB backdoor.
The step 3 comprises the following steps:
step 3.1: calling a fingerprint rule base E to identify the task;
in step 3.1, the identification comprises the following steps:
step 3.1.1: accessing a website corresponding to the task to obtain a response message;
step 3.1.2: constructing response message characteristics F based on server field characteristics, X-Powered-By field characteristics and page related characteristics pages in the response message, and matching the response message characteristics F with a fingerprint rule base E;
step 3.1.3: and if the E is matched with the F, and the E belongs to the E and the F belongs to the F, judging that the website fingerprint of the task is the fingerprint corresponding to the E.
Step 3.2: matching the RCE loopholes Poc corresponding to the identified fingerprints, if the matching is successful, performing the next step, otherwise, judging that the RCE loopholes Poc are not WEB backdoors, and performing the step 4;
step 3.3: executing the vulnerability Poc, if judging that the vulnerability exists, performing the next step, otherwise, judging that the vulnerability does not exist, and performing the step 4;
step 3.4: matching the identified fingerprints with corresponding vulnerability Ext, executing the vulnerability Ext, and acquiring source codes of all webpages of the task;
step 3.5: carrying out feature recognition on any source code by using the source code feature matching set A, if the recognition is successful, judging the source code as a WEB backdoor, and outputting, otherwise, discarding a page corresponding to the current source code; and (4) until the source codes of all the web pages of the task are identified.
In the invention, the matching in the step 3.1.3 refers to matching the webpage with the corresponding fingerprint rule, and a plurality of implementation modes such as character string matching can be adopted; for example, the fields of the response header of web page E are as follows:
Connection:keep-alive;
Content-Encoding:gzip;
Content-Language:zh-CN;
Content-Type:text/html;charset=gbk;
Date:Fri,06 Dec 2019 09:28:59GMT;
Server:nginx;
Transfer-Encoding:chunked;
if rule F is nginx ═ in ("Server", nginx), then here e matches F;
if rule F' is apache-in ("Server"), then e does not match F here.
In the invention, the feature recognition in the step 3.5 is generally to match a source code feature library by using a regular expression and a SimHash, judge the similarity of pages by calculating the Hamming distance between a source file and a feature page, so as to judge whether a source code is similar to the feature page, and further obtain whether the source code is a backdoor; in actual operation, a person skilled in the art can select other feature string matching or text similarity algorithm for recognition according to requirements.
And 4, step 4: and outputting a detection result.
In the invention, the detection result is generally output in an Excel report form or a Word text form.
The invention also relates to a detection device adopting the RCE vulnerability-based WEB backdoor detection method, which comprises the following steps:
the characteristic collection module is used for collecting the existing WEB backgate source codes and RCE code execution vulnerabilities Poc and vulnerabilities Ext and corresponding fingerprint characteristics to construct a characteristic library;
the task receiving module is used for receiving webpage information needing to detect a WEB backdoor;
the task execution module is used for carrying out WEB backdoor detection on the basis of the feature library of the feature collection module and the webpage information received by the task receiving module;
and the result output module is used for receiving and outputting the feedback result of the task execution module.
The task execution module comprises:
the detection module is used for carrying out fingerprint identification and vulnerability detection on the received task;
and the characteristic identification module is used for finding out a source file matched with the webpage corresponding to the task and outputting a file path.
The detection module comprises:
the fingerprint identification module is used for accessing the URL of the website to acquire page resources and carrying out fingerprint identification based on the characteristic matching of the Http response message;
the loophole detection module is used for finding out Poc of the corresponding REC loophole through the identified fingerprint and verifying the Poc;
and the vulnerability utilization module is used for executing the corresponding vulnerability Ext aiming at the vulnerability and obtaining all source files and paths of the website.
In the invention, the characteristic collection module is mainly used for collecting the source codes of the open WEB backdoor webpage and collecting RCE code execution vulnerabilities Poc, vulnerabilities Ext and related influence ranges, namely fingerprint ranges (characteristic ranges) of websites.
In the invention, a task URL is input through a task receiving module, judgment is carried out through a task executing module, and a WEB backdoor path is output through a result output module.
In the invention, in the vulnerability detection module, verification refers to verifying whether the current website has the current REC vulnerability.
In the invention, an embodiment is provided for WEB site WEB backdoor detection of the ThinkPHP 5.X RCE vulnerability.
Collecting a feature library of a WEB backgate from gitubs, wherein a WEB backgate source code set A { a }1,a2,…an-present in the read medium;
collecting Poc of the ThinkPHP 5.XRCE vulnerability from the Internet, wherein host is the host domain name of the target website, and Poc is as follows:
GET /echo abcdefg HTTP/1.1
Host:host
;
collecting website fingerprint characteristics of ThinkPHP 5.X from the Internet, wherein the website fingerprint characteristics are X-Power-By: ThinkPHP.
Defining the vulnerability Ext as dir as a directory path and file as a file name, respectively displaying all files and subdirectories of the current directory and displaying source files of the file:
GET /ls–R HTTP/1.1
Host:host
GET /catfileHTTP/1.1
Host:host
;
setting an editable text box for a user to manually input a website home page address to be scanned; setting a clickable submission button, and clicking the button by a user to issue a task; issuing a website A http:// www.abc.com that a ThinkPHP 5.X RCE vulnerability exists;
accessing a website http:// www.abc.com, and receiving a response packet returned by A;
recognizing that a message header X-Powered-By exists in the response packet: ThinkPHP, then the A website may have a ThinkPHP 5.X RCE vulnerability;
sending vulnerability detection messages
GET /echo abcdefg HTTP/1.1
Host:www.abc.com
;
Identifying that the page response content is abcdefg, and judging that a ThinkPHP 5.X RCE vulnerability exists in the website A;
executing the following steps to obtain all pages of the website:
GET /ls–R HTTP/1.1
Host:www.abc.com
;
if the response result is: file, dir, then show the source file of the file:
GET /catfileHTTP/1.1
Host:www.abc.com
;
if the corresponding result is: <? php @ eval ($ _ POST [ 'pass' ]); is there a Carrying out feature matching;
if the source code content of the page <? php @ eval ($ _ POST [ 'pass' ]); is there a If the file is matched regularly, the file is sent to a result output module;
and outputting, and writing the file path and the source file into the Excel output.
After the device is initialized, the feature collection module is used for collecting features, processing is carried out to obtain a feature library, a task is issued after the device is started, the task receiving module receives the task and is executed by the task execution module, vulnerability recognition is carried out, a WEB backdoor is detected, and a detection result is output by the result output module.
By utilizing RCE loopholes, the invention can remotely detect the directory tree of the website and the source files of all the webpage files, and then carry out feature recognition on the webpage and detect the WEB backdoor existing in an isolated chain, thereby realizing the remote static detection of the WEB backdoor of the website and the searching and killing.