Skip to content

Commit

Permalink
Refactored, Changed obfuscation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bia-pain-bache committed Jan 8, 2025
1 parent 65df406 commit af09d8e
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 127 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ jobs:
run: |
npx wrangler deploy src/worker.js --name bpb-worker-panel --compatibility-flag [nodejs_compat] --compatibility-date 2024-10-26 --dry-run --outdir=dist
cp -f dist/worker.js unobfuscated/worker.js
touch cache.json
npx javascript-obfuscator --split-strings true --split-strings-chunk-length 2 --transform-object-keys true --rename-globals true --rename-properties true --rename-properties-mode unsafe --identifier-names-cache-path cache.json dist/worker.js --output _worker.js
npx javascript-obfuscator --split-strings true --split-strings-chunk-length 2 dist/worker.js --output _worker.js
- name: Commit and push built worker
run: |
Expand Down
33 changes: 16 additions & 17 deletions src/cores-configs/clash.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ async function buildClashDNS (proxySettings, isChain, isWarp) {
const {
remoteDNS,
localDNS,
vlessTrojanFakeDNS,
VLTRFakeDNS,
outProxyParams,
enableIPv6,
warpFakeDNS,
warpEnableIPv6,
bypassIran,
bypassChina,
bypassRussia,
customBypassRules,
customBlockRules
customBypassRules
} = proxySettings;

const warpRemoteDNS = warpEnableIPv6
? ["1.1.1.1", "1.0.0.1", "[2606:4700:4700::1111]", "[2606:4700:4700::1001]"]
: ["1.1.1.1", "1.0.0.1"];
const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp);
const isFakeDNS = (VLTRFakeDNS && !isWarp) || (warpFakeDNS && isWarp);
const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp);
const customBypassRulesDomains = customBypassRules.split(',').filter(address => isDomain(address));
const isBypass = bypassIran || bypassChina || bypassRussia;
Expand Down Expand Up @@ -248,7 +247,7 @@ function buildClashRoutingRules (proxySettings) {
return { rules, ruleProviders };
}

function buildClashVLESSOutbound (remark, address, port, host, sni, path, allowInsecure) {
function buildClashVLOutbound (remark, address, port, host, sni, path, allowInsecure) {
const tls = globalThis.defaultHttpsPorts.includes(port) ? true : false;
const addr = isIPv6(address) ? address.replace(/\[|\]/g, '') : address;
const outbound = {
Expand Down Expand Up @@ -280,7 +279,7 @@ function buildClashVLESSOutbound (remark, address, port, host, sni, path, allowI
return outbound;
}

function buildClashTrojanOutbound (remark, address, port, host, sni, path, allowInsecure) {
function buildClashTROutbound (remark, address, port, host, sni, path, allowInsecure) {
const addr = isIPv6(address) ? address.replace(/\[|\]/g, '') : address;
return {
"name": remark,
Expand Down Expand Up @@ -461,14 +460,14 @@ export async function getClashNormalConfig (request, env) {
cleanIPs,
proxyIP,
ports,
vlessConfigs,
trojanConfigs,
VLConfigs,
TRConfigs,
outProxy,
outProxyParams,
customCdnAddrs,
customCdnHost,
customCdnSni,
bestVLESSTrojanInterval,
bestVLTRInterval,
enableIPv6
} = proxySettings;

Expand Down Expand Up @@ -503,21 +502,21 @@ export async function getClashNormalConfig (request, env) {
const urlTest = config['proxy-groups'][1];
selector.proxies = ['💦 Best Ping 💥'];
urlTest.name = '💦 Best Ping 💥';
urlTest.interval = +bestVLESSTrojanInterval;
urlTest.interval = +bestVLTRInterval;
const Addresses = await getConfigAddresses(cleanIPs, enableIPv6);
const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : [];
const totalAddresses = [...Addresses, ...customCdnAddresses];
let proxyIndex = 1, path;
const protocols = [
...(vlessConfigs ? ['VLESS'] : []),
...(trojanConfigs ? ['Trojan'] : [])
...(VLConfigs ? ['VLESS'] : []),
...(TRConfigs ? ['Trojan'] : [])
];

protocols.forEach ( protocol => {
let protocolIndex = 1;
ports.forEach ( port => {
totalAddresses.forEach( addr => {
let VLESSOutbound, TrojanOutbound;
let VLOutbound, TROutbound;
const isCustomAddr = customCdnAddresses.includes(addr);
const configType = isCustomAddr ? 'C' : '';
const sni = isCustomAddr ? customCdnSni : randomUpperCase(globalThis.hostName);
Expand All @@ -526,7 +525,7 @@ export async function getClashNormalConfig (request, env) {

if (protocol === 'VLESS') {
path = `/${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`;
VLESSOutbound = buildClashVLESSOutbound(
VLOutbound = buildClashVLOutbound(
chainProxy ? `proxy-${proxyIndex}` : remark,
addr,
port,
Expand All @@ -535,14 +534,14 @@ export async function getClashNormalConfig (request, env) {
path,
isCustomAddr
);
config.proxies.push(VLESSOutbound);
config.proxies.push(VLOutbound);
selector.proxies.push(remark);
urlTest.proxies.push(remark);
}

if (protocol === 'Trojan' && globalThis.defaultHttpsPorts.includes(port)) {
path = `/tr${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`;
TrojanOutbound = buildClashTrojanOutbound(
TROutbound = buildClashTROutbound(
chainProxy ? `proxy-${proxyIndex}` : remark,
addr,
port,
Expand All @@ -551,7 +550,7 @@ export async function getClashNormalConfig (request, env) {
path,
isCustomAddr
);
config.proxies.push(TrojanOutbound);
config.proxies.push(TROutbound);
selector.proxies.push(remark);
urlTest.proxies.push(remark);
}
Expand Down
22 changes: 11 additions & 11 deletions src/cores-configs/normalConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ export async function getNormalConfigs(request, env) {
cleanIPs,
proxyIP,
ports,
vlessConfigs,
trojanConfigs ,
VLConfigs,
TRConfigs ,
outProxy,
customCdnAddrs,
customCdnHost,
customCdnSni,
enableIPv6
} = proxySettings;

let vlessConfs = '', trojanConfs = '', chainProxy = '';
let VLConfs = '', TRConfs = '', chainProxy = '';
let proxyIndex = 1;
const Addresses = await getConfigAddresses(cleanIPs, enableIPv6);
const customCdnAddresses = customCdnAddrs ? customCdnAddrs.split(',') : [];
const totalAddresses = [...Addresses, ...customCdnAddresses];
const alpn = globalThis.client === 'singbox' ? 'http/1.1' : 'h2,http/1.1';
const trojanPass = encodeURIComponent(globalThis.trojanPassword);
const TRPass = encodeURIComponent(globalThis.TRPassword);
const earlyData = globalThis.client === 'singbox'
? '&eh=Sec-WebSocket-Protocol&ed=2560'
: encodeURIComponent('?ed=2560');
Expand All @@ -34,18 +34,18 @@ export async function getNormalConfigs(request, env) {
const sni = isCustomAddr ? customCdnSni : randomUpperCase(globalThis.hostName);
const host = isCustomAddr ? customCdnHost : globalThis.hostName;
const path = `${getRandomPath(16)}${proxyIP ? `/${encodeURIComponent(btoa(proxyIP))}` : ''}${earlyData}`;
const vlessRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'VLESS', configType));
const trojanRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'Trojan', configType));
const VLRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'VLESS', configType));
const TRRemark = encodeURIComponent(generateRemark(proxyIndex, port, addr, cleanIPs, 'Trojan', configType));
const tlsFields = globalThis.defaultHttpsPorts.includes(port)
? `&security=tls&sni=${sni}&fp=randomized&alpn=${alpn}`
: '&security=none';

if (vlessConfigs) {
vlessConfs += `${atob('dmxlc3M6Ly8=')}${globalThis.userID}@${addr}:${port}?path=/${path}&encryption=none&host=${host}&type=ws${tlsFields}#${vlessRemark}\n`;
if (VLConfigs) {
VLConfs += `${atob('dmxlc3M6Ly8=')}${globalThis.userID}@${addr}:${port}?path=/${path}&encryption=none&host=${host}&type=ws${tlsFields}#${VLRemark}\n`;
}

if (trojanConfigs) {
trojanConfs += `${atob('dHJvamFuOi8v')}${trojanPass}@${addr}:${port}?path=/tr${path}&host=${host}&type=ws${tlsFields}#${trojanRemark}\n`;
if (TRConfigs) {
TRConfs += `${atob('dHJvamFuOi8v')}${TRPass}@${addr}:${port}?path=/tr${path}&host=${host}&type=ws${tlsFields}#${TRRemark}\n`;
}

proxyIndex++;
Expand All @@ -66,7 +66,7 @@ export async function getNormalConfigs(request, env) {
}
}

const configs = btoa(vlessConfs + trojanConfs + chainProxy);
const configs = btoa(VLConfs + TRConfs + chainProxy);
return new Response(configs, {
status: 200,
headers: {
Expand Down
32 changes: 16 additions & 16 deletions src/cores-configs/sing-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isWarp, remoteDNSDetour)
const {
remoteDNS,
localDNS,
vlessTrojanFakeDNS,
VLTRFakeDNS,
enableIPv6,
warpFakeDNS,
warpEnableIPv6,
Expand All @@ -20,7 +20,7 @@ function buildSingBoxDNS (proxySettings, outboundAddrs, isWarp, remoteDNSDetour)
} = proxySettings;

let fakeip;
const isFakeDNS = (vlessTrojanFakeDNS && !isWarp) || (warpFakeDNS && isWarp);
const isFakeDNS = (VLTRFakeDNS && !isWarp) || (warpFakeDNS && isWarp);
const isIPv6 = (enableIPv6 && !isWarp) || (warpEnableIPv6 && isWarp);
const customBypassRulesDomains = customBypassRules.split(',').filter(address => isDomain(address));
const customBlockRulesDomains = customBlockRules.split(',').filter(address => isDomain(address));
Expand Down Expand Up @@ -349,7 +349,7 @@ function buildSingBoxRoutingRules (proxySettings) {
return {rules, rule_set: ruleSets};
}

function buildSingBoxVLESSOutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) {
function buildSingBoxVLOutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) {
const { enableIPv6, lengthMin, lengthMax, intervalMin, intervalMax, proxyIP } = proxySettings;
const path = `/${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`;
const tls = globalThis.defaultHttpsPorts.includes(port) ? true : false;
Expand Down Expand Up @@ -391,13 +391,13 @@ function buildSingBoxVLESSOutbound (proxySettings, remark, address, port, host,
return outbound;
}

function buildSingBoxTrojanOutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) {
function buildSingBoxTROutbound (proxySettings, remark, address, port, host, sni, allowInsecure, isFragment) {
const { enableIPv6, lengthMin, lengthMax, intervalMin, intervalMax, proxyIP } = proxySettings;
const path = `/tr${getRandomPath(16)}${proxyIP ? `/${btoa(proxyIP)}` : ''}`;
const tls = globalThis.defaultHttpsPorts.includes(port) ? true : false;
const outbound = {
type: "trojan",
password: globalThis.trojanPassword,
password: globalThis.TRPassword,
server: address,
server_port: +port,
domain_strategy: enableIPv6 ? "prefer_ipv4" : "ipv4_only",
Expand Down Expand Up @@ -623,14 +623,14 @@ export async function getSingBoxCustomConfig(request, env, isFragment) {
const {
cleanIPs,
ports,
vlessConfigs,
trojanConfigs,
VLConfigs,
TRConfigs,
outProxy,
outProxyParams,
customCdnAddrs,
customCdnHost,
customCdnSni,
bestVLESSTrojanInterval,
bestVLTRInterval,
enableIPv6
} = proxySettings;

Expand Down Expand Up @@ -663,28 +663,28 @@ export async function getSingBoxCustomConfig(request, env, isFragment) {
const selector = config.outbounds[0];
const urlTest = config.outbounds[1];
selector.outbounds = ['💦 Best Ping 💥'];
urlTest.interval = `${bestVLESSTrojanInterval}s`;
urlTest.interval = `${bestVLTRInterval}s`;
urlTest.tag = '💦 Best Ping 💥';
const totalPorts = ports.filter(port => isFragment ? globalThis.defaultHttpsPorts.includes(port) : true);
let proxyIndex = 1;
const protocols = [
...(vlessConfigs ? ['VLESS'] : []),
...(trojanConfigs ? ['Trojan'] : [])
...(VLConfigs ? ['VLESS'] : []),
...(TRConfigs ? ['Trojan'] : [])
];

protocols.forEach ( protocol => {
let protocolIndex = 1;
totalPorts.forEach ( port => {
totalAddresses.forEach ( addr => {
let VLESSOutbound, TrojanOutbound;
let VLOutbound, TROutbound;
const isCustomAddr = customCdnAddresses.includes(addr);
const configType = isCustomAddr ? 'C' : isFragment ? 'F' : '';
const sni = isCustomAddr ? customCdnSni : randomUpperCase(globalThis.hostName);
const host = isCustomAddr ? customCdnHost : globalThis.hostName;
const remark = generateRemark(protocolIndex, port, addr, cleanIPs, protocol, configType);

if (protocol === 'VLESS') {
VLESSOutbound = buildSingBoxVLESSOutbound (
VLOutbound = buildSingBoxVLOutbound (
proxySettings,
chainProxy ? `proxy-${proxyIndex}` : remark,
addr,
Expand All @@ -694,11 +694,11 @@ export async function getSingBoxCustomConfig(request, env, isFragment) {
isCustomAddr,
isFragment
);
config.outbounds.push(VLESSOutbound);
config.outbounds.push(VLOutbound);
}

if (protocol === 'Trojan') {
TrojanOutbound = buildSingBoxTrojanOutbound (
TROutbound = buildSingBoxTROutbound (
proxySettings,
chainProxy ? `proxy-${proxyIndex}` : remark,
addr,
Expand All @@ -708,7 +708,7 @@ export async function getSingBoxCustomConfig(request, env, isFragment) {
isCustomAddr,
isFragment
);
config.outbounds.push(TrojanOutbound);
config.outbounds.push(TROutbound);
}

if (chainProxy) {
Expand Down
Loading

0 comments on commit af09d8e

Please sign in to comment.