tweak dynamic url rewriting logic
This commit is contained in:
@@ -33,7 +33,7 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
||||
SetRequestModifications(
|
||||
// rx.SpoofJA3fingerprint(ja3, "Googlebot"),
|
||||
// rx.MasqueradeAsFacebookBot(),
|
||||
//rx.MasqueradeAsGoogleBot(),
|
||||
rx.MasqueradeAsGoogleBot(),
|
||||
rx.DeleteOutgoingCookies(),
|
||||
rx.ForwardRequestHeaders(),
|
||||
//rx.SpoofReferrerFromGoogleSearch(),
|
||||
@@ -42,6 +42,7 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
||||
// rx.RequestArchiveIs(),
|
||||
).
|
||||
AddResponseModifications(
|
||||
tx.InjectScriptBeforeDOMContentLoaded(`(() => {let d = document.createElement("div"); d.id = "adb-check"; document.body.append(d) })()`),
|
||||
tx.ForwardResponseHeaders(),
|
||||
tx.BypassCORS(),
|
||||
tx.BypassContentSecurityPolicy(),
|
||||
|
||||
@@ -67,8 +67,11 @@
|
||||
|
||||
//console.log(`proxychain: origin: ${origin} // proxyOrigin: ${proxyOrigin} // original: ${oldUrl}`)
|
||||
|
||||
//originDomain = origin.replace("https://", "");
|
||||
let scheme = origin.split(":")[0];
|
||||
|
||||
if (url.startsWith("//")) {
|
||||
url = `/${origin}/${encodeURIComponent(url.substring(2))}`;
|
||||
url = `/${scheme}://${encodeURIComponent(url.substring(2))}`;
|
||||
} else if (url.startsWith("/")) {
|
||||
url = `/${origin}/${encodeURIComponent(url.substring(1))}`;
|
||||
} else if (
|
||||
@@ -131,7 +134,7 @@
|
||||
|
||||
// monkey patch xmlhttprequest
|
||||
const oldOpen = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function(
|
||||
XMLHttpRequest.prototype.open = function (
|
||||
method,
|
||||
url,
|
||||
async = true,
|
||||
@@ -147,7 +150,7 @@
|
||||
);
|
||||
|
||||
const oldSend = XMLHttpRequest.prototype.send;
|
||||
XMLHttpRequest.prototype.send = function(method, url) {
|
||||
XMLHttpRequest.prototype.send = function (method, url) {
|
||||
return oldSend.call(this, method, rewriteURL(url));
|
||||
};
|
||||
hideMonkeyPatch(
|
||||
@@ -158,7 +161,7 @@
|
||||
|
||||
// monkey patch service worker registration
|
||||
const oldRegister = ServiceWorkerContainer.prototype.register;
|
||||
ServiceWorkerContainer.prototype.register = function(scriptURL, options) {
|
||||
ServiceWorkerContainer.prototype.register = function (scriptURL, options) {
|
||||
return oldRegister.call(this, rewriteURL(scriptURL), options);
|
||||
};
|
||||
hideMonkeyPatch(
|
||||
@@ -169,7 +172,7 @@
|
||||
|
||||
// monkey patch URL.toString() method
|
||||
const oldToString = URL.prototype.toString;
|
||||
URL.prototype.toString = function() {
|
||||
URL.prototype.toString = function () {
|
||||
let originalURL = oldToString.call(this);
|
||||
return rewriteURL(originalURL);
|
||||
};
|
||||
@@ -181,7 +184,7 @@
|
||||
|
||||
// monkey patch URL.toJSON() method
|
||||
const oldToJson = URL.prototype.toString;
|
||||
URL.prototype.toString = function() {
|
||||
URL.prototype.toString = function () {
|
||||
let originalURL = oldToJson.call(this);
|
||||
return rewriteURL(originalURL);
|
||||
};
|
||||
@@ -197,11 +200,11 @@
|
||||
"href",
|
||||
);
|
||||
Object.defineProperty(URL.prototype, "href", {
|
||||
get: function() {
|
||||
get: function () {
|
||||
let originalHref = originalHrefDescriptor.get.call(this);
|
||||
return rewriteURL(originalHref);
|
||||
},
|
||||
set: function(newValue) {
|
||||
set: function (newValue) {
|
||||
originalHrefDescriptor.set.call(this, rewriteURL(newValue));
|
||||
},
|
||||
});
|
||||
@@ -278,6 +281,19 @@
|
||||
}
|
||||
});
|
||||
|
||||
// monkey-patching Element.setAttribute
|
||||
const originalSetAttribute = Element.prototype.setAttribute;
|
||||
Element.prototype.setAttribute = function (name, value) {
|
||||
const isMatchingElement = elements.some((element) => {
|
||||
return this.tagName.toLowerCase() === element.tag &&
|
||||
name.toLowerCase() === element.attribute;
|
||||
});
|
||||
if (isMatchingElement) {
|
||||
value = rewriteURL(value);
|
||||
}
|
||||
originalSetAttribute.call(this, name, value);
|
||||
};
|
||||
|
||||
// sometimes, libraries will set the Element.innerHTML or Element.outerHTML directly with a string instead of setters.
|
||||
// in this case, we intercept it, create a fake DOM, parse it and then rewrite all attributes that could
|
||||
// contain a URL. Then we return the replacement innerHTML/outerHTML with redirected links.
|
||||
|
||||
@@ -66,6 +66,7 @@ func PatchTrackerScripts() proxychain.ResponseModification {
|
||||
// preflight checks
|
||||
reqURL := chain.Request.URL.String()
|
||||
isTracker := false
|
||||
//
|
||||
|
||||
var surrogateScript io.ReadCloser
|
||||
for domain, domainRules := range rules {
|
||||
|
||||
Reference in New Issue
Block a user