Skip to content

Commit cc865e8

Browse files
committed
Added key export functionality
1 parent b650ebb commit cc865e8

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
*.DS_Store
1717
*.bin
1818
*.mfd
19-
build/*
19+
build/*
20+
*-key.dic

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ $> gofare -dump MifareDump.bin -v
1818
```
1919

2020
![](img/img002.png)
21+
22+
To save the keys from a dump:
23+
24+
```sh
25+
$> gofare -dump MifareDump.bin -keys
26+
```
27+
28+
![](img/img003.png)

img/img003.png

92.9 KB
Loading

main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import (
2727
var (
2828
dump string
2929
verbose bool
30+
keys bool
3031
)
3132

3233
func init() {
3334
flag.StringVar(&dump, "dump", "", "Dump to print")
3435
flag.BoolVar(&verbose, "v", false, "Display color codes")
36+
flag.BoolVar(&keys, "keys", false, "Save keys to UID-key.dic")
3537
flag.Parse()
3638
}
3739

@@ -42,7 +44,7 @@ func main() {
4244
if verbose {
4345
parser.CodeColor()
4446
}
45-
parser.ParseDump(dump)
47+
parser.ParseDump(dump, keys)
4648

4749
} else {
4850
fmt.Printf("\nGofare - Mifare pretty print utility\n\n")

modules/parser/parser.go

+37-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var white = color.New(color.Bold, color.FgWhite)
3939

4040
// ParseDump will open the Mifare Dump
4141
// and print it in a readable way
42-
func ParseDump(dump string) {
42+
func ParseDump(dump string, keys bool) {
4343
dumpFile, err := os.Open(dump)
4444
CheckErr(err)
4545

@@ -49,6 +49,8 @@ func ParseDump(dump string) {
4949
buf := make([]byte, 16)
5050
i := 1
5151
x := 0
52+
var keyDictionary []string
53+
var uid string
5254

5355
fmt.Printf("⌌----------⫟--------------⫟----------⫟--------------⌍\n")
5456
fmt.Printf("| %v | %v | %v | %v |\n", white.Sprintf("%v", "Offset"), white.Sprintf("%v", "A"), white.Sprintf("%v", "Access"), white.Sprintf("%v", "B"))
@@ -65,8 +67,10 @@ func ParseDump(dump string) {
6567
}
6668
if i == 1 {
6769
fmt.Printf("| %v | %v%v%v | %v%x | %x |\n", gray.Sprintf("%08x", x), yellow.Sprintf("%08x", buf[0:4]), cyan.Sprintf("%2x", buf[4]), hired.Sprintf("%02x", buf[5]), magenta.Sprintf("%02x", buf[6]), buf[7:10], buf[10:16])
70+
uid = fmt.Sprintf("%08x", buf[0:4])
6871
} else if i%4 == 0 {
6972
fmt.Printf("| %v | %v | %v | %v |\n", gray.Sprintf("%08x", x), green.Sprintf("%x", buf[0:6]), red.Sprintf("%x", buf[6:10]), blue.Sprintf("%x", buf[10:16]))
73+
keyDictionary = append(keyDictionary, fmt.Sprintf("%x", buf[0:6]), fmt.Sprintf("%x", buf[10:16]))
7074
} else {
7175
fmt.Printf("| %v | %x | %x | %x |\n", gray.Sprintf("%08x", x), buf[0:6], buf[6:10], buf[10:16])
7276
}
@@ -76,6 +80,24 @@ func ParseDump(dump string) {
7680

7781
fmt.Printf("⌎----------⫠--------------⫠----------⫠--------------⌏\n\n")
7882

83+
if keys {
84+
SaveKeys(keyDictionary, uid)
85+
}
86+
87+
}
88+
89+
// SaveKeys will store the keys of a dumo
90+
// into a file named UID-keys.dic
91+
func SaveKeys(keyDictionary []string, uid string) {
92+
uniqueKeys := RemoveDuplicates(keyDictionary)
93+
94+
file, err := os.Create(uid + "-key.dic")
95+
CheckErr(err)
96+
defer file.Close()
97+
for _, key := range uniqueKeys {
98+
fmt.Fprintf(file, "%v\n", key)
99+
}
100+
fmt.Printf("%v Keys saved into %v\n\n", green.Sprintf("[+]"), white.Sprintf("%v-keys.dic", uid))
79101
}
80102

81103
// CodeColor prints the legent
@@ -90,6 +112,20 @@ func CodeColor() {
90112
fmt.Printf(" ⌎-----------⫟-----------⌏\n")
91113
}
92114

115+
// RemoveDuplicates will remove the duplicate
116+
// keys found in the dump
117+
func RemoveDuplicates(keyDictionary []string) []string {
118+
keys := make(map[string]bool)
119+
keyList := []string{}
120+
for _, entry := range keyDictionary {
121+
if _, value := keys[entry]; !value {
122+
keys[entry] = true
123+
keyList = append(keyList, entry)
124+
}
125+
}
126+
return keyList
127+
}
128+
93129
// CheckErr will handle errors
94130
// for the entire program
95131
func CheckErr(err error) {

0 commit comments

Comments
 (0)