用 HAX.co.id 作为备份通道,绕过GFW封锁,SSH登录目标VPS
在翻墙还成功的时候,注册一个 HAX 的账户 (需要Telegram ID)
如果我们的VPS被封IP了,或封22端口了,可以通过 HAX 跳板登录我们的VPS
1. 注册HAX账户
访问 https://hax.co.id/ 点击“Register”
https://hax.co.id/register
3. 开通VPS
点击 "VPS" - "Create VPS"
https://hax.co.id/create-vps/
https://hax.co.id/vps-info
把你的 VPS 的 IPv6 地址记下来
但是这个 VPS 只有 IPv6,如果你的网络环境和我一样只有 IPv4 那么,
要么直接使用 Web Terminal https://hax.co.id/terminal 接下来看第6步。
要么还要搭个桥。
4. 设置IPv4转IPv6
点击 IPv4 to IPv6
https://hax.co.id/ipv6-to-ipv4/
From IP Address 选一个你在自己电脑上能 ping 得通的,Port 随便选。
协议选 TCP (SSH 是走 TCP 的)
To IPv6 Address 填你的 VPS 的地址,Port 填22(SSH的端口)
提交之后,有可能会失败。你换个 From 的 IP 和 Port,再试一次。
成功是这个样子的。
这一步我们建立了一个端口转发,从 91.134.238.133 的 4387端口转发到 2001:41d0:8:824f:22:d9e4:90a3:1的22端口。(蓝色部分是举例,以你自己的端口转发设置为准)
意思是,所有连接到91.134.238.133 的 4387端口的TCP包,转发到2001:41d0:8:824f:22:d9e4:90a3:1的22端口。反过来也是如此。
5. 登录HAX的VPS
在你的SSH工具上(推荐 Xshell)新建一个会话,IP填上一步(第4步)的From IP (例: 91.134.238.133),端口填上一步(第4步)的 From 的端口 (例: 4387),用户名 root,密码是你第3步开通 VPS 时输入的root密码。
举例:
如果不成功,检查IP地址能否ping通。进一步地,tcping检查 IP地址和端口通不通。
如果IP地址和端口不通,返回上一步新建 IPv4 to IPv6 通道。
6. 安装warp IPv4出口
现在要用 IPv4 去访问我们的被封锁的 目标VPS了。安装 warp ,相当于添加一个 IPv4 "网口"。
apt install -y bash curlbash <(curl -fsSL git.io/warp.sh) 4
脚本跑完了用 ifconfig 检查一下是不是多出来一个wgcf的“网口”
ping 一下我们的目标VPS的IP地址。是否正常了?
7. 登录我们的VPS
从HAX 的 VPS 的命令行 SSH 登录我们的目标 VPS
ssh 目标VPS的IP地址
出现 Are you sure you want to continue connecting (yes/no/[fingerprint])? 的时候,输入yes 回车。
输入 root 密码的时候可以粘贴,输入密码是不显示的,输完按回车就是了。
8. 用 Cloudflare Worker 反代 hax.co.id 防止被墙
在Cloudflare里新建一个Worker把左边脚本框里面原来的内容全部删掉。打开这个页面,把内容复制粘贴到Worker的脚本框里。
https://github.com/EtherDream/jsproxy/blob/master/cf-worker/index.js
https://github.com/EtherDream/jsproxy/blob/master/cf-worker/index.js
浏览器访问你的worker的域名,把 https://hax.co.id/ 填进去然后点 "GO"
-----------------------
完
'use strict'/*** static files (404.html, sw.js, conf.js)*/const ASSET_URL = 'https://etherdream.github.io/jsproxy'const JS_VER = 10const MAX_RETRY = 1/** @type {RequestInit} */const PREFLIGHT_INIT = {status: 204,headers: new Headers({'access-control-allow-origin': '*','access-control-allow-methods': 'GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS','access-control-max-age': '1728000',}),}/*** @param {any} body* @param {number} status* @param {Object<string, string>} headers*/function makeRes(body, status = 200, headers = {}) {headers['--ver'] = JS_VERheaders['access-control-allow-origin'] = '*'return new Response(body, {status, headers})}/*** @param {string} urlStr*/function newUrl(urlStr) {try {return new URL(urlStr)} catch (err) {return null}}addEventListener('fetch', e => {const ret = fetchHandler(e).catch(err => makeRes('cfworker error:\n' + err.stack, 502))e.respondWith(ret)})/*** @param {FetchEvent} e*/async function fetchHandler(e) {const req = e.requestconst urlStr = req.urlconst urlObj = new URL(urlStr)const path = urlObj.href.substr(urlObj.origin.length)if (urlObj.protocol === 'http:') {urlObj.protocol = 'https:'return makeRes('', 301, {'strict-transport-security': 'max-age=99999999; includeSubDomains; preload','location': urlObj.href,})}if (path.startsWith('/http/')) {return httpHandler(req, path.substr(6))}switch (path) {case '/http':return makeRes('请更新 cfworker 到最新版本!')case '/ws':return makeRes('not support', 400)case '/works':return makeRes('it works')default:// static filesreturn fetch(ASSET_URL + path)}}/*** @param {Request} req* @param {string} pathname*/function httpHandler(req, pathname) {const reqHdrRaw = req.headersif (reqHdrRaw.has('x-jsproxy')) {return Response.error()}// preflightif (req.method === 'OPTIONS' &&reqHdrRaw.has('access-control-request-headers')) {return new Response(null, PREFLIGHT_INIT)}let acehOld = falselet rawSvr = ''let rawLen = ''let rawEtag = ''const reqHdrNew = new Headers(reqHdrRaw)reqHdrNew.set('x-jsproxy', '1')// 此处逻辑和 http-dec-req-hdr.lua 大致相同// https://github.com/EtherDream/jsproxy/blob/master/lua/http-dec-req-hdr.luaconst refer = reqHdrNew.get('referer')const query = refer.substr(refer.indexOf('?') + 1)if (!query) {return makeRes('missing params', 403)}const param = new URLSearchParams(query)for (const [k, v] of Object.entries(param)) {if (k.substr(0, 2) === '--') {// 系统信息switch (k.substr(2)) {case 'aceh':acehOld = truebreakcase 'raw-info':[rawSvr, rawLen, rawEtag] = v.split('|')break}} else {// 还原 HTTP 请求头if (v) {reqHdrNew.set(k, v)} else {reqHdrNew.delete(k)}}}if (!param.has('referer')) {reqHdrNew.delete('referer')}// cfworker 会把路径中的 `//` 合并成 `/`const urlStr = pathname.replace(/^(https?):\/+/, '$1://')const urlObj = newUrl(urlStr)if (!urlObj) {return makeRes('invalid proxy url: ' + urlStr, 403)}/** @type {RequestInit} */const reqInit = {method: req.method,headers: reqHdrNew,redirect: 'manual',}if (req.method === 'POST') {reqInit.body = req.body}return proxy(urlObj, reqInit, acehOld, rawLen, 0)}/**** @param {URL} urlObj* @param {RequestInit} reqInit* @param {number} retryTimes*/async function proxy(urlObj, reqInit, acehOld, rawLen, retryTimes) {const res = await fetch(urlObj.href, reqInit)const resHdrOld = res.headersconst resHdrNew = new Headers(resHdrOld)let expose = '*'for (const [k, v] of resHdrOld.entries()) {if (k === 'access-control-allow-origin' ||k === 'access-control-expose-headers' ||k === 'location' ||k === 'set-cookie') {const x = '--' + kresHdrNew.set(x, v)if (acehOld) {expose = expose + ',' + x}resHdrNew.delete(k)}else if (acehOld &&k !== 'cache-control' &&k !== 'content-language' &&k !== 'content-type' &&k !== 'expires' &&k !== 'last-modified' &&k !== 'pragma') {expose = expose + ',' + k}}if (acehOld) {expose = expose + ',--s'resHdrNew.set('--t', '1')}// verifyif (rawLen) {const newLen = resHdrOld.get('content-length') || ''const badLen = (rawLen !== newLen)if (badLen) {if (retryTimes < MAX_RETRY) {urlObj = await parseYtVideoRedir(urlObj, newLen, res)if (urlObj) {return proxy(urlObj, reqInit, acehOld, rawLen, retryTimes + 1)}}return makeRes(res.body, 400, {'--error': `bad len: ${newLen}, except: ${rawLen}`,'access-control-expose-headers': '--error',})}if (retryTimes > 1) {resHdrNew.set('--retry', retryTimes)}}let status = res.statusresHdrNew.set('access-control-expose-headers', expose)resHdrNew.set('access-control-allow-origin', '*')resHdrNew.set('--s', status)resHdrNew.set('--ver', JS_VER)resHdrNew.delete('content-security-policy')resHdrNew.delete('content-security-policy-report-only')resHdrNew.delete('clear-site-data')if (status === 301 ||status === 302 ||status === 303 ||status === 307 ||status === 308) {status = status + 10}return new Response(res.body, {status,headers: resHdrNew,})}/*** @param {URL} urlObj*/function isYtUrl(urlObj) {return (urlObj.host.endsWith('.googlevideo.com') &&urlObj.pathname.startsWith('/videoplayback'))}/*** @param {URL} urlObj* @param {number} newLen* @param {Response} res*/async function parseYtVideoRedir(urlObj, newLen, res) {if (newLen > 2000) {return null}if (!isYtUrl(urlObj)) {return null}try {const data = await res.text()urlObj = new URL(data)} catch (err) {return null}if (!isYtUrl(urlObj)) {return null}return urlObj}
评论
发表评论