-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathgemtek-pass.c
More file actions
184 lines (143 loc) · 4.56 KB
/
gemtek-pass.c
File metadata and controls
184 lines (143 loc) · 4.56 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
Can be compiled with the following command:
gcc gemtek-pass.c -lcrypto -o gemtek-pass
Purpose of this program is to calculate the default wifi password
of some Gemtek router (tested on WVRTM-127ACN distributet in Italy by Linkem)
passing as parameter the router serial number and last 3 digits of the
Mac Addrss (same digits used as last 6 chars of the default SSID)
The algorithm implemented on this program is based on reverse engineering
of the binary /bin/assistant, included in the router firmware and root
file system.
A tipycal invocation of /bin/assistant to generate the default password
is:
# assistant -p "hO2PHGNmaX0Ww!v0eqD8" -w wifi -h "GMK170210005623" -s A8D9A6 \
2> /dev/null | cut -c1-8 | tr 'A-Z' 'a-z'
wsagj2zz
Licensed under MIT License:
Copyright (c) 2019, Valerio Di Giampietro, http://va.ler.io, v@ler.io
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void upper_string(char s[]) {
int c = 0;
while (s[c] != '\0') {
if (s[c] >= 'a' && s[c] <= 'z') {
s[c] = s[c] - 32;
}
c++;
}
}
void lower_string(char s[]) {
int c = 0;
while (s[c] != '\0') {
if (s[c] >= 'A' && s[c] <= 'Z') {
s[c] = s[c] + 32;
}
c++;
}
}
size_t b64_encoded_size(size_t inlen)
{
size_t ret;
ret = inlen;
if (inlen % 3 != 0)
ret += 3 - (inlen % 3);
ret /= 3;
ret *= 4;
return ret;
}
char *b64_encode(const unsigned char *in, unsigned char *out, size_t len)
{
size_t elen;
size_t i;
size_t j;
size_t v;
if (in == NULL || len == 0)
return NULL;
elen = b64_encoded_size(len);
out[elen] = '\0';
for (i=0, j=0; i<len; i+=3, j+=4) {
v = in[i];
v = i+1 < len ? v << 8 | in[i+1] : v << 8;
v = i+2 < len ? v << 8 | in[i+2] : v << 8;
out[j] = b64chars[(v >> 18) & 0x3F];
out[j+1] = b64chars[(v >> 12) & 0x3F];
if (i+1 < len) {
out[j+2] = b64chars[(v >> 6) & 0x3F];
} else {
out[j+2] = '=';
}
if (i+2 < len) {
out[j+3] = b64chars[v & 0x3F];
} else {
out[j+3] = '=';
}
}
return out;
}
char *wifipass(const unsigned char *serial, const unsigned char *halfmac, unsigned char *buf) {
unsigned char passbin[6];
unsigned char sha1bin[SHA_DIGEST_LENGTH];
int i = 0;
int j = 0;
int lastpos = 0;
int modulus = SHA_DIGEST_LENGTH;
SHA1(serial, strlen(serial), sha1bin);
if (sha1bin[0] != 0) {
for (i=1; i<SHA_DIGEST_LENGTH; i++) {
if (sha1bin[i] == 0) {
modulus = i;
break;
}
}
}
for (i=0; i<6; i++) {
j= halfmac[i]- '0' + lastpos;
j= j % modulus;
passbin[i]=sha1bin[j];
lastpos=j;
}
b64_encode(passbin,buf,6);
lower_string(buf);
return buf;
}
int main(int argn, char *argv[]) {
int i = 0;
int j = 0;
char buf[SHA_DIGEST_LENGTH*2];
char bufpass[6];
unsigned char passb64[20];
if ( argn != 3 ) {
printf("Usage: %s serial last3-mac-digits\n", argv[0]);
printf(" Example: %s GMK170210005623 A8D9A6\n", argv[0]);
return -1;
}
if ( strlen(argv[2]) != 6) {
printf(" Error: the last 3 mac digits must be a 6 char string (example 'A1B2C3')\n");
return -1;
}
upper_string(argv[2]);
memset(buf, 0x0, SHA_DIGEST_LENGTH*2);
wifipass((unsigned char *)argv[1],(unsigned char *)argv[2],passb64);
printf("Serial number : %s\n", argv[1]);
printf("Last 3 MAC digits: %s\n", argv[2]);
printf("wifi password is : %s\n", passb64);
return 0;
}