CN110417919B - Traffic hijacking method and device - Google Patents
Traffic hijacking method and device Download PDFInfo
- Publication number
- CN110417919B CN110417919B CN201910810437.4A CN201910810437A CN110417919B CN 110417919 B CN110417919 B CN 110417919B CN 201910810437 A CN201910810437 A CN 201910810437A CN 110417919 B CN110417919 B CN 110417919B
- Authority
- CN
- China
- Prior art keywords
- instance object
- wkwebview
- access request
- page access
- response data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
- H04L67/63—Routing a service request depending on the request content or context
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The embodiment of the invention discloses a flow hijacking method and a device, wherein the method comprises the following steps: according to the triggering operation of a user in a preset application program, a first wkwebview page access request based on a hypertext transfer protocol is generated, and response data corresponding to the first wkwebview page access request is obtained through a first instance object set in the preset application program. In the embodiment of the invention, the first instance object can intercept wkwebview page access requests in different processes, so that the first instance object can intercept any wkwebview page access request (including a wkwebview webpage access request of http or https) triggered in a preset application program by setting the first instance object in the preset application program, and the accuracy of flow interception is improved.
Description
Technical Field
The invention relates to the technical field of communication, in particular to a traffic hijacking method and device.
Background
With the rapid development of information technology, the application range of the internet is wider and wider, and when the terminal device detects that a user triggers a webpage access request on an application program APP of the terminal device, the terminal device can go to a corresponding server to obtain response data corresponding to the webpage access request. However, in order to better realize network acceleration, the APP may hijack the web access request before the web access request exits the terminal device, and may obtain response data corresponding to the web access request from the near-end server through the CDN server, so that the pressure of the far-end server may be reduced, and the response speed may be increased.
At present, an apple Operating System (iOS) generally loads a web access request based on a wkwebview framework, and accordingly, a web access request triggered by a user on an APP of the iOS is also converted into a wkwebview web access request from a conventional UIwebview web access request. The method comprises the following steps that a traditional UIwebview webpage access request generally uses an instance object supported by a NSURLProtocol protocol to intercept the UIwebview webpage access request, and the instance object supported by the NSURLProtocol protocol can intercept and process all webpage access requests in a process; however, since a wkwebview web page access request based on Hypertext transfer protocol (http) or https in the wkwebview framework is generally sent in a separate process, a problem may occur when an instance object supported by the NSURLProtocol protocol intercepts a wkwebview web page access request based on http or https. Specifically, the web page access request includes a Uniform Resource Locator (URL) address and request content (i.e., body), and when intercepting a web page access request of another process, an instance object supported by the NSURLProtocol protocol may intercept a normal URL address, but may lose part or all of the body; therefore, if an instance object supported by the NSURLProtocol protocol is used to intercept a wkwebview web page access request based on http or https, part or all of the body in the wkwebview web page access request may be lost.
In order to solve the above problems, in an existing solution, after an APP in the iOS generates a wkwebview web page access request according to a trigger operation of a user, the wkwebview web page access request may be parsed to obtain an original URL address and a body, and the original URL address and the body are further spliced together and sent out as a new URL address; in this way, after the instance object supported by the NSURLProtocol protocol intercepts the new URL address, the original URL address and the body can be obtained through analysis, so as to obtain response data according to the original URL address and the body. However, the data size of the wwwebview webpage access request limited URL address needs to be less than 1M, and the limited URL address needs to be a character type (i.e. string type), so this implementation cannot support the case that the data size of the body exceeds 1M or the type of the body is a non-character type, resulting in that the traffic of the wwwebview webpage access request based on http or https cannot be intercepted accurately.
In summary, there is a need for a traffic hijacking method for accurately intercepting traffic of a wkwebview web page access request based on http or https.
Disclosure of Invention
The embodiment of the invention provides a traffic hijacking method which is used for accurately intercepting the traffic of a wkwebview webpage access request based on http or https.
In a first aspect, an embodiment of the present invention provides a traffic hijacking method, where the method is applied to a traffic hijacking device, and the traffic hijacking device is set in a preset application program of a terminal device; the method comprises the following steps:
generating a first wkwebview page access request based on a hypertext transfer protocol according to a triggering operation of a user in the preset application program, and acquiring response data corresponding to the first wkwebview page access request through a first instance object set in the preset application program; the first instance object supports a WKURLSchemeHandler protocol, and is used for intercepting the first wkwebview page access request and acquiring response data corresponding to the first wkwebview page access request.
In the design, the instance object supported by the WKURLSchemeHandler protocol in the IOS system can intercept wkwebview page access requests in different processes, so that the first instance object can intercept any wkwebview page access request (including the wkwebview page access request of http or https) triggered in the preset application program by setting the first instance object supporting the WKURLSchemeHandler protocol in the preset application program, and thus, the flow of the wkwebview page access request based on http or https can be accurately intercepted.
In a possible design, the obtaining, by a first instance object set in the preset application program, response data corresponding to the first wkwebview page access request includes: and inquiring whether response data corresponding to the first wkwebview page access request exists in a first preset space corresponding to the first instance object, if not, sending the first wkwebview page access request to a second object instance, and acquiring the response data corresponding to the first wkwebview page access request through the second object instance.
In one possible design, the second instance object supports the NSURLProtocol protocol, and the first instance object and the second instance object are located in the same process.
In the design, as the second instance object supporting the NSURLProtocol protocol can intercept and process all webpage access requests in the process and can accurately acquire corresponding response data, the first wkwebview page access request can be accurately intercepted by combining the first instance object supporting the WKURLschemeHandler protocol and the second instance object supporting the NSURLProtocol protocol, and the accuracy and the comprehensiveness of flow interception are improved; in addition, by setting the first preset space corresponding to the first instance object, the first preset space can be used for storing historical response data acquired by the first instance object, so that after the first instance object intercepts the first wkwebview page access request, if response data corresponding to the first wkwebview page access request exists in the first preset space, the first instance object can directly send the response data corresponding to the first wkwebview page access request in the first preset space to the APP without repeatedly executing and calling the second instance object and/or the CDN server to acquire the response data, thereby improving the response speed and reducing the system resource occupancy rate.
In one possible design, the obtaining, by the second object instance, response data corresponding to the first wkwebview page access request includes: inquiring whether response data corresponding to the first wkwebview page access request exist in a second preset space corresponding to the second instance object, and if the response data do not exist, sending the first wkwebview page access request to a Content Delivery Network (CDN) server; further, after response data corresponding to the first wkwebview page access request sent by the CDN server is obtained, the response data is displayed to the user sequentially through the second instance object, the first instance object, and the preset application program.
In the above design, by setting the second preset space corresponding to the second instance object, the second preset space may be used to store the historical response data acquired by the second instance object, and thus, after the second instance object receives the first wkwebview page access request sent by the first instance object, if the second preset space has response data corresponding to the first wkwebview page access request, the second instance object may directly send the response data corresponding to the first wkwebview page access request in the second preset space to the first instance object without acquiring the response data from the CDN server, so that the response speed may be increased, and the system resource occupancy may be reduced.
In one possible design, the method further includes: setting a first identifier of the first wkwebview page access request in the first instance object and a second identifier in the second instance object, and calling a response method corresponding to the second identifier to send the response data to the first instance object after the response data is acquired through the second instance object; further, after the response data is obtained through the first instance object, a response method corresponding to the first identifier is called to send the response data to the preset application program, and the response data is displayed to the user through the preset application program.
In the above design, by setting the first identifier of the first wkwebview page access request in the first instance object and the second identifier in the second instance object, the first instance object may invoke the response method corresponding to the first identifier to send the response data, and the second instance object invokes the response method corresponding to the second identifier to send the response data, so that stability and accuracy of transmission of the response data in the first instance object and the second instance object are ensured.
In a possible design, after the obtaining, by the first instance object, response data corresponding to the first wkwebview page access request, the method further includes: storing the response data in the first preset space.
In a second aspect, an embodiment of the present invention provides a traffic hijacking apparatus, where the traffic hijacking apparatus is set in a preset application program of a terminal device, and the apparatus includes:
the generating module is used for generating a first wkwebview page access request based on a hypertext transfer protocol according to triggering operation of a user in a preset application program;
the acquisition module is used for acquiring response data corresponding to the first wkwebview page access request through a first instance object set in the preset application program;
the first instance object supports a WKURLSchemeHandler protocol, and is used for intercepting the first wkwebview page access request and acquiring response data corresponding to the first wkwebview page access request.
In one possible design, the obtaining module is specifically configured to: and inquiring whether response data corresponding to the first wkwebview page access request exists in a first preset space corresponding to the first instance object, if not, sending the first wkwebview page access request to a second object instance, and acquiring the response data corresponding to the first wkwebview page access request through the second object instance.
In one possible design, the second instance object supports the NSURLProtocol protocol, and the first instance object and the second instance object are located in the same process.
In one possible design, the obtaining module is specifically configured to: inquiring whether response data corresponding to the first wkwebview page access request exist in a second preset space corresponding to the second instance object, and if the response data do not exist, sending the first wkwebview page access request to a Content Delivery Network (CDN) server; further, after response data corresponding to the first wkwebview page access request sent by the CDN server is obtained, the response data is displayed to the user sequentially through the second instance object, the first instance object, and the preset application program.
In one possible design, the apparatus further includes a processing module to: setting a first identifier of the first wkwebview page access request in the first instance object and a second identifier in the second instance object, and calling a response method corresponding to the second identifier to send the response data to the first instance object after the response data is acquired through the second instance object; further, after the response data is obtained through the first instance object, a response method corresponding to the first identifier is called to send the response data to the preset application program, and the response data is displayed to the user through the preset application program.
In one possible design, the obtaining module is further configured to: storing the response data in the first preset space.
In a third aspect, an embodiment of the present invention provides a computing device, including at least one processing unit and at least one storage unit, where the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit is caused to execute the traffic hijacking method according to any one of the above first aspects.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores a computer program executable by a computing device, and when the program runs on the computing device, the program causes the computing device to execute the traffic hijacking method according to any one of the first aspect.
These and other aspects of the present application will be more readily apparent from the following description of the embodiments.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic flow chart of a traffic hijacking method according to an embodiment of the present invention;
fig. 2 is an interaction flow diagram of a traffic hijacking method according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a traffic hijacking device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flow chart of a traffic hijacking method according to an embodiment of the present invention, where the method is applied to a traffic hijacking device; the traffic hijack device is arranged in a preset application program of the terminal equipment, can intercept a webpage request generated in the terminal equipment, and can acquire response data corresponding to the webpage request from the interior of the traffic hijack device or a Content Delivery Network (CDN) system; the method comprises the following steps:
In this embodiment of the present invention, the terminal device may be a terminal device loaded with an IOS system, such as a mobile phone loaded with an IOS system, a tablet computer loaded with an IOS system, or an Ipad loaded with an IOS system, and is not limited specifically. Accordingly, the preset APP may be an APP that is installed on the terminal device and supports the wkwebview framework.
In a possible implementation manner, a user may trigger a preset APP to generate a first wwwbview page access request in a front-end network frame interaction manner, for example, the user may trigger the preset APP to generate the first wwwbview page access request by clicking a preset icon or a preset hyperlink on the preset APP, or the user may also input a preset link in a text box of the preset APP to trigger the preset APP to generate the first wwwbview page access request, or the user may also call a browser to access the wwwbview page to trigger the preset APP to generate the first wwwbview page access request, and so on. It is to be understood that the user may also trigger the preset APP to generate the first wwwebview page access request by other means, such as a voice trigger, a brain wave trigger, or a remote control trigger, which is not limited in this disclosure.
It should be noted that the embodiment of the present invention does not limit the type of the front-end network framework, and for example, the front-end network framework may be any one of an ajax framework, a jquery framework, or an vue framework.
And 102, acquiring response data corresponding to the first wkwebview page access request through a first instance object set in the preset application program.
Here, the first instance object may be an instance object supporting the WKURLSchemeHandler protocol. The embodiment of the invention sets the first instance object supporting the WKURLSchemeHandler protocol in the preset APP, so that the preset APP can intercept the wkwebview page access request based on http and/or https by using the first instance object.
It should be noted that the WKURLSchemeHandler protocol is a protocol set based on the wkwebview framework of the IOS system, and the protocol may be added to a user-defined scheme, so that a wkwebview page access request corresponding to the user-defined protocol may be intercepted. For example, if a user sets a custom protocol in an APP, after a program supporting the WKURLSchemeHandler protocol is added to the APP, the APP may intercept a wkwebview page access request with the type of the custom protocol using the WKURLSchemeHandler protocol.
In summary, the existing WKURLSchemeHandler protocol in the IOS system only supports intercepting wkwebview page access requests corresponding to a customized protocol, while the first wkwebview page access request generated by the preset APP is a wkwebview page access request based on http and/or https, http and/or https are a customized protocol and do not belong to the customized protocol; therefore, if the preset APP is directly set to support the existing WKURLSchemeHandler protocol, the preset APP cannot intercept the first wkwebview page access request.
In a possible implementation manner, in order to solve the above problem, a first instance object supporting the WKURLSchemeHandler protocol may be created first, and then the first instance object may intercept a wkwebview page access request based on http and/or https by configuring attribute information of the first instance object. The creating of the first instance object and the configuring of the attribute information of the first instance object may be implemented by the following programs:
WKWebSchemeHandler*handle=[[WKWebSchemeHandler alloc]init];
[configuration setURLSchemeHandler:handle forURLScheme:@"http"];
[configuration setURLSchemeHandler:handle forURLScheme:@"https"];
the first journey sequence is used for creating a first instance object handle supporting a WKURLSChmeHandler protocol, an initial space is distributed for the first instance object handle, and a memory occupied by the initial space meets the requirement of [ WKWebSchemeHandler alloc ]; correspondingly, the second line program and the third line program are used for configuring attribute information of the first instance object handle, the first instance object can be made to intercept a wkwebview page access request based on http through the second line program, and the first instance object can be made to intercept a wkwebview page access request based on https through the third line program.
Further, by creating a first instance object and configuring attribute information of the first instance object, the first instance object can intercept a wkwebview page access request based on http and/or https; however, for any wkwebview page access request (which may be any type of page access request, not only http and/or https-based page access request, but also other types of page access requests, without limitation), after detecting that the wkwebview page access request is generated, the wkwebview framework first calls a private method handleurslcheme to determine whether the wkwebview page access request meets the requirements of the WKWebSchemeHandler protocol. If the access request of the wkwebview page meets the requirement of the WKWebSchemeHandler protocol, returning 'YES' to the first instance object by the private method handleURLScheme so that the first instance object obtains response data corresponding to the access request of the wkwebview page according to the intercepted access request of the wkwebview page; correspondingly, if the wkwebview page access request does not meet the requirements of the WKWebSchemeHandler protocol, the private method handleurslchome returns "NO" to the first instance object, and thus the first instance object does not perform any processing on the intercepted wkwebview page access request subsequently.
Based on the principle, if the existing private method handleurslcheme in the IOS system is directly used, after the first instance object intercepts a first wkwebview page access request based on http and/or https, the first instance object calls the existing private method handleurslcheme to determine whether the first wkwebview page access request meets the requirements of the WKWebSchemeHandler protocol; because the WKWebSchemeHandler protocol only supports the wkwebview page access request corresponding to the self-defined protocol, but cannot support the first wkwebview page access request of http and/or https, the existing private method handleURLScheme returns 'NO' to the first instance object, and the first instance object cannot perform any processing on the intercepted first wkwebview page access request.
In order to solve the problem, the embodiment of the present invention modifies the existing private class method handleurslchrome, so that when detecting that the wkwebview page access request intercepted by the first instance object is a wkwebview page access request based on http and/or https, the private class method handleurslchrome returns "YES" to the first instance object. In this way, after the first instance object intercepts the first wkwebview page access request based on http and/or https, the private method handlesrlscheme judges that the first wkwebview page access request is the wkwebview page access request based on http and/or https, and therefore "YES" may be returned to the first instance object, so that the first instance object may obtain response data corresponding to the first wkwebview page access request according to the intercepted first wkwebview page access request.
In one possible implementation manner, the response data corresponding to the first wkwebview page access request may have the following three situations:
in case one, response data corresponding to a first wkwebview page access request is stored in a first preset space corresponding to a first instance object;
in case two, response data corresponding to the first wkwebview page access request is stored in a second preset space corresponding to the second instance object;
in case three, the response data corresponding to the first wkwebview page access request is not stored in the first preset space corresponding to the first instance object, nor stored in the second preset space corresponding to the second instance object.
It should be noted that the second instance object in the embodiment of the present invention may be an instance object supporting the NSURLProtocol protocol, and the first instance object and the second instance object may be located in the same process.
Based on the first to third cases, in a specific implementation, after the first instance object intercepts the first wkwebview page access request and receives a "YES" returned by the private method handlesrlcheme, a first preset space corresponding to the first instance object may be queried, and it is determined whether response data corresponding to the first wkwebview page access request exists in the first preset space. If response data corresponding to the first wkwebview page access request exists in the first preset space, the first instance object may send the response data corresponding to the first wkwebview page access request to the preset APP, so that the preset APP displays a page corresponding to the first wkwebview page access request to a user according to the response data corresponding to the first wkwebview page access request. Correspondingly, if no response data corresponding to the first wkwebview page access request exists in the first preset space, the first instance object may send the first wkwebview page access request to the second instance object, and thus, after receiving the first wkwebview page access request, the second instance object may query a second preset space corresponding to the second instance object, and determine whether response data corresponding to the first wkwebview page access request exists in the second preset space.
Further, if response data corresponding to the first wkwebview page access request exists in the second preset space, the second instance object may send the response data corresponding to the first wkwebview page access request to the first instance object, and thus, the first instance object may send the response data corresponding to the first wkwebview page access request to the preset APP, so that the preset APP displays the page corresponding to the first wkwebview page access request to the user according to the response data corresponding to the first wkwebview page access request. Correspondingly, if no response data corresponding to the first wkwebview page access request exists in the second preset space, the second instance object may send the first wkwebview page access request to the CDN server; the CDN server may be any server in the CDN system, such as an edge node server, an intermediate node server, or an origin station, which is not limited herein. In this way, the CDN server may first search response data corresponding to the first wwwbview page access request from the near-end resource server, and if not, go to the far-end resource server to search for response data corresponding to the first wwwbview page access request, and then send the response data corresponding to the first wwwbview page access request to the second instance object, so that the second instance object sends the response data corresponding to the first wwwbview page access request to the first instance object, and then the first instance object sends the response data corresponding to the first wwbwview page access request to the preset APP, and display the page corresponding to the first wwbwview page access request to the user through the preset APP.
In an example, after the second instance object acquires response data corresponding to the first wkwebview page access request sent by the CDN server, the response data may also be stored in a second preset space; correspondingly, after the first instance object acquires the response data corresponding to the first wkwebview page access request sent by the second instance object, the response data may also be stored in the first preset space.
In the embodiment of the present invention, by setting the first preset space corresponding to the first instance object, the first preset space may be used to store the historical response data acquired by the first instance object. Therefore, after the first instance object intercepts the first wkwebview page access request, if response data corresponding to the first wkwebview page access request exists in the first preset space, the first instance object can directly send the response data corresponding to the first wkwebview page access request in the first preset space to the APP without repeatedly executing and calling the second instance object and/or the CDN server to obtain the response data, so that the response speed can be increased, and the processing speed can be increased. Similarly, the response speed can be further increased and the processing speed can be increased by setting the second preset space corresponding to the second instance object.
It should be noted that the second instance object may support an existing NSURLProtocol, and because the existing NSURLProtocol may intercept and process all page access requests in the process where the second instance object is located, if the first instance object does not query response data corresponding to the first wkwebview page access request in the first preset space, when the first instance object sends the first wkwebview page access request in the process where the first instance object is located, because the first instance object and the second instance object are located in the same process, the second instance object may intercept and process the first wkwebview page access request.
In the embodiment of the invention, a first instance object supporting WKURLSchemeHandler protocol is established in a preset APP, the attribute of the first instance object is configured, and a private method class handleURLScheme is modified, so that the first instance object can intercept and process a wkwebview page access request triggered in the preset APP and based on http and/or https; and a second instance object which supports NSURLProtocol protocol and is in the same process with the first instance object is established in the preset APP, so that the second instance object can intercept and process all webpage access requests in the process, and can accurately acquire corresponding response data. Therefore, by using the first instance object supporting the WKURLSCHEME Handler protocol and the second instance object supporting the NSURLProtocol protocol, the wkwebview page access request triggered in the preset APP and based on http and/or https can be accurately intercepted, the corresponding response data can be accurately acquired, and the accurate acquisition of the wkwebview page access request based on http and/or https can be realized.
In a possible implementation manner, if response data corresponding to the first wkwebview page access request does not exist in the first preset space, before the first instance object sends the first wkwebview page access request to the second instance object, a first identifier of the first wkwebview page access request in the first instance object may also be set; correspondingly, if no response data corresponding to the first wkwebview page access request exists in the second preset space, before the second instance object sends the first wkwebview page access request to the CDN server, a second identifier of the first wkwebview page access request in the second instance object may also be set. In this way, after receiving response data corresponding to the first wkwebview page access request sent by the CDN server, the second instance object may call a response method corresponding to the second identifier to send the response data corresponding to the first wkwebview page access request to the first instance object; correspondingly, after receiving the response data corresponding to the first wkwebview page access request sent by the second instance object, the first instance object may call a response method corresponding to the first identifier to send the response data corresponding to the first wkwebview page access request to the preset APP, so as to display the corresponding page to the user through the preset APP.
In one example, the correspondence between the first wkwebview page access request and the first identifier may be stored in a first instance object in a key-value pair manner, and the correspondence between the first wkwebview page access request and the second identifier may also be stored in a second instance object in a key-value pair manner. For example, both the first instance object and the second instance object may be provided with a key-value pair database, and after the first instance object generates the first identifier corresponding to the first wkwebview page access request, the first instance object may store the correspondence between the first wkwebview page access request and the first identifier in the key-value pair database of the first instance object by using the first wkwebview page access request as a key and the first identifier as a value corresponding to the key; correspondingly, after the second instance object generates the second identifier corresponding to the first wkwebview page access request, the second instance object may store the corresponding relationship between the first wkwebview page access request and the second identifier in a key-value pair database of the second instance object by using the first wkwebview page access request as a key and the second identifier as a value corresponding to the key.
In a specific implementation, taking the first instance object as an example, if the first instance object receives response data corresponding to the first wwwbview page access request sent by the second instance object, the first instance object may query and determine a first identifier corresponding to the first wwwbview page access request from key-value pair data of the first instance object, and then send the response data corresponding to the first wwwbview page access request to the preset APP by using a response method corresponding to the first identifier. If the first instance object does not receive response data corresponding to the first wkwebview page access request sent by the second instance object within the preset time length or receives an abnormal response message sent by the second instance object, the first instance object may query and determine a first identifier corresponding to the first wkwebview page access request from key value pair data of the first instance object, and then send indication information of request abnormality to the preset APP by an abnormal response method corresponding to the first identifier.
In the embodiment of the invention, by setting the first identifier of the first wkwebview page access request in the first instance object and the second identifier in the second instance object, the first instance object can call the response method corresponding to the first identifier to send the response data, and the second instance object calls the response method corresponding to the second identifier to send the response data, so that the stability and the accuracy of the transmission of the response data in the first instance object and the second instance object are ensured.
Based on the traffic hijacking method illustrated in fig. 1, fig. 2 is an interaction flow diagram of the traffic hijacking method provided in the embodiment of the present invention, and a specific implementation process of the traffic hijacking method in the embodiment of the present invention is described below with reference to fig. 2.
It can be understood that the traffic hijacking method in the embodiment of the present invention not only relates to the preset APP at the front end of the terminal device, the first instance object and the second instance object at the background of the preset APP, but also relates to the CDN server, where the CDN server may be any server in the CDN system, for example, may be an edge node server, an intermediate server, or may also be a source station, and is not limited herein.
Step 201, a preset APP generates a first wkwebview page access request based on http and/or https according to a trigger operation of a user.
Here, after the preset APP generates the first wkwebview page access request, the preset APP may send the first wkwebview page access request in a process corresponding to http and/or https.
In step 202, a first instance object intercepts a first wkwebview page access request in a preset APP.
In an example, the first instance object may be started together with the start of the preset APP and cleared together with the exit of the preset APP, that is, the life cycle of the first instance object may be the same as that of the preset APP, so as to reduce the resource occupation of the system.
In the embodiment of the invention, when the first instance object is started, the second instance object can be automatically registered for the preset APP.
Step 203, the first instance object queries and determines whether the first preset space corresponding to the first instance object includes response data corresponding to the first wkwebview page access request, if so, the step 204a is skipped, and if not, the step 204b is skipped.
In step 204a, the first instance object obtains response data corresponding to the first wkwebview page access request from the first preset space corresponding to the first instance object, and sends the response data corresponding to the first wkwebview page access request to the preset APP, and then the step 213 is skipped.
And 204b, setting a first identifier of the first wkwebview page access request in the first instance object by the first instance object, and storing the corresponding relation between the first wkwebview page access request and the first identifier in a key-value pair database of the first instance object.
In step 205, the first instance object sends a first wkwebview page access request to the second instance object.
In specific implementation, the first instance object and the second instance object are in the same process, and the second instance object can intercept and process all wkwebview page access requests sent in the process where the first instance object is located, so that the first instance object can directly send the first wkwebview page access requests to the process where the first instance object is located.
In step 206, the second instance object queries to determine whether the second preset space corresponding to the second instance object includes response data corresponding to the first wkwebview page access request, if so, the step 207a is skipped, and if not, the step 207b is skipped.
In step 207a, the second instance object obtains response data corresponding to the first wkwebview page access request from the second preset space corresponding to the second instance object, and sends the response data corresponding to the first wkwebview page access request to the first instance object, and then the step 212 is skipped.
And step 207b, the second instance object sets a second identifier of the first wkwebview page access request in the second instance object, and stores the corresponding relation between the first wkwebview page access request and the second identifier in a key-value pair database of the second instance object.
And step 208, the second instance object sends the first wkwebview page access request to the CDN server.
Step 209, the CDN server obtains response data corresponding to the first wkwebview page access request.
Here, the CDN server may obtain response data corresponding to the first wkwebview page access request from the near-end resource server, and if the response data is not obtained, obtain response data corresponding to the first wkwebview page access request from the far-end resource server.
Step 210, the CDN server sends response data corresponding to the first wkwebview page access request to the second instance object.
And step 211, the second instance object acquires a second identifier corresponding to the first wkwebview page access request from a key value pair database of the second instance object, and calls a response method corresponding to the second identifier to send response data corresponding to the first wkwebview page access request to the first instance object.
Step 212, the first instance object acquires a first identifier corresponding to the first wkwebview page access request from a key value pair database of the first instance object, and calls a response method corresponding to the first identifier to send response data corresponding to the first wkwebview page access request to the preset APP.
Step 213, displaying a page corresponding to the first wkwebview page access request to a user according to response data corresponding to the first wkwebview page access request by a preset APP.
In the embodiment of the invention, according to the triggering operation of a user in a preset application program, a first wkwebview page access request based on a hypertext transfer protocol is generated, and response data corresponding to the first wkwebview page access request is acquired through a first instance object set in the preset application program; the first instance object supports a WKURLSchemeHandler protocol, and is used for intercepting the first wkwebview page access request and acquiring response data corresponding to the first wkwebview page access request. In the embodiment of the invention, the instance object supported by the WKULSchemeHandler protocol in the IOS system can intercept the wkwebview page access requests in different processes, so that the first instance object can intercept any wkwebview page access request (including the wkwebview page access request of http or https) triggered in the preset application program by setting the first instance object supporting the WKULSchemeHandler protocol in the preset application program, and the flow of the wkwebview page access request based on http or https can be accurately intercepted.
Aiming at the method flow, the embodiment of the invention also provides a flow hijacking device, and the specific content of the device can be implemented by referring to the method.
Fig. 3 is a schematic structural diagram of a traffic hijacking apparatus according to an embodiment of the present invention, where the apparatus is disposed in a preset application program of a terminal device, and the apparatus includes:
the generation module 301 is configured to generate a first wkwebview page access request based on a hypertext transfer protocol according to a trigger operation of a user in a preset application program;
an obtaining module 302, configured to obtain response data corresponding to the first wkwebview page access request through a first instance object set in the preset application program;
the first instance object supports a WKURLSchemeHandler protocol, and is used for intercepting the first wkwebview page access request and acquiring response data corresponding to the first wkwebview page access request.
Optionally, the obtaining module 302 is specifically configured to:
and inquiring whether response data corresponding to the first wkwebview page access request exists in a first preset space corresponding to the first instance object, if not, sending the first wkwebview page access request to a second object instance, and acquiring the response data corresponding to the first wkwebview page access request through the second object instance.
Optionally, the second instance object supports the NSURLProtocol protocol, and the first instance object and the second instance object are located in the same process.
Optionally, the obtaining module 302 is specifically configured to:
inquiring whether response data corresponding to the first wkwebview page access request exist in a second preset space corresponding to the second instance object, and if the response data do not exist, sending the first wkwebview page access request to a Content Delivery Network (CDN) server;
and after response data corresponding to the first wkwebview page access request sent by the CDN server is obtained, the response data are sequentially displayed to the user through the second instance object, the first instance object and the preset application program.
Optionally, the apparatus further comprises a processing module 303, wherein the processing module 303 is configured to:
setting a first identifier of the first wkwebview page access request in the first instance object and a second identifier in the second instance object;
after the response data is obtained through the second instance object, a response method corresponding to the second identifier is called to send the response data to the first instance object;
after the response data are obtained through the first instance object, calling a response method corresponding to the first identifier to send the response data to the preset application program;
and displaying the response data to the user through the preset application program.
Optionally, the obtaining module 302 is further configured to:
storing the response data in the first preset space.
From the above, it can be seen that: in the embodiment of the invention, according to the triggering operation of a user in a preset application program, a first wkwebview page access request based on a hypertext transfer protocol is generated, and response data corresponding to the first wkwebview page access request is acquired through a first instance object set in the preset application program; the first instance object supports a WKURLSchemeHandler protocol, and is used for intercepting the first wkwebview page access request and acquiring response data corresponding to the first wkwebview page access request. In the embodiment of the invention, the instance object supported by the WKULSchemeHandler protocol in the IOS system can intercept the wkwebview page access requests in different processes, so that the first instance object can intercept any wkwebview page access request (including the wkwebview page access request of http or https) triggered in the preset application program by setting the first instance object supporting the WKULSchemeHandler protocol in the preset application program, and the flow of the wkwebview page access request based on http or https can be accurately intercepted.
Based on the same inventive concept, an embodiment of the present invention further provides a computing device, including at least one processing unit and at least one storage unit, where the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit is caused to execute the traffic hijacking method as described in any of fig. 1 or fig. 2.
Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium storing a computer program executable by a computing device, where the program, when executed on the computing device, causes the computing device to execute a traffic hijacking method as described in any of fig. 1 or fig. 2.
It should be apparent to those skilled in the art that embodiments of the present invention may be provided as a method, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.
Claims (12)
1. A traffic hijacking method is characterized in that the method is applied to a traffic hijacking device, and the traffic hijacking device is arranged in a preset application program of terminal equipment; the method comprises the following steps:
generating a first wkwebview page access request based on a hypertext transfer protocol according to the triggering operation of a user in the preset application program;
inquiring whether response data corresponding to the first wkwebview page access request exists in a first preset space corresponding to a first instance object, if not, sending the first wkwebview page access request to a second instance object, and acquiring the response data corresponding to the first wkwebview page access request through the second instance object;
the first instance object supports a WKURLSchemeHandler protocol, and is used for intercepting the first wkwebview page access request and acquiring response data corresponding to the first wkwebview page access request.
2. The method of claim 1, wherein the second instance object supports the NSURLProtocol protocol, and wherein the first instance object and the second instance object are located within the same process.
3. The method of claim 1, wherein the obtaining response data corresponding to the first wkwebview page access request through the second instance object comprises:
inquiring whether response data corresponding to the first wkwebview page access request exist in a second preset space corresponding to the second instance object, and if the response data do not exist, sending the first wkwebview page access request to a Content Delivery Network (CDN) server;
and after response data corresponding to the first wkwebview page access request sent by the CDN server is obtained, the response data are sequentially displayed to the user through the second instance object, the first instance object and the preset application program.
4. The method of claim 3, further comprising:
setting a first identifier of the first wkwebview page access request in the first instance object and a second identifier in the second instance object;
after the response data is obtained through the second instance object, a response method corresponding to the second identifier is called to send the response data to the first instance object;
after the response data are obtained through the first instance object, calling a response method corresponding to the first identifier to send the response data to the preset application program;
and displaying the response data to the user through the preset application program.
5. The method according to any one of claims 1 to 4, wherein after the obtaining response data corresponding to the first wkwebview page access request by the first instance object, the method further comprises:
storing the response data in the first preset space.
6. A traffic hijack device is characterized in that the traffic hijack device is arranged in a preset application program of a terminal device, and the device comprises:
the generating module is used for generating a first wkwebview page access request based on a hypertext transfer protocol according to triggering operation of a user in a preset application program;
the acquisition module is used for inquiring whether response data corresponding to the first wkwebview page access request exists in a first preset space corresponding to a first instance object, if the response data do not exist, the first wkwebview page access request is sent to a second instance object, and the response data corresponding to the first wkwebview page access request is acquired through the second instance object;
the first instance object supports a WKURLSchemeHandler protocol, and is used for intercepting the first wkwebview page access request and acquiring response data corresponding to the first wkwebview page access request.
7. The apparatus of claim 6, wherein the second instance object supports the NSURLProtocol protocol, and wherein the first instance object and the second instance object are located within a same process.
8. The apparatus of claim 6, wherein the obtaining module is specifically configured to:
inquiring whether response data corresponding to the first wkwebview page access request exist in a second preset space corresponding to the second instance object, and if the response data do not exist, sending the first wkwebview page access request to a Content Delivery Network (CDN) server;
and after response data corresponding to the first wkwebview page access request sent by the CDN server is obtained, the response data are sequentially displayed to the user through the second instance object, the first instance object and the preset application program.
9. The apparatus of claim 8, further comprising a processing module to:
setting a first identifier of the first wkwebview page access request in the first instance object and a second identifier in the second instance object;
after the response data is obtained through the second instance object, a response method corresponding to the second identifier is called to send the response data to the first instance object;
after the response data are obtained through the first instance object, calling a response method corresponding to the first identifier to send the response data to the preset application program;
and displaying the response data to the user through the preset application program.
10. The apparatus of any one of claims 6 to 9, wherein the obtaining module is further configured to:
storing the response data in the first preset space.
11. A computing device comprising at least one processing unit and at least one memory unit, wherein the memory unit stores a computer program that, when executed by the processing unit, causes the processing unit to perform the method of any of claims 1 to 5.
12. A computer-readable storage medium storing a computer program executable by a computing device, the program, when run on the computing device, causing the computing device to perform the method of any of claims 1 to 5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910810437.4A CN110417919B (en) | 2019-08-29 | 2019-08-29 | Traffic hijacking method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910810437.4A CN110417919B (en) | 2019-08-29 | 2019-08-29 | Traffic hijacking method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110417919A CN110417919A (en) | 2019-11-05 |
CN110417919B true CN110417919B (en) | 2021-10-29 |
Family
ID=68369734
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910810437.4A Active CN110417919B (en) | 2019-08-29 | 2019-08-29 | Traffic hijacking method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110417919B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111931083B (en) * | 2020-06-30 | 2023-07-25 | 北京奇艺世纪科技有限公司 | Webpage loading method and device, terminal equipment and readable storage medium |
CN113792234A (en) * | 2021-08-18 | 2021-12-14 | 五八有限公司 | Page request processing method and device, electronic equipment and storage medium |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6438125B1 (en) * | 1999-01-22 | 2002-08-20 | Nortel Networks Limited | Method and system for redirecting web page requests on a TCP/IP network |
CN103366019A (en) * | 2013-08-06 | 2013-10-23 | 飞天诚信科技股份有限公司 | Webpage intercepting method and device based on iOS device |
WO2014101783A1 (en) * | 2012-12-26 | 2014-07-03 | Tencent Technology (Shenzhen) Company Limited | Method and server for performing cloud detection for malicious information |
CN104572777A (en) * | 2013-10-28 | 2015-04-29 | 腾讯科技(深圳)有限公司 | Webpage loading method and device based on UIWebView component |
EP3148165A1 (en) * | 2015-09-22 | 2017-03-29 | Instart Logic Inc. | Controlling access to network resources |
CN107203555A (en) * | 2016-03-17 | 2017-09-26 | 阿里巴巴集团控股有限公司 | Page loading processing method and device |
CN107977371A (en) * | 2016-10-21 | 2018-05-01 | 阿里巴巴集团控股有限公司 | Requesting method, display methods and the client of page elements |
CN109842617A (en) * | 2019-01-03 | 2019-06-04 | 深圳壹账通智能科技有限公司 | Ad blocking method, apparatus and storage medium |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103150513B (en) * | 2013-03-20 | 2015-12-09 | 北京奇虎科技有限公司 | The method of the implantation information in interception application program and device |
-
2019
- 2019-08-29 CN CN201910810437.4A patent/CN110417919B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6438125B1 (en) * | 1999-01-22 | 2002-08-20 | Nortel Networks Limited | Method and system for redirecting web page requests on a TCP/IP network |
WO2014101783A1 (en) * | 2012-12-26 | 2014-07-03 | Tencent Technology (Shenzhen) Company Limited | Method and server for performing cloud detection for malicious information |
CN103366019A (en) * | 2013-08-06 | 2013-10-23 | 飞天诚信科技股份有限公司 | Webpage intercepting method and device based on iOS device |
CN104572777A (en) * | 2013-10-28 | 2015-04-29 | 腾讯科技(深圳)有限公司 | Webpage loading method and device based on UIWebView component |
EP3148165A1 (en) * | 2015-09-22 | 2017-03-29 | Instart Logic Inc. | Controlling access to network resources |
CN107203555A (en) * | 2016-03-17 | 2017-09-26 | 阿里巴巴集团控股有限公司 | Page loading processing method and device |
CN107977371A (en) * | 2016-10-21 | 2018-05-01 | 阿里巴巴集团控股有限公司 | Requesting method, display methods and the client of page elements |
CN109842617A (en) * | 2019-01-03 | 2019-06-04 | 深圳壹账通智能科技有限公司 | Ad blocking method, apparatus and storage medium |
Non-Patent Citations (2)
Title |
---|
"The Cracked Cookie Jar: HTTP Cookie Hijacking and the Exposure of Private Information";Suphannee Sivakorn,Iasonas Polakis;《2016 IEEE Symposium on Security and Privacy (SP)》;20160818;全文 * |
"基于JavaScript的恶意网页异常检测方法研究";马洪亮;《中国博士学位论文全文数据库 信息科技辑》;20190131;全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN110417919A (en) | 2019-11-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11477298B2 (en) | Offline client replay and sync | |
US20170371974A1 (en) | Method for loading webpage, client and programmable device | |
US8527862B2 (en) | Methods for making ajax web applications bookmarkable and crawlable and devices thereof | |
CN106911693B (en) | Method and device for detecting hijacking of webpage content and terminal equipment | |
CN103973461A (en) | Notification message pushing method and message server | |
CN107679214B (en) | Link positioning method, device, terminal and computer readable storage medium | |
CN106569790B (en) | Card template generation method, service providing method, information providing method and device | |
US20170351691A1 (en) | Search method and apparatus | |
CN110417919B (en) | Traffic hijacking method and device | |
CN112579118B (en) | Method, device, system, medium and equipment for updating configuration information of micro-service | |
CN104572843A (en) | Page loading method and device | |
CN108574721B (en) | Login method, device, server, user terminal and readable storage medium | |
CN105956136B (en) | Method and device for acquiring login information | |
US11064052B2 (en) | Page insertion method and device | |
CN106933817B (en) | Content query method, device and system based on B/S structure | |
CN104932910A (en) | Method and system for application program interface extension | |
CN105871961B (en) | A kind of method and device of gray scale publication routing | |
CN106686040A (en) | Message processing method and message processing device | |
CN106599045B (en) | Request sending method and device | |
JP2018500670A (en) | Handling unstructured messages | |
US10095791B2 (en) | Information search method and apparatus | |
CN103051722B (en) | A kind ofly determine the method whether page is held as a hostage and relevant device | |
CN109495319B (en) | Method, device and equipment for determining fault information of CDN node | |
CN113138814A (en) | Remote assistance method, device, equipment and storage medium | |
CN107562469B (en) | Title bar data display method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |