-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCEServer.java
More file actions
46 lines (34 loc) · 1.46 KB
/
RCEServer.java
File metadata and controls
46 lines (34 loc) · 1.46 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
import java.io.*;
import java.net.*;
public class RCEServer {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(5000);
System.out.println("Server started... Waiting for client");
Socket s = ss.accept();
System.out.println("Client connected!");
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter output = new PrintWriter(s.getOutputStream(), true);
String command;
while ((command = input.readLine()) != null) {
System.out.println("Command received: " + command);
if (!(command.equals("dir") || command.equals("date") || command.equals("whoami"))) {
output.println("Command not allowed!");
output.println("END");
continue;
}
Process process = Runtime.getRuntime().exec("cmd /c " + command);
BufferedReader result = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = result.readLine()) != null) {
output.println(line);
}
output.println("END");
}
s.close();
ss.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}