Last active
April 9, 2016 20:30
-
-
Save mikemackintosh/fbf43553fba079bf2694 to your computer and use it in GitHub Desktop.
OSX Attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "io/ioutil" | |
| "log" | |
| "os/exec" | |
| "strings" | |
| ) | |
| // ChromeProfile stores the local user profiles for | |
| // attribution purposes only. | |
| type chromeProfile struct { | |
| AccountInfo []chromeAccountInfo `json:"account_info,omitempty"` | |
| } | |
| // ChromeAccountInfo contains Chrome Profile details | |
| type chromeAccountInfo struct { | |
| AccountID string `json:"account_id,omitempty"` | |
| FullName string `json:"full_name,omitempty"` | |
| Email string `json:"email,omitempty"` | |
| GivenName string `json:"given_name,omitempty"` | |
| HostedDomain string `json:"hd,omitempty"` | |
| PictureURL string `json:"picture_url,omitempty"` | |
| SourceProfile string `json:"profile,omitempty"` | |
| } | |
| // main function, executes all teh code | |
| func main() { | |
| fmt.Println("#########################################") | |
| fmt.Println("# #") | |
| fmt.Println("# ChromeProfiles by \033[38;5;154m@mikemackintosh\033[0m #") | |
| fmt.Println("# #") | |
| fmt.Println("#########################################") | |
| fmt.Println("\nFound The following Chrome Profile information") | |
| fmt.Println("==============================================") | |
| profiles := extractChromeProfiles() | |
| for _, p := range profiles { | |
| fmt.Printf("\n\tProfile for: \033[38;5;32m%s\033[0m\n", p.Email) | |
| fmt.Println("\t----------------------------") | |
| fmt.Printf("\t Name: %s\n", p.FullName) | |
| fmt.Printf("\t Domain: %s\n", p.HostedDomain) | |
| fmt.Printf("\t Pic: %s\n", p.PictureURL) | |
| fmt.Printf("\tProfile: %s\n", p.SourceProfile) | |
| fmt.Println("") | |
| } | |
| fmt.Println("") | |
| } | |
| // GetCommandOutput runs a command and returns it's output | |
| func GetCommandOutput(cmd string) (string, error) { | |
| out, err := exec.Command("bash", "-c", cmd).Output() | |
| if err != nil { | |
| return "", err | |
| } | |
| return strings.TrimSpace(string(out)), nil | |
| } | |
| // extractChromeProfiles attempts to locate all of the local | |
| // chrome profiles on this device so we can attempt to attribute | |
| // it to a user | |
| func extractChromeProfiles() []chromeAccountInfo { | |
| profiles := []chromeAccountInfo{} | |
| var profile chromeProfile | |
| // Get the different profiles on a box | |
| cmd := "ls -1 /Users/*/Library/Application\\ Support/Google/Chrome/*/Preferences" | |
| rawChromeProfiles, err := GetCommandOutput(cmd) | |
| if err != nil { | |
| log.Printf("--> [ERR] Meta: Unable to obtain Chrome Profiles: %s", err) | |
| } | |
| // Range through the different discovered profiles | |
| chromeProfiles := strings.Split(rawChromeProfiles, "\n") | |
| for _, chromeProfile := range chromeProfiles { | |
| rawProfile, err := ioutil.ReadFile(chromeProfile) | |
| if err != nil { | |
| // There was an error reading the chrome profile, | |
| // just move along for now | |
| continue | |
| } | |
| // Unmarshal the Chrome profile data | |
| err = json.Unmarshal(rawProfile, &profile) | |
| if err != nil { | |
| fmt.Printf("> %s", err) | |
| // There was an error reading the chrome profile, | |
| // just move along for now | |
| continue | |
| } | |
| // Loop through each of the profiles we found | |
| for _, p := range profile.AccountInfo { | |
| p.SourceProfile = chromeProfile | |
| profiles = append(profiles, p) | |
| } | |
| } | |
| return profiles | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment