page 121
Sunday, May 22, 2022
[反爬蟲原理與繞過實戰] Cookie 與 JavaScript 結合
假设访问网站/verify/cookie/content.html必须携带一个符合规定的 cookie,如果cookie不符合规定,则会被重定向到/verify/cookie/index.html去设置一个cookie,有了cookie后才能继续访问content.html。
这种方法很常见,就好比淘宝,在访问其商品列表页面前,必须登录且信息无误后才能继续访问,这种方法不仅能增加用户数,还能实现反爬。
反爬
我起初猜测它可能是这样实现的:在content.html加入一段JavaScript代码,使其能获取请求头中的cookie并判断是否符合规定,如果不符合则重定向到index.html,然后在index.html内插入一些JavaScript算法来生成cookie。
content.html
========================================================================
<body>
<h1>This is cookie/content.html</h1>
<script>
var reg = /auth=[0-9]{3}[A-Z]{5}[0-9]{6}[A-Z]{3}/
// 如果Cookie不符合要求,则跳转到首页
if (reg.test(document.cookie) != true) {
location.href = './index.html';
}
</script>
</body>
========================================================================
用浏览器测试了一下,确实可以实现重定向的操作,但是还是会先访问content.html。这种做法只能起到增长用户的目的,并不能实现反爬虫,因为python是没有JavaScript解释器的,它不会解析js代码,对于这种页面还是照爬无误。
所以还是得靠nginx,继续修改一下配置
========================================================================
location /verify/cookie/index.html {
root /home/pineapple/Code/WebProject/www;
index index.html;
}
location /verify/cookie/content.html {
if ($http_cookie !~* "auth=[0-9]{3}[A-Z]{5}[0-9]{6}[A-Z]{3}") {
rewrite content.html ./index.html redirect;
}
root /home/pineapple/Code/WebProject/www;
index content.html;
}
========================================================================
為了在重定向后给客户端设置cookie,需要在index.html里加入JavaScript代码
進行測試會發現 Cookie 值是隨機變化的
========================================================================
<!--
* @Date : 2020-10-22 22:38:37
* @LastEditors : Pineapple
* @LastEditTime : 2020-10-23 17:30:20
* @FilePath : /www/verify/cookie/index.html
* @Blog : https://blog.csdn.net/pineapple_C
* @Github : https://github.com/Pineapple666
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>This is cookie/index.html</h1>
<h1><a href="./content.html">Go to cookie/content.html</a></h1>
<script id="random cookie">
function randcookie() {
// 生成随机字符串用作cookie值
var header = randints(9, 3, 0);
var middle = randstrs(5);
var footer = randints(9, 6, 0);
var pp = randstrs(3);
var res = header + middle + footer + pp
return res;
}
function randints(r, n, tof) {
/* 生成随机数字,tof决定返回number类型或者字符串类型
r 代表数字范围 n 代表数量
*/
var result = [];
if (tof) {
return Math.floor(Math.random() * r);
}
for (var i = 0; i < n; i++) {
s = Math.floor(Math.random() * r);
result.push(s);
}
return result.join('');
}
function randstrs(n) {
// 生成随机字母,n为随机字母的数量
var result = [];
for (var i = 0; i < n; i++) {
s = String.fromCharCode(65 + randints(25, 1, 1));
result.push(s);
}
return result.join('');
}
// 设置Cookie
document.cookie = 'auth=' + randcookie();
</script>
</body>
</html>
========================================================================
Saturday, May 21, 2022
[爬蟲與反爬蟲] 反爬蟲原理與繞過實戰
反爬蟲
1. User-Agent 反爬蟲繞過實戰 详解用User-Agent进行反爬虫的原理和绕过 (403 error)
2. Cookie 反爬蟲 (200 但空的)
3. 签名验证反爬虫的原理和绕过方法 (403 error)
引數 static/md5.js 和 static/sign.js 相關關鍵字
4. 签名验证反爬虫的原理和绕过方法 (透過 Tornado)
7. WebSocket握手验证反爬虫
Sunday, May 8, 2022
[Architecture] 制定设计策略
在 Architecting: How Much and When 書中,Barry Boehm 證明開發、架構設計、返工是構成項目工期的三個主要部分。
在 Using Risk to Balance Agile and Plan-Driven Methods 書中,Boehm 和 Richard Turner 建議用風險決定何時關注架構。
[Architecture] 設計思維基礎
一、設計思維的四條原則
以人为本(human)
推迟决策(ambiguity)
善于借鉴(redesign)
化虚为实(tangibility)
以人为本
设计的本质是社交。
尊重所有直接和间接与架构有关的人,换位思考,理解他们的感受。
推迟决策
推迟不确定的决策。
模糊的需求、设计、承诺会毁掉项目。不到条件成熟的最后一刻,不要着急做出最终的设计决策。
不影响质量属性和交付进度的设计决策可以放到架构设计之外。
善于借鉴
所有的设计都是在已有设计基础上的重新设计和调整创新。
留心琢磨熟悉的事物——研究以往的设计,探索其中的规律。
多花点时间研究已有的设计,而不是凭空创造一个新的出来。
化虚为实
让想法具体化、有形化,以便于沟通交流。
代码不适合用来讨论质量属性、组件、设计原则、决策结果之类的问题。
二、運用思維模式
思维模式分为:理解、探索、展示、评估
理解问题
主动获取信息,清晰描述问题,理解对方需求,掌握团队风格
探索想法
尝试各种结构的组合,直到找到最能提升目标质量属性的那种组合。
寻找各种解决问题的模式、技术、方案。
展示想法
展示想法不仅是为了分享,也是为了检验合理性。
可以用线框图、编写文档、展示数据等方法。
对系统进行建模。
评估适用性
可以针对不同的场景审视某一块架构,还可以通过实验,或者通过检查决策风险来展开评估。
三、思考(Think)、动手(Do)、检查(Check)
TDC 循环
n8n index
【n8n免費本地端部署】Windows版|程式安裝x指令大補帖 【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能
-
#include <iostream> using namespace std; struct X { // member binary operator void operator*(int) { cout << "void...
-
while true; do ps -eo pid,ppid,cmd,%mem,%cpu --sort -pcpu,+pmem ps -eo pid,ppid,%mem,%cpu --sort -pcpu,+pmem | awk '{if ($3!=0){total1...
-
#!/bin/sh # Define the process name process_name=rsyslogd # Get minimum number of threads from command line parameters process_min_threads=...