Files
s41r4j-webtools/assets/js/browser_fingerprinting.js
T

492 lines
16 KiB
JavaScript

// Initialize Fingerprinting when script is loaded by the router
(function initFingerprinting() {
var fingerprintingDetails = [
{
category: 'Browser Information',
items: [
{ label: 'User Agent', id: 'userAgent' },
{ label: 'Browser', id: 'browser' },
{ label: 'Browser Engine', id: 'browserEngine' },
{ label: 'Browser Window Size', id: 'windowSize' },
{ label: 'Addons', id: 'addons' },
{ label: 'Ad Blocker Used', id: 'adBlockerUsed' },
{ label: 'Cookies Enabled', id: 'cookiesEnabled' },
{ label: 'JavaScript Enabled', id: 'javascriptEnabled' },
]
},
{
category: 'Device Information',
items: [
{ label: 'Device', id: 'device' },
{ label: 'Operating System', id: 'operatingSystem' },
{ label: 'Screen Dimensions', id: 'computerScreen' },
{ label: 'Time Zone', id: 'timeZone' },
{ label: 'System Fonts', id: 'systemFonts' },
{ label: 'CPU Cores', id: 'cpuCores' },
{ label: 'Memory', id: 'memory' },
{ label: 'GPU', id: 'gpu' }
]
},
{
category: 'Network Information',
items: [
{ label: 'VPN Detection', id: 'vpnDetection' },
{ label: 'Proxy Detection', id: 'proxyDetection' },
{ label: 'Tor Detection', id: 'torDetection' },
{ label: 'Local IP', id: 'localIP' },
{ label: 'Public IP', id: 'publicIP' },
{ label: 'Location', id: 'location' },
{ label: 'Upload Speed', id: 'uploadSpeed' },
{ label: 'Download Speed', id: 'downloadSpeed' }
]
},
];
var containerElement = document.getElementById('fingerprintingContainer');
if (!containerElement) return; // Guard clause in case script runs out of order
var tableElement = document.createElement('table');
tableElement.classList.add('table');
fingerprintingDetails.forEach(function (category) {
var categoryRow = document.createElement('tr');
categoryRow.classList.add('category-row');
var categoryCell = document.createElement('td');
categoryCell.classList.add('category-cell');
categoryCell.textContent = category.category;
categoryCell.colSpan = 2;
categoryRow.appendChild(categoryCell);
tableElement.appendChild(categoryRow);
category.items.forEach(function (detail) {
var row = document.createElement('tr');
var labelCell = document.createElement('td');
labelCell.textContent = detail.label;
row.appendChild(labelCell);
var valueCell = document.createElement('td');
valueCell.id = detail.id;
row.appendChild(valueCell);
tableElement.appendChild(row);
});
});
var containerWrapper = document.createElement('div');
containerWrapper.classList.add('table-container');
// Create an inner wrapper for styling matching the CSS
var tableWrapperInner = document.createElement('div');
tableWrapperInner.classList.add('table-wrapper');
tableWrapperInner.appendChild(tableElement);
containerWrapper.appendChild(tableWrapperInner);
containerElement.appendChild(containerWrapper);
// Get the user agent
var userAgent = navigator.userAgent;
var userAgentElement = document.getElementById('userAgent');
if (userAgentElement) userAgentElement.textContent = userAgent;
// Get the browser details
var browserElement = document.getElementById('browser');
var browserDetails = parseBrowser(userAgent);
if (browserDetails && browserElement) {
browserElement.textContent = browserDetails;
} else if (browserElement) {
browserElement.parentElement.style.display = 'none';
}
// Function to parse the browser from user agent
function parseBrowser(userAgent) {
var matches = userAgent.match(/(firefox|chrome|safari|opera|edge|msie|trident(?=\/))\/?\s*(\d+)/i);
if (matches && matches.length >= 3) {
return matches[1] + ' ' + matches[2];
} else {
return null;
}
}
// Get the browser engine details
var browserEngineElement = document.getElementById('browserEngine');
var browserEngineDetails = parseBrowserEngine(userAgent);
if (browserEngineDetails && browserEngineElement) {
browserEngineElement.textContent = browserEngineDetails;
} else if (browserEngineElement) {
browserEngineElement.parentElement.style.display = 'none';
}
// Function to parse the browser engine from user agent
function parseBrowserEngine(userAgent) {
var matches = userAgent.match(/(Gecko|WebKit|Trident|Blink|Presto|EdgeHTML)(\/|\s)(\d+)/i);
if (matches && matches.length >= 4) {
return matches[1] + ' ' + matches[3];
} else {
return null;
}
}
// Function to detect the device
function getDevice() {
var isMobile = /Mobile|Android|iP(hone|od|ad)/i.test(navigator.userAgent);
return isMobile ? 'Mobile Device' : 'Desktop/Laptop';
}
// Function to detect the operating system
function getOperatingSystem() {
var platform = navigator.platform;
var userAgent = navigator.userAgent;
if (/Win/i.test(platform)) {
return 'Windows';
} else if (/Mac/i.test(platform)) {
return 'Mac OS';
} else if (/Linux/i.test(platform)) {
return 'Linux';
} else if (/Android/i.test(userAgent)) {
return 'Android';
} else if (/iPhone|iPad|iPod/i.test(userAgent)) {
return 'iOS';
} else {
return 'Unknown';
}
}
// Function to detect VPN
function detectVPN() {
// Implement your VPN detection logic here
return false;
}
// Function to detect proxy
function detectProxy() {
// Implement your proxy detection logic here
return false;
}
// Function to detect Tor using the Tor Project website
function detectTor() {
return new Promise(function (resolve, reject) {
fetch('https://check.torproject.org/', { mode: 'no-cors' })
.then(function (response) {
var headers = response.headers;
var isTor = headers.has('Onion-Location');
resolve(isTor);
})
.catch(function (error) {
console.error('Tor detection error:', error);
reject();
});
});
}
// Update the table with Tor detection result
function updateTorDetectionResult(isTor) {
var torDetectionElement = document.getElementById('torDetection');
if (torDetectionElement) torDetectionElement.textContent = isTor ? 'Detected' : 'Not Detected';
}
// Usage example
var torStatusElement = document.getElementById('torDetection');
if (torStatusElement) torStatusElement.textContent = 'Checking...';
detectTor()
.then(function (isTor) {
updateTorDetectionResult(isTor);
})
.catch(function () {
updateTorDetectionResult(false);
});
// Function to check if cookies are enabled
function areCookiesEnabled() {
// Check if normal cookies are enabled
var normalCookiesEnabled = navigator.cookieEnabled;
// Check if third-party cookies are enabled
var thirdPartyCookiesEnabled = true;
document.cookie = 'thirdPartyCookieTest=true';
if (document.cookie.indexOf('thirdPartyCookieTest') === -1) {
thirdPartyCookiesEnabled = false;
}
document.cookie = 'thirdPartyCookieTest=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
return normalCookiesEnabled && thirdPartyCookiesEnabled;
}
// Function to check if JavaScript is enabled
function isJavaScriptEnabled() {
try {
eval("1 + 1"); // Evaluating a simple expression
return true; // JavaScript is enabled
} catch (error) {
return false; // JavaScript is disabled
}
}
// Function to get the local IP address
function getLocalIP() {
return new Promise(function (resolve, reject) {
var RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
if (!RTCPeerConnection) {
reject();
}
try {
var rtcPeerConnection = new RTCPeerConnection({
iceServers: []
});
rtcPeerConnection.createDataChannel('');
rtcPeerConnection.onicecandidate = function (event) {
if (event && event.candidate && event.candidate.candidate) {
var localIP = event.candidate.candidate.split('\n')[0].split(' ')[4];
resolve(localIP);
} else {
reject();
}
rtcPeerConnection.close();
};
rtcPeerConnection.createOffer(function (offer) {
rtcPeerConnection.setLocalDescription(offer);
}, function () {
reject();
});
} catch (e) {
reject();
}
});
}
// Function to get the location
function getLocation() {
return new Promise(function (resolve, reject) {
// Implement your location detection logic here
resolve('N/A');
});
}
// Function to get the screen size (pixels)
function getScreenSize() {
return window.screen.width + ' x ' + window.screen.height;
}
// Function to get the browser window size
function getWindowSize() {
return window.innerWidth + ' x ' + window.innerHeight;
}
// Function to get the system fonts
function getSystemFonts() {
var fonts = [];
if (document.fonts) {
document.fonts.forEach(function (font) {
fonts.push(font.family);
});
}
return fonts.length > 0 ? fonts.join(', ') : 'N/A';
}
// Function to detect if an ad blocker is used
function detectAdBlocker() {
return new Promise(function (resolve, reject) {
var testAd = document.createElement('div');
testAd.innerHTML = ' ';
testAd.className = 'adsbox';
document.body.appendChild(testAd);
window.setTimeout(function () {
if (testAd.offsetHeight === 0) {
resolve(true); // Ad blocker detected
} else {
resolve(false); // No ad blocker detected
}
testAd.remove();
}, 100);
});
}
// Call the functions to get the fingerprinting details
var deviceElement = document.getElementById('device');
if (deviceElement) deviceElement.textContent = getDevice();
var operatingSystemElement = document.getElementById('operatingSystem');
if (operatingSystemElement) operatingSystemElement.textContent = getOperatingSystem();
var vpnDetectionElement = document.getElementById('vpnDetection');
if (vpnDetectionElement) vpnDetectionElement.textContent = detectVPN() ? 'Detected' : 'Not Detected';
var proxyDetectionElement = document.getElementById('proxyDetection');
if (proxyDetectionElement) proxyDetectionElement.textContent = detectProxy() ? 'Detected' : 'Not Detected';
var cookiesEnabledElement = document.getElementById('cookiesEnabled');
if (cookiesEnabledElement) cookiesEnabledElement.textContent = areCookiesEnabled() ? 'Enabled' : 'Disabled';
var javascriptEnabledElement = document.getElementById('javascriptEnabled');
if (javascriptEnabledElement) javascriptEnabledElement.textContent = isJavaScriptEnabled() ? 'Enabled' : 'Disabled';
var localIPElement = document.getElementById('localIP');
getLocalIP().then(function (localIP) {
if (localIPElement) localIPElement.textContent = localIP || 'N/A';
}).catch(function () {
if (localIPElement) localIPElement.textContent = 'N/A';
});
var locationElement = document.getElementById('location');
getLocation().then(function (location) {
if (locationElement) locationElement.textContent = location || 'N/A';
}).catch(function () {
if (locationElement) locationElement.textContent = 'N/A';
});
var computerScreenElement = document.getElementById('computerScreen');
if (computerScreenElement) computerScreenElement.textContent = getScreenSize() + ' pixels';
var windowSizeElement = document.getElementById('windowSize');
if (windowSizeElement) windowSizeElement.textContent = getWindowSize() + ' pixels';
function updateNetworkHints() {
var downloadSpeedElement = document.getElementById('downloadSpeed');
var uploadSpeedElement = document.getElementById('uploadSpeed');
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
if (downloadSpeedElement) {
if (connection && typeof connection.downlink === 'number') {
downloadSpeedElement.textContent = connection.downlink + ' Mbps (reported)';
} else {
downloadSpeedElement.textContent = 'Unavailable';
}
}
if (uploadSpeedElement) {
if (connection && connection.effectiveType) {
uploadSpeedElement.textContent = connection.effectiveType + ' network';
} else {
uploadSpeedElement.textContent = 'Not exposed';
}
}
}
updateNetworkHints();
var networkConnection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
if (networkConnection && networkConnection.addEventListener) {
networkConnection.addEventListener('change', updateNetworkHints);
}
// Function to get the addons
var addonsElement = document.getElementById('addons');
getAddons().then(function (addons) {
if (addonsElement) addonsElement.textContent = addons.length > 0 ? addons.join(', ') : 'N/A';
}).catch(function () {
if (addonsElement) addonsElement.textContent = 'N/A';
});
// Function to detect if an ad blocker is used
var adBlockerUsedElement = document.getElementById('adBlockerUsed');
detectAdBlocker().then(function (adBlockerUsed) {
if (adBlockerUsedElement) adBlockerUsedElement.textContent = adBlockerUsed ? 'Used' : 'Not Used';
}).catch(function () {
if (adBlockerUsedElement) adBlockerUsedElement.textContent = 'N/A';
});
var timeZoneElement = document.getElementById('timeZone');
if (timeZoneElement) timeZoneElement.textContent = Intl.DateTimeFormat().resolvedOptions().timeZone;
var systemFontsElement = document.getElementById('systemFonts');
if (systemFontsElement) systemFontsElement.textContent = getSystemFonts();
// Get the hardware-related information
function getHardwareInfo() {
var hardwareInfo = {
cpuCores: navigator.hardwareConcurrency || 'N/A',
memory: navigator.deviceMemory ? navigator.deviceMemory + ' GB' : 'N/A',
gpu: 'N/A' // Implement GPU detection logic here
};
return hardwareInfo;
}
// Update the hardware-related information in the table
var hardwareInfo = getHardwareInfo();
var cpuCoresElement = document.getElementById('cpuCores');
if (cpuCoresElement) cpuCoresElement.textContent = hardwareInfo.cpuCores;
var memoryElement = document.getElementById('memory');
if (memoryElement) memoryElement.textContent = hardwareInfo.memory;
var gpuElement = document.getElementById('gpu');
if (gpuElement) gpuElement.textContent = hardwareInfo.gpu;
// Function to get the addons
function getAddons() {
return new Promise(function (resolve, reject) {
if (navigator && navigator.plugins && navigator.plugins.length > 0) {
var addons = Array.from(navigator.plugins).map(function (plugin) {
return plugin.name;
});
resolve(addons);
} else {
resolve([]);
}
});
}
// Add print button functionality
var printButton = document.getElementById('printButton');
if (printButton) {
printButton.addEventListener('click', function () {
// Add a class to the body to apply the print styles
document.body.classList.add('print-mode');
// Wait for a short delay to allow the styles to be applied
setTimeout(function () {
// Use the browser's print functionality to save the rendered content as a PDF
window.print();
// Remove the print class after printing
document.body.classList.remove('print-mode');
}, 100);
});
}
// Add JSON download functionality
var downloadJsonButton = document.getElementById('downloadJsonButton');
if (downloadJsonButton) {
downloadJsonButton.addEventListener('click', function () {
var data = {};
var rows = tableElement.querySelectorAll('tr:not(.category-row)');
rows.forEach(function (row) {
var cells = row.querySelectorAll('td');
if (cells.length === 2) {
var key = cells[0].textContent.trim();
var value = cells[1].textContent.trim();
data[key] = value;
}
});
var blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'webtools_fingerprint.json';
document.body.appendChild(a);
a.click();
setTimeout(function () {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 100);
});
}
})();