-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
271 lines (237 loc) · 7.56 KB
/
main.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/gorilla/websocket"
"golang.org/x/sys/windows/registry"
)
var browserPaths = map[string][]string{
"chrome": {
`C:\Program Files\Google\Chrome\Application\chrome.exe`,
`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
filepath.Join(os.Getenv("USERPROFILE"), `AppData\Local\Google\Chrome\Application\chrome.exe`),
},
"vivaldi": {
`C:\Program Files\Vivaldi\Application\vivaldi.exe`,
`C:\Program Files (x86)\Vivaldi\Application\vivaldi.exe`,
filepath.Join(os.Getenv("LOCALAPPDATA"), `Vivaldi\Application\vivaldi.exe`),
},
"edge": {
filepath.Join(os.Getenv("ProgramFiles(x86)"), `Microsoft\Edge\Application\msedge.exe`),
filepath.Join(os.Getenv("ProgramFiles"), `Microsoft\Edge\Application\msedge.exe`),
filepath.Join(os.Getenv("LOCALAPPDATA"), `Microsoft\Edge\Application\msedge.exe`),
},
"opera": {
`C:\Program Files\Opera\launcher.exe`,
`C:\Program Files (x86)\Opera\launcher.exe`,
filepath.Join(os.Getenv("LOCALAPPDATA"), `Programs\Opera\launcher.exe`),
},
"operagx": {
`C:\Program Files\Opera GX\launcher.exe`,
`C:\Program Files (x86)\Opera GX\launcher.exe`,
filepath.Join(os.Getenv("LOCALAPPDATA"), `Programs\Opera GX\launcher.exe`),
},
"brave": {
`C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe`,
`C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe`,
filepath.Join(os.Getenv("LOCALAPPDATA"), `BraveSoftware\Brave-Browser\Application\brave.exe`),
},
}
var userDataDirs = map[string]string{
"chrome": filepath.Join(os.Getenv("LOCALAPPDATA"), "Google", "Chrome", "User Data"),
"vivaldi": filepath.Join(os.Getenv("LOCALAPPDATA"), "Vivaldi", "User Data"),
"edge": filepath.Join(os.Getenv("LOCALAPPDATA"), "Microsoft", "Edge", "User Data"),
"opera": filepath.Join(os.Getenv("LOCALAPPDATA"), "Opera Software", "Opera Stable"),
"operagx": filepath.Join(os.Getenv("LOCALAPPDATA"), "Opera Software", "Opera GX Stable"),
"brave": filepath.Join(os.Getenv("LOCALAPPDATA"), "BraveSoftware", "Brave-Browser", "User Data"),
}
var registryPaths = map[string]string{
"chrome": `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe`,
"vivaldi": `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vivaldi.exe`,
"edge": `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe`,
"opera": `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\opera.exe`,
"operagx": `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\opera_gx.exe`,
"brave": `SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe`,
}
const (
DEBUG_PORT = 9222
DEBUG_URL = "http://localhost:9222/json"
)
type Cookie struct {
Domain string `json:"domain"`
HTTPOnly bool `json:"httpOnly"`
Path string `json:"path"`
Secure bool `json:"secure"`
Expiry float64 `json:"expires"`
Name string `json:"name"`
Value string `json:"value"`
}
func findBrowserPath(browserName string) (string, error) {
if paths, ok := browserPaths[browserName]; ok {
for _, path := range paths {
if _, err := os.Stat(path); err == nil {
return path, nil
}
}
}
return "", fmt.Errorf("not found")
}
func getUserDataDir(browserName string) (string, error) {
if dir, ok := userDataDirs[browserName]; ok {
return dir, nil
}
return "", fmt.Errorf("not found")
}
func findBrowserPathInRegistry(browserName string) (string, error) {
if regPath, ok := registryPaths[browserName]; ok {
key, err := registry.OpenKey(registry.LOCAL_MACHINE, regPath, registry.QUERY_VALUE)
if err != nil {
return "", err
}
defer key.Close()
path, _, err := key.GetStringValue("")
return path, err
}
return "", fmt.Errorf("not found")
}
func getDebugWsURL() (string, error) {
resp, err := http.Get(DEBUG_URL)
if err != nil {
return "", err
}
defer resp.Body.Close()
var data []map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return "", err
}
if len(data) > 0 {
if wsURL, ok := data[0]["webSocketDebuggerUrl"].(string); ok {
return strings.TrimSpace(wsURL), nil
}
}
return "", fmt.Errorf("webSocketDebuggerUrl not found")
}
func killBrowser(browserName string) error {
processName := map[string]string{
"chrome": "chrome.exe",
"vivaldi": "vivaldi.exe",
"edge": "msedge.exe",
"opera": "opera.exe",
"operagx": "opera_gx.exe",
"brave": "brave.exe",
}
if name, ok := processName[browserName]; ok {
return exec.Command("taskkill", "/F", "/IM", name).Run()
}
return fmt.Errorf("not found")
}
func startDebuggedChrome(chromePath, userDataDir string) {
cmd := exec.Command(chromePath, fmt.Sprintf("--remote-debugging-port=%d", DEBUG_PORT), "--remote-allow-origins=*", "--headless", fmt.Sprintf("--user-data-dir=%s", userDataDir))
cmd.Stdout = nil
cmd.Stderr = nil
cmd.Start()
time.Sleep(2 * time.Second)
}
func jsonToNetscape(jsonCookies string) string {
var cookies []Cookie
json.Unmarshal([]byte(jsonCookies), &cookies)
var netscapeCookies []string
for _, cookie := range cookies {
httpOnly := "FALSE"
if cookie.HTTPOnly {
httpOnly = "TRUE"
}
secure := "FALSE"
if cookie.Secure {
secure = "TRUE"
}
netscapeCookies = append(netscapeCookies, fmt.Sprintf("%s\t%s\t%s\t%s\t%.0f\t%s\t%s", cookie.Domain, httpOnly, cookie.Path, secure, cookie.Expiry, cookie.Name, cookie.Value))
}
return strings.Join(netscapeCookies, "\n")
}
func saveCookiesToFile(filename, cookies string) error {
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()
_, err = file.WriteString(cookies)
if err != nil {
return err
}
return nil
}
func main() {
var input int
fmt.Print("[1] Chrome\n[2] Vivaldi\n[3] Edge\n[4] Opera\n[5] Opera GX\n[6] Brave\n\nEnter number: ")
_, err := fmt.Scan(&input)
if err != nil {
fmt.Println("Error reading input:", err)
return
}
browsers := map[int]string{
1: "chrome",
2: "vivaldi",
3: "edge",
4: "opera",
5: "operagx",
6: "brave",
}
if browserName, ok := browsers[input]; ok {
chromePath, err := findBrowserPathInRegistry(browserName)
if err != nil || chromePath == "" {
chromePath, err = findBrowserPath(browserName)
if err != nil || chromePath == "" {
return
}
}
userDataDir, err := getUserDataDir(browserName)
if err != nil {
log.Fatalf("Error getting user data directory: %v", err)
}
killBrowser(browserName)
startDebuggedChrome(chromePath, userDataDir)
url, err := getDebugWsURL()
if err != nil {
log.Fatalf("Error getting WebSocket URL: %v", err)
}
ws, _, err := websocket.DefaultDialer.Dial(url, nil)
if err != nil {
log.Fatalf("Error connecting WebSocket: %v", err)
}
defer ws.Close()
message := map[string]interface{}{
"id": 1,
"method": "Network.getAllCookies",
}
messageJSON, _ := json.Marshal(message)
if err := ws.WriteMessage(websocket.TextMessage, messageJSON); err != nil {
log.Fatalf("Error sending WebSocket message: %v", err)
}
_, response, err := ws.ReadMessage()
if err != nil {
log.Fatalf("Error reading WebSocket message: %v", err)
}
var result map[string]interface{}
json.Unmarshal(response, &result)
cookies := result["result"].(map[string]interface{})["cookies"]
cookieData, _ := json.MarshalIndent(cookies, "", " ")
netscapeCookies := jsonToNetscape(string(cookieData))
err = saveCookiesToFile("cookies.txt", netscapeCookies)
if err != nil {
log.Fatalf("Error exporting cookies: %v", err)
} else {
fmt.Printf("[!] Succesfully exported %d cookies\n", len(strings.Split(netscapeCookies, "\n")))
}
killBrowser(browserName)
} else {
main()
}
}