Skip to content

Commit

Permalink
fix(route/bilibili): add addDmVerifyInfoWithInter to bypass the risk …
Browse files Browse the repository at this point in the history
…control mechanism (#17147)
  • Loading branch information
syfxlin authored Oct 18, 2024
1 parent f455df8 commit 9f44e77
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type Config = {
bilibili: {
cookies: Record<string, string | undefined>;
dmImgList?: string;
dmImgInter?: string;
};
bitbucket: {
username?: string;
Expand Down Expand Up @@ -472,6 +473,7 @@ const calculateValue = () => {
bilibili: {
cookies: bilibili_cookies,
dmImgList: envs.BILIBILI_DM_IMG_LIST,
dmImgInter: envs.BILIBILI_DM_IMG_INTER,
},
bitbucket: {
username: envs.BITBUCKET_USERNAME,
Expand Down
10 changes: 3 additions & 7 deletions lib/routes/bilibili/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,9 @@ const getUsernameAndFaceFromUID = async (uid) => {
if (!name || !face) {
const cookie = await getCookie();
const wbiVerifyString = await getWbiVerifyString();
// await got(`https://space.bilibili.com/${uid}/`, {
// headers: {
// Referer: `https://www.bilibili.com/`,
// Cookie: cookie,
// },
// });
const params = utils.addWbiVerifyInfo(`mid=${uid}&token=&platform=web&web_location=1550101`, wbiVerifyString);
const dmImgList = utils.getDmImgList();
const renderData = await getRenderData(uid);
const params = utils.addWbiVerifyInfo(utils.addRenderData(utils.addDmVerifyInfo(`mid=${uid}&token=&platform=web&web_location=1550101`, dmImgList), renderData), wbiVerifyString);
const { data: nameResponse } = await got(`https://api.bilibili.com/x/space/wbi/acc/info?${params}`, {
headers: {
Referer: `https://space.bilibili.com/${uid}/`,
Expand Down
88 changes: 85 additions & 3 deletions lib/routes/bilibili/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function getDmImgList() {
const dmImgList = JSON.parse(config.bilibili.dmImgList);
return JSON.stringify([dmImgList[Math.floor(Math.random() * dmImgList.length)]]);
}
const x = Math.max(generateGaussianInteger(650, 5), 0);
const y = Math.max(generateGaussianInteger(400, 5), 0);
const x = Math.max(generateGaussianInteger(1245, 5), 0);
const y = Math.max(generateGaussianInteger(1285, 5), 0);
const path = [
{
x: 3 * x + 2 * y,
Expand All @@ -109,12 +109,92 @@ function getDmImgList() {
return JSON.stringify(path);
}

function addDmVerifyInfo(params, dmImgList) {
function getDmImgInter() {
if (config.bilibili.dmImgInter !== undefined) {
const dmImgInter = JSON.parse(config.bilibili.dmImgInter);
return JSON.stringify([dmImgInter[Math.floor(Math.random() * dmImgInter.length)]]);
}
const p1 = getDmImgInterWh(274, 601);
const s1 = getDmImgInterOf(134, 30);
const p2 = getDmImgInterWh(332, 64);
const s2 = getDmImgInterOf(1101, 338);
const of = getDmImgInterOf(0, 0);
const wh = getDmImgInterWh(1245, 1285);
const ds = [
{
t: getDmImgInterT('div'),
c: getDmImgInterC('clearfix g-search search-container'),
p: [p1[0], p1[2], p1[1]],
s: [s1[2], s1[0], s1[1]],
},
{
t: getDmImgInterT('div'),
c: getDmImgInterC('wrapper'),
p: [p2[0], p2[2], p2[1]],
s: [s2[2], s2[0], s2[1]],
},
];
return JSON.stringify({ ds, wh, of });
}

function getDmImgInterT(tag: string) {
return {
a: 4,
article: 29,
button: 7,
div: 2,
em: 27,
form: 17,
h1: 11,
h2: 12,
h3: 13,
h4: 14,
h5: 15,
h6: 16,
img: 5,
input: 6,
label: 25,
li: 10,
ol: 9,
option: 20,
p: 3,
section: 28,
select: 19,
span: 1,
strong: 26,
table: 21,
td: 23,
textarea: 18,
th: 24,
tr: 22,
ul: 8,
}[tag];
}

function getDmImgInterC(className: string) {
return Buffer.from(className).toString('base64').slice(0, -2);
}

function getDmImgInterOf(top: number, left: number) {
const seed = Math.floor(514 * Math.random());
return [3 * top + 2 * left + seed, 4 * top - 4 * left + 2 * seed, seed];
}

function getDmImgInterWh(width: number, height: number) {
const seed = Math.floor(114 * Math.random());
return [2 * width + 2 * height + 3 * seed, 4 * width - height + seed, seed];
}

function addDmVerifyInfo(params: string, dmImgList: string) {
const dmImgStr = Buffer.from('no webgl').toString('base64').slice(0, -2);
const dmCoverImgStr = Buffer.from('no webgl').toString('base64').slice(0, -2);
return `${params}&dm_img_list=${dmImgList}&dm_img_str=${dmImgStr}&dm_cover_img_str=${dmCoverImgStr}`;
}

function addDmVerifyInfoWithInter(params: string, dmImgList: string, dmImgInter: string) {
return `${addDmVerifyInfo(params, dmImgList)}&dm_img_inter=${dmImgInter}`;
}

const bvidTime = 1_589_990_400;

export default {
Expand All @@ -124,7 +204,9 @@ export default {
hexsign,
addWbiVerifyInfo,
getDmImgList,
getDmImgInter,
addDmVerifyInfo,
addDmVerifyInfoWithInter,
bvidTime,
addRenderData,
};
14 changes: 6 additions & 8 deletions lib/routes/bilibili/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ async function handler(ctx) {
const cookie = await cache.getCookie();
const wbiVerifyString = await cache.getWbiVerifyString();
const dmImgList = utils.getDmImgList();
const dmImgInter = utils.getDmImgInter();
const renderData = await cache.getRenderData(uid);
const [name, face] = await cache.getUsernameAndFaceFromUID(uid);

// await got(`https://space.bilibili.com/${uid}/video?tid=0&page=1&keyword=&order=pubdate`, {
// headers: {
// Referer: `https://space.bilibili.com/${uid}/`,
// Cookie: cookie,
// },
// });
const params = utils.addWbiVerifyInfo(utils.addRenderData(utils.addDmVerifyInfo(`mid=${uid}&ps=30&tid=0&pn=1&keyword=&order=pubdate&platform=web&web_location=1550101&order_avoided=true`, dmImgList), renderData), wbiVerifyString);
const params = utils.addWbiVerifyInfo(
utils.addRenderData(utils.addDmVerifyInfoWithInter(`mid=${uid}&ps=30&tid=0&pn=1&keyword=&order=pubdate&platform=web&web_location=1550101&order_avoided=true`, dmImgList, dmImgInter), renderData),
wbiVerifyString
);
const response = await got(`https://api.bilibili.com/x/space/wbi/arc/search?${params}`, {
headers: {
Referer: `https://space.bilibili.com/${uid}/video?tid=0&page=1&keyword=&order=pubdate`,
Referer: `https://space.bilibili.com/${uid}/video?tid=0&pn=1&keyword=&order=pubdate`,
Cookie: cookie,
},
});
Expand Down

0 comments on commit 9f44e77

Please sign in to comment.