CN108429757A - 一种保护网站资源的反爬方法 - Google Patents

一种保护网站资源的反爬方法 Download PDF

Info

Publication number
CN108429757A
CN108429757A CN201810250380.2A CN201810250380A CN108429757A CN 108429757 A CN108429757 A CN 108429757A CN 201810250380 A CN201810250380 A CN 201810250380A CN 108429757 A CN108429757 A CN 108429757A
Authority
CN
China
Prior art keywords
token
counter
website
climbs
guarding
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810250380.2A
Other languages
English (en)
Inventor
吴杨
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Digital Peak Technology Co Ltd
Chengdu Rui Code Technology Co Ltd
Original Assignee
Hangzhou Digital Peak Technology Co Ltd
Chengdu Rui Code Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Digital Peak Technology Co Ltd, Chengdu Rui Code Technology Co Ltd filed Critical Hangzhou Digital Peak Technology Co Ltd
Priority to CN201810250380.2A priority Critical patent/CN108429757A/zh
Publication of CN108429757A publication Critical patent/CN108429757A/zh
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/14Network architectures or network communication protocols for network security for detecting or protecting against malicious traffic
    • H04L63/1441Countermeasures against malicious traffic
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/04Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks
    • H04L63/0428Network architectures or network communication protocols for network security for providing a confidential data exchange among entities communicating through data packet networks wherein the data content is protected, e.g. by encrypting or encapsulating the payload
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/321Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving a third party or a trusted authority
    • H04L9/3213Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving a third party or a trusted authority using tickets or tokens, e.g. Kerberos
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3226Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using a predetermined code, e.g. password, passphrase or PIN
    • H04L9/3228One-time or temporary data, i.e. information which is sent for every authentication or authorization, e.g. one-time-password, one-time-token or one-time-key
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Hardware Design (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Storage Device Security (AREA)

Abstract

本发明公开了一种保护网站资源的反爬方法,该方法用户第一次Http请求访问资料时,网站服务器返回一系列资源文件;第二次Http请求申请访问资料的Token,网站服务器返回加密的Token;用户使用网站服务器返回的资源文件中包含的代码对Token进行解密和往Cookie中设置Token;使用解密的Token生成发出第三个Http请求的代码访问资料;网站服务器对Token进行合法性校验,通过后向用户返回访问资料的有效数据。本反顾不过通过加密的方式,让爬虫的访问效率比人的随机访问效率更低,迫使爬虫放弃抓取行为,从而从另一个维度保证了数据的独特性;同其他方案结合起来能达到最好的反爬效果。

Description

一种保护网站资源的反爬方法
技术领域
本发明涉及一种反爬方法,具体涉及一种保护网站资源的反爬方法,属于互联网技术领域。
背景技术
为保障网站上的数据具有独特性,网站管理员并不希望自己的数据被搜索引擎的网络爬虫抓取,也不希望数据被竞争对手的爬虫抓走用做竞品分析。所以希望能有一种技术,既不影响普通客户对网站的访问,又能避免自己的网站资源被竞争对手大范围的抓走。
当前反爬虫的常用技术有以下几种:
1、检测IP地址的访问频率;
2、检测用户行为是否存在周期性;
3、检测访问请求是否包含合法浏览器头。
这些方法能应对普通的爬虫行为,但均有简单的方法绕过,比如:
1、通过频繁更换IP地址来规避检测IP地址的访问频率的反爬方法;
2、通过在访问行为里面加随机行为进行干扰来规避检测用户行为是否存在周期性的反爬方法;
3、通过伪造浏览器头来规避检测访问请求是否包含合法浏览器头的反爬方法。
因此,研制一种有效弥补现有反爬技术的不足,通过加密的方式,让爬虫的访问效率比人的随机访问效率更低,从而从另一个维度保证了数据的独特性的反爬方法是非常必要的,并且该发明也有重要的应用前景。
发明内容
本发明针对现有技术的弊端,公开了一种通过加密的方式,让爬虫的访问效率比人的随机访问效率更低,从而从另一个维度保证了数据的独特性的反爬方法。
为了实现上述目标,本发明所采用的技术方案是:
一种保护网站资源的反爬方法,包括以下步骤:
S1、用户第一次Http请求访问资料时,网站服务器返回一系列资源文件,执行步骤S2;
S2、第二次Http请求申请访问资料的Token,网站服务器返回加密的Token,执行步骤S3;
S3、用户使用所述步骤S1中网站服务器返回的资源文件中包含的代码对所述步骤S2中网站服务器返回的Token进行解密和往Cookie中设置Token,执行步骤S4;
S4、使用解密的Token生成发出第三个Http请求的代码访问资料,执行步骤S5;
S5、网站服务器对Token进行合法性校验,通过后向用户返回访问资料的有效数据。
前述的保护网站资源的反爬方法,所述步骤S1中,网站服务器返回的资源文件中包含的用于解密所述步骤S2中Token的代码由JavaScript编写。
前述的保护网站资源的反爬方法,所述步骤S2中,Token在使用一次后失效。
前述的保护网站资源的反爬方法,所述步骤S2中,Token的加密方法是,将Token和往Cookie中设置Token的Javascript语句全部用ASCII码对应的十六进制数表示,然后在这些ASCII代码中每隔M个字符加入随机字符,再每隔N个字符加入随机字符。
前述的保护网站资源的反爬方法,加密过程迭代若干次。
前述的保护网站资源的反爬方法,M,N定期更换。
前述的保护网站资源的反爬方法,所述步骤S4中,第三个Http请求的代码所使用的加密方法是,代码用ASCII码对应的十六进制表示,且每隔H个字符加入随机字符,存储在一个独立的JavaScript文件。
前述的保护网站资源的反爬方法,JavaScript文件加入冗余字符。
前述的保护网站资源的反爬方法,JavaScript文件压缩保存。
与现有技术相比,本发明的有益之处在于:
(1)通过加密的方式,让爬虫的访问效率比人的随机访问效率更低,迫使爬虫放弃抓取行为,从而从另一个维度保证了数据的独特性;
(2)同其他方案结合起来能达到最好的反爬效果。
附图说明
图1是本发明的保护网站资源的反爬方法的流程示意图。
具体实施方式
以下结合附图和具体实施例对本发明作具体的介绍。
参照图1,本发明的保护网站资源的反爬方法,包括以下步骤:
S1、用户第一次Http请求访问资料时,网站服务器返回一系列资源文件,执行步骤S2;资源文件中包含一定的冗余数据,造成爬虫难以识别有效的代码在哪里。
S2、第二次Http请求申请访问资料的Token,网站服务器返回加密的Token,执行步骤S3;
S3、用户使用所述步骤S1中网站服务器返回的资源文件中包含的代码对所述步骤S2中网站服务器返回的Token进行解密和往Cookie中设置Token,执行步骤S4;
S4、使用解密的Token生成发出第三个Http请求的代码访问资料,执行步骤S5;
S5、网站服务器对Token进行合法性校验,通过后向用户返回访问资料的有效数据。
作为一种优选的方案,步骤S1中,网站服务器返回的资源文件中包含的用于解密步骤S2中Token的代码由JavaScript编写。
作为一种优选的方案,步骤S2中,Token在使用一次后失效,可以避免token被爬虫识别后,反复使用。
作为一种优选的方案,步骤S2中,Token的加密方法是,将Token和往Cookie中设置Token的Javascript语句全部用ASCII码对应的十六进制数表示,然后在这些ASCII代码中每隔M个字符加入随机字符,再每隔N个字符加入随机字符。
作为一种更加优选的方案,加密过程迭代若干次。
作为一种更加优选的方案,M,N定期更换,可以让爬虫难以发现规律,进而无从破解。
作为一种优选的方案,步骤S4中,第三个Http请求的代码所使用的加密方法是,代码用ASCII码对应的十六进制表示,且每隔H个字符加入随机字符,存储在一个独立的JavaScript文件。
作为一种更加优选的方案,JavaScript文件加入冗余字符。
作为一种更加优选的方案,JavaScript文件压缩保存,压缩之后,难以阅读,保护了解密算法不被破解。
综上所述,本发明的保护网站资源的反爬方法,通过加密的方式,让爬虫的访问效率比人的随机访问效率更低,迫使爬虫放弃抓取行为从而从另一个维度保证了数据的独特性,同其他方案结合起来能达到最好的反爬效果。
需要说明的是,以上所述仅为本发明的较佳实施例,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。

Claims (9)

1.一种保护网站资源的反爬方法,其特征在于,包括以下步骤:
S1、用户第一次Http请求访问资料时,网站服务器返回一系列资源文件,执行步骤S2;
S2、第二次Http请求申请访问资料的Token,网站服务器返回加密的Token,执行步骤S3;
S3、用户使用所述步骤S1中网站服务器返回的资源文件中包含的代码对所述步骤S2中网站服务器返回的Token进行解密和往Cookie中设置Token,执行步骤S4;
S4、使用解密的Token生成发出第三个Http请求的代码访问资料,执行步骤S5;
S5、网站服务器对Token进行合法性校验,通过后向用户返回访问资料的有效数据。
2.根据权利要求1所述的保护网站资源的反爬方法,其特征在于,所述步骤S1中,网站服务器返回的资源文件中包含的用于解密所述步骤S2中Token的代码由JavaScript编写。
3.根据权利要求1所述的保护网站资源的反爬方法,其特征在于,所述步骤S2中,Token在使用一次后失效。
4.根据权利要求1所述的保护网站资源的反爬方法,其特征在于,所述步骤S2中,Token的加密方法是,将Token和往Cookie中设置Token的Javascript语句全部用ASCII码对应的十六进制数表示,然后在这些ASCII代码中每隔M个字符加入随机字符,再每隔N个字符加入随机字符。
5.根据权利要求4所述的保护网站资源的反爬方法,其特征在于,加密过程迭代若干次。
6.根据权利要求4所述的保护网站资源的反爬方法,其特征在于,M,N定期更换。
7.根据权利要求1所述的保护网站资源的反爬方法,其特征在于,所述步骤S4中,第三个Http请求的代码所使用的加密方法是,代码用ASCII码对应的十六进制表示,且每隔H个字符加入随机字符,存储在一个独立的JavaScript文件。
8.根据权利要求7所述的保护网站资源的反爬方法,其特征在于,JavaScript文件加入冗余字符。
9.根据权利要求7所述的保护网站资源的反爬方法,其特征在于,JavaScript文件压缩保存。
CN201810250380.2A 2018-03-26 2018-03-26 一种保护网站资源的反爬方法 Pending CN108429757A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810250380.2A CN108429757A (zh) 2018-03-26 2018-03-26 一种保护网站资源的反爬方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810250380.2A CN108429757A (zh) 2018-03-26 2018-03-26 一种保护网站资源的反爬方法

Publications (1)

Publication Number Publication Date
CN108429757A true CN108429757A (zh) 2018-08-21

Family

ID=63159135

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810250380.2A Pending CN108429757A (zh) 2018-03-26 2018-03-26 一种保护网站资源的反爬方法

Country Status (1)

Country Link
CN (1) CN108429757A (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111901332A (zh) * 2020-07-27 2020-11-06 北京百川盈孚科技有限公司 网页内容反爬方法及系统

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090094372A1 (en) * 2007-10-05 2009-04-09 Nyang Daehun Secret user session managing method and system under web environment, recording medium recorded program executing it
US9075990B1 (en) * 2014-07-01 2015-07-07 Shape Security, Inc. Reliable selection of security countermeasures
CN105577701A (zh) * 2016-03-09 2016-05-11 携程计算机技术(上海)有限公司 网络爬虫的识别方法及系统
CN105812366A (zh) * 2016-03-14 2016-07-27 携程计算机技术(上海)有限公司 服务器、反爬虫系统和反爬虫验证方法
CN107733633A (zh) * 2017-09-22 2018-02-23 成都知道创宇信息技术有限公司 一种基于算力的防爬虫方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090094372A1 (en) * 2007-10-05 2009-04-09 Nyang Daehun Secret user session managing method and system under web environment, recording medium recorded program executing it
US9075990B1 (en) * 2014-07-01 2015-07-07 Shape Security, Inc. Reliable selection of security countermeasures
CN105577701A (zh) * 2016-03-09 2016-05-11 携程计算机技术(上海)有限公司 网络爬虫的识别方法及系统
CN105812366A (zh) * 2016-03-14 2016-07-27 携程计算机技术(上海)有限公司 服务器、反爬虫系统和反爬虫验证方法
CN107733633A (zh) * 2017-09-22 2018-02-23 成都知道创宇信息技术有限公司 一种基于算力的防爬虫方法

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111901332A (zh) * 2020-07-27 2020-11-06 北京百川盈孚科技有限公司 网页内容反爬方法及系统

Similar Documents

Publication Publication Date Title
Hong et al. How you get shot in the back: A systematical study about cryptojacking in the real world
Plohmann et al. A comprehensive measurement study of domain generating malware
Torroledo et al. Hunting malicious TLS certificates with deep neural networks
CN104166822B (zh) 一种数据保护的方法和装置
Caballero et al. Input generation via decomposition and re-stitching: Finding bugs in malware
Ciampa et al. A heuristic-based approach for detecting SQL-injection vulnerabilities in Web applications
JP6527590B2 (ja) オフライン・ネットワーク・トラフィックに基づいてカバート・チャネルのネットワーク侵入を検出するためのシステムおよび方法
Gu et al. DIAVA: a traffic-based framework for detection of SQL injection attacks and vulnerability analysis of leaked data
Van Gundy et al. Catch Me, If You Can: Evading Network Signatures with Web-based Polymorphic Worms.
Borgolte et al. Delta: automatic identification of unknown web-based infection campaigns
US9152808B1 (en) Adapting decoy data present in a network
US20140281535A1 (en) Apparatus and Method for Preventing Information from Being Extracted from a Webpage
Nagpal et al. A survey on the detection of SQL injection attacks and their countermeasures
Kar et al. Prevention of SQL Injection attack using query transformation and hashing
Taylor et al. Detecting malicious exploit kits using tree-based similarity searches
US9092782B1 (en) Methods and apparatus for risk evaluation of compromised credentials
Abirami et al. A top web security vulnerability SQL injection attack—Survey
CN110807187B (zh) 一种基于区块链的网络市场违法信息存证方法及平台端
Zhang et al. Privacy‐assured substructure similarity query over encrypted graph‐structured data in cloud
Pramono Anomaly-based intrusion detection and prevention system on website usage using rule-growth sequential pattern analysis: Case study: Statistics of Indonesia (BPS) website
CN108429757A (zh) 一种保护网站资源的反爬方法
Snyder et al. Cloudsweeper: enabling data-centric document management for secure cloud archives
CN107276967A (zh) 一种分布式系统及其登录验证方法
CN108810032A (zh) 一种基于代理的Web跨站安全处理方法
CN114401117A (zh) 基于区块链的账户登录验证系统

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20180821

RJ01 Rejection of invention patent application after publication