//1// Copyright (c) 2006-2025 Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56/**7* Provides basic session functions.8* @namespace beef.session9*/10beef.session = {1112hook_session_id_length: 80,13hook_session_id_chars: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",14ec: new evercookie(),15beefhook: "<%= @hook_session_name %>",1617/**18* Gets a string which will be used to identify the hooked browser session19*20* @example: var hook_session_id = beef.session.get_hook_session_id();21*/22get_hook_session_id: function() {23// check if the browser is already known to the framework24var id = this.ec.evercookie_cookie(beef.session.beefhook);25if (typeof id == 'undefined') {26var id = this.ec.evercookie_userdata(beef.session.beefhook);27}28if (typeof id == 'undefined') {29var id = this.ec.evercookie_window(beef.session.beefhook);30}3132// if the browser is not known create a hook session id and set it33if ((typeof id == 'undefined') || (id == null)) {34id = this.gen_hook_session_id();35this.set_hook_session_id(id);36}3738// return the hooked browser session identifier39return id;40},4142/**43* Sets a string which will be used to identify the hooked browser session44*45* @example: beef.session.set_hook_session_id('RANDOMSTRING');46*/47set_hook_session_id: function(id) {48// persist the hook session id49this.ec.evercookie_cookie(beef.session.beefhook, id);50this.ec.evercookie_userdata(beef.session.beefhook, id);51this.ec.evercookie_window(beef.session.beefhook, id);52},5354/**55* Generates a random string using the chars in hook_session_id_chars.56*57* @example: beef.session.gen_hook_session_id();58*/59gen_hook_session_id: function() {60// init the return value61var hook_session_id = "";6263// construct the random string64for(var i=0; i<this.hook_session_id_length; i++) {65var rand_num = Math.floor(Math.random()*this.hook_session_id_chars.length);66hook_session_id += this.hook_session_id_chars.charAt(rand_num);67}6869return hook_session_id;70}71};7273beef.regCmp('beef.session');747576