This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
107 lines (89 loc) · 2.13 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
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"github.com/rusq/dlog"
_ "modernc.org/sqlite"
)
const (
chrome = "c"
firefox = "f"
)
var browsers = []string{chrome, firefox}
const passBufSz = 512
var (
browserType = flag.String("b", "", "`browser` to pull the data from. Browser is 1 character:\n"+
"\tc\t- Chrome\n\tf\t- Firefox")
openSSL = flag.Bool("openssl", false, "(chrome) use OpenSSL instead of built-in cryptographic library (slow)")
mozNSS = flag.Bool("nss3", false, "(firefox) use Mozilla NSS native library (buggy)")
verbose = flag.Bool("v", false, "verbose output")
)
// Browser is the interface that each browser must satisfy. We're not asking
// for too much.
type Browser interface {
Decrypt() (results <-chan *LoginInfo)
}
func main() {
flag.Parse()
dlog.SetDebug(*verbose)
var (
browser Browser
err error
)
switch *browserType {
default:
flag.Usage()
os.Exit(1)
case chrome:
browser, err = NewChrome(*openSSL)
case firefox:
if *mozNSS {
browser, err = NewFirefoxNSS()
} else {
browser, err = NewFirefox()
}
}
if err != nil {
log.Fatal(err)
}
results := browser.Decrypt()
formFormatter(results, *verbose)
}
func formFormatter(results <-chan *LoginInfo, verbose bool) {
const (
fmtLoginErr = "\tlogin:\t\t%q\n\terror:\t\t%s\n"
)
var buf = bufio.NewWriter(os.Stdout)
defer buf.Flush()
var prev string
for res := range results {
var decryptErr bool
if res.Err != nil {
dlog.Printf("failure on profile %q: %s", res.Profile, res.Err)
if _, ok := res.Err.(*DecryptError); !ok {
continue
}
decryptErr = true
}
if res.Username == "" && res.Password == "" {
continue
}
if prev != res.Profile {
fmt.Fprintf(buf, "\n<PROFILE: %s>\n", res.Profile)
prev = res.Profile
}
fmt.Fprintln(buf, res.Origin)
if res.Err != nil && !decryptErr {
fmt.Fprintf(buf, fmtLoginErr, res.Username, res.Err)
continue
}
if verbose {
fmt.Fprintf(buf, "\tlogin:\t\t%q\n\tpassword:\t%q\n\tct:\t\t%v\n", res.Username, res.Password, res.Encrypted)
} else {
fmt.Fprintf(buf, "\tlogin:\t\t%q\n\tpassword:\t%q\n", res.Username, res.Password)
}
}
}