Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from jianjianai/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jianjianai authored Jun 18, 2024
2 parents 340514f + cde761b commit 2ca3d1d
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 86 deletions.
237 changes: 175 additions & 62 deletions src/html/ChallengeResponseBody.html
Original file line number Diff line number Diff line change
@@ -1,96 +1,209 @@
<html>

<head>
<script type="text/javascript">
async function ChallengeComplete() {
const IG = window.parent._G.IG;
const convId = window.parent.CIB.manager.conversation.id;
const rid = window.parent.CIB.manager.conversation.messages[0].requestId;
const iframeid = new URL(window.location.href).searchParams.get('iframeid');
const T = await window.parent.aesEncrypt('Harry-zklcdc/go-proxy-bingai',IG);

await fetch('/challenge/verify?IG=' + encodeURI(IG) + '&iframeid=' + encodeURI(iframeid) + '&convId=' + encodeURI(convId) + '&rid=' + encodeURI(rid) + '&T=' + encodeURI(T), {
credentials: 'include',
}).then((res) => {
if (res.ok) {
window.parent.postMessage("verificationComplete", "*");
} else {
<script type="text/javascript">
(() => {
const verify = async () => {
const IG = window.parent._G.IG;
const convId = window.parent.CIB.manager.conversation.id;
const rid = window.parent.CIB.manager.conversation.messages[0].requestId;
const iframeid = new URL(window.location.href).searchParams.get('iframeid');
const TA = 'Harry-zklcdc/go-proxy-bingai';//Harry-zklcdc这是验证通过的功能作者哦,本项目和go-proxy-bingai使用的相同的验证通过技术Harry-zklcdc/go-bingai-pass。
const T = await window.parent.aesEncrypt(TA, IG);
const params = new URLSearchParams();
params.append("IG", IG);
params.append("iframeid", iframeid);
params.append("convId", convId);
params.append("rid", rid);
params.append("T", T);
const res = await fetch('/challenge/verify?' + params, { credentials: 'include' });
if (!res.ok) {
if (res.status === 451) {
const verifyContainer = document.getElementById('verifyContainer');
verifyContainer.innerHTML = '';
let newElement = document.createElement('h4');
newElement.textContent = "您似乎是盗版软件受害者,该项目在 Github 开源。"
verifyContainer.appendChild(newElement);
throw "您似乎是盗版软件受害者,该项目在 Github 开源。"
} else {
window.parent.postMessage("verificationFailed", "*");
throw await res.text();
}
}
}).catch(() => {
window.parent.postMessage("verificationFailed", "*");
const rjson = await res.text();
if(rjson.indexOf("cct=")<0){
throw "Harry-zklcdc/go-bingai-pass 服务器似乎没有正常工作!请检查BYPASS_SERVER环境变量是否正确配置。";
}
}
window.addEventListener("load",async ()=>{
const successDIV = document.getElementById("success");
const verifyingDIV = document.getElementById("verifying");
const failDIV = document.getElementById("fail");
const errorText = document.getElementById("error-text");
await new Promise((t)=>setTimeout(t,1000));
try{
await verify();
}catch(error){
console.error("verify error",error);
verifyingDIV.style.display = "none";
failDIV.style.display = "flex";
errorText.innerText = error;
errorText.style.display = "block";
setTimeout(()=>location.reload(),5000);
return;
}
verifyingDIV.style.display = "none";
successDIV.style.display = "flex";
setTimeout(()=>window.parent.postMessage("verificationComplete", "*"),2000);
});
}
window.onload = ChallengeComplete;
})();
</script>
<style>
.n-base-loading {
position: relative;
line-height: 0;
width: 1em;
height: 1em;
.verifyContainer {
display: flex;
align-items: center;
gap: 12px;
width: 300px;
height: 63px;
background-color: #fafafa;
border: 1px solid #e0e0e0;
padding: 0 10px;
}

.n-spin {
display: inline-flex;
height: var(--n-size);
width: var(--n-size);
font-size: var(--n-size);
color: var(--n-color);
#success-icon {
display: flex;
margin-right: 8px;
border-radius: 50%;
box-shadow: inset 0 0 0 #038127;
width: 30px;
height: 30px;
animation: scale-up-center 0.6s cubic-bezier(0.55, 0.085, 0.68, 0.53) both;
stroke-width: 6px;
stroke: #f8f8f8;
stroke-miterlimit: 10;
}

@keyframes spin {
#spinner-icon {
display: flex;
margin-right: 8px;
width: 30px;
height: 30px;
animation: rotate 5s linear infinite;
}

@keyframes rotate {
100% {
transform: rotate(360deg);
}
}

@keyframes scale-up-center {
0% {
transform: rotate(0deg);
transform: scale(0.01);
}

100% {
transform: rotate(360deg);
transform: scale(1);
}
}

.verifyContainer {
.circle {
stroke-width: 3px;
stroke-linecap: round;
stroke: #000000;
stroke-dasharray: 0, 100, 0;
stroke-dashoffset: 200;
stroke-miterlimit: 1;
stroke-linejoin: round;
}

.success-circle {
stroke-dashoffset: 0;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #1d1f20;
fill: #1d1f20;
}

.cb-container {
display: flex;
align-items: center;
gap: 12px;
margin-left: 11px;
}

#fail-icon {
display: flex;
margin-right: 8px;
border-radius: 50%;
width: 30px;
height: 30px;
stroke-width: 6px;
stroke: #f8f8f8;
stroke-miterlimit: 10;
box-shadow: inset 0 0 0 #1d1f20;
animation: fillfail-offlabel 0.4s ease-in-out 0.4s forwards, scale 0.3s ease-in-out 0.9s both;
}

.failure-circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #1d1f20;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

@keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}

@keyframes fillfail-offlabel {
100% {
box-shadow: inset 0 0 0 30px #1d1f20;
}
}
</style>
</head>

<body>
<p id="error-text" style="font-size: 10px;margin: 0;border: 0;color: red;display: none;"></p>
<div id="verifyContainer" class="verifyContainer">
<div class="n-base-loading n-spin" role="img" aria-label="loading"
style="--n-bezier: cubic-bezier(.4, 0, .2, 1); --n-opacity-spinning: 0.5; --n-size: 40px; --n-color: #2080f0; --n-text-color: #18a058;"
style="width: 48px">
<div class="n-base-loading__transition-wrapper" style="width: 48px">
<div class="n-base-loading__container">
<svg class="n-base-loading__icon" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<g>
<animateTransform attributeName="transform" type="rotate" values="0 100 100;270 100 100"
begin="0s" dur="1.6s" fill="freeze" repeatCount="indefinite"></animateTransform>
<circle class="n-base-loading__icon" fill="none" stroke="currentColor" stroke-width="16"
stroke-linecap="round" cx="100" cy="100" r="92" stroke-dasharray="567"
stroke-dashoffset="1848">
<animateTransform attributeName="transform" type="rotate"
values="0 100 100;135 100 100;450 100 100" begin="0s" dur="1.6s" fill="freeze"
repeatCount="indefinite"></animateTransform>
<animate attributeName="stroke-dashoffset" values="567;142;567" begin="0s" dur="1.6s"
fill="freeze" repeatCount="indefinite"></animate>
</circle>
</g>
</svg>
</div>
<div id="success" class="cb-container" style="display: none;align-items: center; visibility: visible;"
role="alert">
<svg id="success-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52" aria-hidden="true">
<circle class="success-circle" cx="26" cy="26" r="25"></circle>
<path class="p1" d="m13,26l9.37,9l17.63,-18"></path>
</svg>
<span id="success-text">成功!</span>
</div>
<div id="verifying" class="cb-container" style="display: flex; visibility: visible;align-items: center;">
<svg id="spinner-icon" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"
class="">
<line x1="15" x2="15" y1="1.5" y2="5.5" class="circle"></line>
<line x1="24.5459" x2="24.5459" y1="5.45405" y2="10.45405" transform="rotate(45 24.5459 5.45405)"
class="circle"></line>
<line x1="28.5" x2="28.5" y1="15" y2="20" transform="rotate(90 28.5 15)" class="circle"></line>
<line x1="24.5459" x2="24.5459" y1="24.546" y2="29.546" transform="rotate(135 24.5459 24.546)"
class="circle"></line>
<line x1="15" x2="15" y1="28.5" y2="33.5" transform="rotate(180 15 28.5)" class="circle"></line>
<line x1="5.4541" x2="5.4541" y1="24.5459" y2="29.5459" transform="rotate(-135 5.4541 24.5459)"
class="circle"></line>
<line x1="1.5" x2="1.5" y1="15" y2="20" transform="rotate(-90 1.5 15)" class="circle"></line>
<line x1="5.45408" x2="5.45408" y1="5.45404" y2="10.45404" transform="rotate(-45 5.45408 5.45404)"
class="circle"></line>
</svg>
<div id="verifying-msg">
<span id="verifying-text">人机验证中...</span>
</div>
</div>
<div id="fail" class="cb-container" style="display: none; visibility: visible;" role="alert">
<svg id="fail-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52" aria-hidden="true">
<circle class="failure-circle" cx="26" cy="26" r="25" fill="none"></circle>
<path class="failure-cross" fill="none" d="M14.1 27.2 l24.124.2"></path>
</svg>
<div id="failure-msg">
<span id="fail-text">失败!</span>
<br><span id="fr-helper"><a href="https://github.com/Harry-zklcdc/go-bingai-pass"
id="fr-helper-link">遇到问题?</a></span>
</div>
</div>
<h4>自动通过人机验证中<br>请耐心等待...</h4>
</div>
</body>

Expand Down
40 changes: 22 additions & 18 deletions src/proxy/bingPorxyWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const bingProxyLink = newProxyLinkHttp<Env>({
if (reqUrl.pathname == "/challenge/verify") {
return verify(req,env);
}
//客户端请求验证接口
if(reqUrl.pathname == '/turing/captcha/challenge' && (!reqUrl.searchParams.has('h'))){
return new Response(ChallengeResponseBody,{
headers:{
Expand All @@ -77,19 +78,17 @@ const bingProxyLink = newProxyLinkHttp<Env>({
return null;
},
async reqTranslator(config, req, env) {//修改请求
const url = new URL(config.url);
config.url = url;
{ //基础转换
url.port = ""
url.protocol = 'https:';
config.url.port = ""
config.url.protocol = 'https:';
config.init.headers = new Headers(config.init.headers);
}

{//重定向请求
const p = url.pathname;
const p = config.url.pathname;
//sydney的请求
if (p.startsWith("/sydney/")) {
url.hostname = "sydney.bing.com";//设置链接
config.url.hostname = "sydney.bing.com";//设置链接
}
//copilot的请求
if (
Expand All @@ -115,11 +114,11 @@ const bingProxyLink = newProxyLinkHttp<Env>({
p.startsWith("/pwa/") ||
p.startsWith("/videos/")
) {
url.hostname = "copilot.microsoft.com"
config.url.hostname = "copilot.microsoft.com"
}
// bing请求
if (p.startsWith("/opaluqu/")) {
url.hostname = "www.bing.com"
config.url.hostname = "www.bing.com"
}
// login请求
if (
Expand All @@ -131,23 +130,23 @@ const bingProxyLink = newProxyLinkHttp<Env>({
p == "/GetExperimentAssignments.srf" ||
p == "/logout.srf"
) {
url.hostname = "login.live.com"
config.url.hostname = "login.live.com"
}
// login account请求
if(
p.startsWith("/proofs/") ||
p=="/SummaryPage.aspx"
){
url.hostname = "account.live.com"
config.url.hostname = "account.live.com"
}
//storage请求
if (p.startsWith("/users/") ) {
url.hostname = "storage.live.com"
config.url.hostname = "storage.live.com"
}
//bing验证请求
if(p=='/turing/captcha/challenge'){
url.hostname = "www.bing.com";
url.searchParams.delete('h');
config.url.hostname = "www.bing.com";
config.url.searchParams.delete('h');
}
}

Expand All @@ -160,7 +159,7 @@ const bingProxyLink = newProxyLinkHttp<Env>({
const resHeaders = config.init.headers as Headers;
const origin = resHeaders.get('Origin');
if (origin) {
const url = config.url as URL;
const url = config.url;
const originUrl = new URL(origin);
originUrl.protocol = "https:";
originUrl.port = '';
Expand Down Expand Up @@ -199,6 +198,7 @@ const bingProxyLink = newProxyLinkHttp<Env>({
}

{//修改登录请求 /secure/Passport.aspx
const url = config.url;
const p = url.pathname;
const porxyOrigin = new URL(req.url).origin;
if (p == "/secure/Passport.aspx" || p == "/passport.aspx") {
Expand Down Expand Up @@ -243,6 +243,7 @@ const bingProxyLink = newProxyLinkHttp<Env>({
}

{//不同域重定向转换
const url = config.url;
if (url.searchParams.has("cprt")) { //cprt -> hostname
url.hostname = url.searchParams.get("cprt") as string;
url.searchParams.delete("cprt");
Expand Down Expand Up @@ -280,19 +281,22 @@ const bingProxyLink = newProxyLinkHttp<Env>({
config.init.headers = newheaders;
}

{//txt文本替换
{//txt文本替换
const resUrl = new URL(res.url);
const resHeaders = config.init.headers as Headers;
const contentType = res.headers.get("Content-Type");
if( contentType && (

if( resUrl.pathname!="/turing/captcha/challenge" && // 这个路径是验证接口,不进行处理
contentType &&
(
contentType.startsWith("text/") ||
contentType.startsWith("application/javascript") ||
contentType.startsWith("application/json")
)
){
resHeaders.delete("Content-Md5");
let retBody = await res.text();
const resUrl = new URL(res.url);


retBody = retBody.replace(/https?:\/\/sydney\.bing\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`);
retBody = retBody.replace(/https?:\/\/login\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`);
retBody = retBody.replace(/https?:\/\/account\.live\.com(:[0-9]{1,6})?/g, `${reqUrl.origin}`);
Expand Down
Loading

0 comments on commit 2ca3d1d

Please sign in to comment.