@@ -39,7 +39,7 @@ var white = color.New(color.Bold, color.FgWhite)
39
39
40
40
// ParseDump will open the Mifare Dump
41
41
// and print it in a readable way
42
- func ParseDump (dump string ) {
42
+ func ParseDump (dump string , keys bool ) {
43
43
dumpFile , err := os .Open (dump )
44
44
CheckErr (err )
45
45
@@ -49,6 +49,8 @@ func ParseDump(dump string) {
49
49
buf := make ([]byte , 16 )
50
50
i := 1
51
51
x := 0
52
+ var keyDictionary []string
53
+ var uid string
52
54
53
55
fmt .Printf ("⌌----------⫟--------------⫟----------⫟--------------⌍\n " )
54
56
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) {
65
67
}
66
68
if i == 1 {
67
69
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 ])
68
71
} else if i % 4 == 0 {
69
72
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 ]))
70
74
} else {
71
75
fmt .Printf ("| %v | %x | %x | %x |\n " , gray .Sprintf ("%08x" , x ), buf [0 :6 ], buf [6 :10 ], buf [10 :16 ])
72
76
}
@@ -76,6 +80,24 @@ func ParseDump(dump string) {
76
80
77
81
fmt .Printf ("⌎----------⫠--------------⫠----------⫠--------------⌏\n \n " )
78
82
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 ))
79
101
}
80
102
81
103
// CodeColor prints the legent
@@ -90,6 +112,20 @@ func CodeColor() {
90
112
fmt .Printf (" ⌎-----------⫟-----------⌏\n " )
91
113
}
92
114
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
+
93
129
// CheckErr will handle errors
94
130
// for the entire program
95
131
func CheckErr (err error ) {
0 commit comments