Last active
April 27, 2025 07:43
-
-
Save alpgul/ce2458bfcec06b82b13f26ff48883b53 to your computer and use it in GitHub Desktop.
JavaScript Window Proxy with Eval-Based Access and Modification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let temp; | |
const tempWindow={} | |
const log=console.log; | |
const error=console.error; | |
// Geçerli JavaScript tanımlayıcı kontrolü (güvenlik için) | |
function isValidIdentifier(str) { | |
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str); | |
} | |
// Native fonksiyon kontrolü | |
function isNativeFunction(fn) { | |
return typeof fn === 'function' && fn.toString().includes('[native code]'); | |
} | |
// createProxyHandler fonksiyonu | |
function createProxyHandler(baseEval) { | |
return { | |
get(target, property, receiver) { | |
log(`Erişilen özellik: ${String(property)}`); | |
// eval ile baseEval.property formatında erişim | |
try { | |
// Güvenlik kontrolü: property geçerli bir tanımlayıcı mı? | |
if (!isValidIdentifier(property)) { | |
throw new Error(`Geçersiz özellik adı: ${String(property)}`); | |
} | |
// eval fonksiyonunu özel olarak izleme | |
if (property === 'eval') { | |
return function (code) { | |
log('eval çağrıldı, çalıştırılan kod:', code); | |
// eval'i receiver bağlamında çalıştır | |
return eval.call(receiver, code); | |
}; | |
} | |
// Önce target'ta saklanan native fonksiyon var mı kontrol et | |
const nativeFunc = target[baseEval + "." + property]; | |
if (nativeFunc ) { | |
return nativeFunc; | |
} | |
const value = eval(`${baseEval}.${property}`); // baseEval.property | |
// Fonksiyonları izlemek için Proxy | |
if (typeof value === 'function') { | |
const base = eval(baseEval); | |
target[baseEval + "." + property] = new Proxy(value, { | |
apply(targetFn, thisArg, args) { | |
log(`Fonksiyon çağrıldı: ${String(property)}, Argümanlar:`, args); | |
return Reflect.apply(targetFn, base, args); | |
} | |
}); | |
return target[baseEval + "." + property]; | |
} | |
// Value obje mi kontrolü ve recursive Proxy (boş obje ile) | |
if (value && typeof value === 'object') { | |
target[baseEval + "." + property] = new Proxy(target, createProxyHandler(`${baseEval}.${property}`)); // Güncellenmiş baseEval | |
return target[baseEval + "." + property]; | |
} | |
return value; | |
} catch (err) { | |
error(`eval ile erişim hatası (özellik: ${String(property)}):`, err); | |
return undefined; // Hata durumunda undefined dön | |
} | |
}, | |
set(target, property, value, receiver) { | |
log(`Özellik değiştirildi: ${String(property)}, Yeni değer:`, value); | |
// eval ile baseEval.property = value formatında atama | |
try { | |
// Güvenlik kontrolü: property geçerli bir tanımlayıcı mı? | |
if (!isValidIdentifier(property)) { | |
throw new Error(`Geçersiz özellik adı: ${String(property)}`); | |
} | |
// Fonksiyon kontrolü | |
if (typeof value === 'function') { | |
if (isNativeFunction(value)) { | |
temp = value; | |
eval(`${baseEval}.${property} = temp`); | |
}else{ | |
eval(`${baseEval}.${property} = ${value}`); | |
} | |
} else { | |
eval(`${baseEval}.${property} = ${JSON.stringify(value)}`); | |
} | |
return true; | |
} catch (err) { | |
error(`eval ile yazma hatası (özellik: ${String(property)}):`, err); | |
return false; // Hata durumunda false dön | |
} | |
} | |
}; | |
} | |
// Proxy handler'ı window için oluştur | |
const proxyHandler = createProxyHandler('window'); | |
// Boş obje ile Proxy oluşturma | |
const windowProxy = new Proxy(tempWindow, proxyHandler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment