-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathextract_cookie.go
More file actions
55 lines (49 loc) · 1.5 KB
/
extract_cookie.go
File metadata and controls
55 lines (49 loc) · 1.5 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
package firefox
import (
"database/sql"
"sort"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/sqliteutil"
)
const (
firefoxCookieQuery = `SELECT name, value, host, path,
creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
firefoxCountCookieQuery = `SELECT COUNT(*) FROM moz_cookies`
)
func extractCookies(path string) ([]types.CookieEntry, error) {
cookies, err := sqliteutil.QueryRows(path, true, firefoxCookieQuery,
func(rows *sql.Rows) (types.CookieEntry, error) {
var (
name, value, host, cookiePath string
isSecure, isHTTPOnly int
createdAt, expiry int64
)
if err := rows.Scan(&name, &value, &host, &cookiePath,
&createdAt, &expiry, &isSecure, &isHTTPOnly); err != nil {
return types.CookieEntry{}, err
}
hasExpire := expiry > 0
return types.CookieEntry{
Name: name,
Host: host,
Path: cookiePath,
Value: value, // Firefox cookies are not encrypted
IsSecure: isSecure != 0,
IsHTTPOnly: isHTTPOnly != 0,
HasExpire: hasExpire,
IsPersistent: hasExpire,
ExpireAt: firefoxSeconds(expiry),
CreatedAt: firefoxMicros(createdAt),
}, nil
})
if err != nil {
return nil, err
}
sort.Slice(cookies, func(i, j int) bool {
return cookies[i].CreatedAt.After(cookies[j].CreatedAt)
})
return cookies, nil
}
func countCookies(path string) (int, error) {
return sqliteutil.CountRows(path, true, firefoxCountCookieQuery)
}