-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
430 lines (369 loc) · 9.55 KB
/
client.go
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
package main
import (
"archive/zip"
"bytes"
"fmt"
"github.com/bluekeyes/go-gitdiff/gitdiff"
"io"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
)
// Helper function to compare byte slices
func bytesEqual(a, b []byte) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func downloadZIP(flavor string) {
// URL of the zip file to download
// Check if it's Windows or Linux
url := ""
if flavor == "windows" {
url = "https://github.com/blurbdust/rainbowcrackalack/releases/download/untagged/rainbowcrackalack-win-x64.zip"
} else if flavor == "linux" {
url = "https://github.com/blurbdust/rainbowcrackalack/releases/download/untagged/rainbowcrackalack-linux-x64.zip"
} else {
fmt.Println("Unsupported OS!")
}
// Destination directory to extract the contents to
destDir := "crackalack"
// Create the destination directory if it doesn't already exist
if _, err := os.Stat(destDir); os.IsNotExist(err) {
os.MkdirAll(destDir, 0755)
} else {
println("Folder already exists, skipping download")
return
}
// Create a temporary file to save the downloaded zip file to
tmpFile, err := os.CreateTemp("", "rainbow*.zip")
if err != nil {
panic(err)
}
defer os.Remove(tmpFile.Name()) // Remove the temporary file when we're done with it
// Download the zip file and save it to the temporary file
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
_, err = io.Copy(tmpFile, resp.Body)
if err != nil {
panic(err)
}
// Open the zip file
zipReader, err := zip.OpenReader(tmpFile.Name())
if err != nil {
panic(err)
}
defer zipReader.Close()
// Extract the contents of the zip file to the destination directory
for _, file := range zipReader.File {
filePath := filepath.Join(destDir, file.Name)
if file.FileInfo().IsDir() {
os.MkdirAll(filePath, file.Mode())
continue
}
err = os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
if err != nil {
panic(err)
}
outFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
if err != nil {
panic(err)
}
defer outFile.Close()
inFile, err := file.Open()
if err != nil {
panic(err)
}
defer inFile.Close()
_, err = io.Copy(outFile, inFile)
if err != nil {
panic(err)
}
}
// Done!
println("Archive downloaded and extracted successfully!")
}
func helpCheck(dir string, prog string, filePath string, cdir string, computeUnitsInt int) int {
// Check if the file exists
if _, err := os.Stat(filePath); err == nil {
// Delete the file
err = os.Remove(filePath)
if err != nil {
panic(err)
}
fmt.Printf("File '%s' deleted\n", filePath)
} else if os.IsNotExist(err) {
fmt.Printf("File '%s' does not exist\n", filePath)
} else {
panic(err)
}
// double check execute bit is set on Linux
if runtime.GOOS == "linux" {
err := os.Chmod(prog, 0775)
if err != nil {
log.Fatal(err)
}
}
// Start the thing.exe process
cmd := exec.Command(prog, "netntlmv1", "byte", "7", "7", "0", "2", "1", "0")
// Create a pipe to capture the process output
stdout, err := cmd.StdoutPipe()
if err != nil {
panic(err)
}
// Start the process
err = cmd.Start()
if err != nil {
panic(err)
}
// Done!
fmt.Printf("Started process in directory %s\n", cdir)
// Read the output from the process
outputBytes, err := io.ReadAll(stdout)
if err != nil {
panic(err)
}
// Convert the output to a string and print it
output := strings.TrimSpace(string(outputBytes))
temp := strings.Split(output, "\n")
for _, line := range temp {
if strings.Contains(line, "Max compute units:") {
computeUnits := strings.Replace(line, "Max compute units: ", "", 1)
computeUnits = strings.TrimSpace(computeUnits)
computeUnitsInt, err = strconv.Atoi(computeUnits)
if err != nil {
panic(err)
}
}
}
// Wait for the process to finish
err = cmd.Wait()
if err != nil {
panic(err)
}
return computeUnitsInt
}
func runCheck(dir string, prog string) int {
computeUnitsInt := -1
// Get the current working directory
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
// Create the path to the subdirectory
cdir := filepath.Join(cwd, dir)
// Change into the subdirectory
err = os.Chdir(cdir)
if err != nil {
panic(err)
}
filePath := "netntlmv1_byte#7-7_0_2x1_0.rt"
computeUnitsInt = helpCheck(dir, prog, filePath, cdir, computeUnitsInt)
// Read the contents of the file into a byte slice
data, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}
// Define the desired byte sequence
desiredBytes := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcd, 0x72, 0xdf, 0xc6, 0xe6, 0xd0, 0x40, 0x00}
// Compare the byte slices
if bytesEqual(data, desiredBytes) {
fmt.Println("The byte sequences match!")
return computeUnitsInt
} else {
fmt.Println("The byte sequences do not match. Checking possibility of patch needed")
// TODO: If Linux, patch to old.netntlmv1.cl and rt.cl
oPath := filepath.Join("CL", "old.netntlmv1.cl")
nPath := filepath.Join("CL", "netntlmv1.cl")
bPath := filepath.Join("CL", "bad.netntlmv1.cl")
rPath := filepath.Join("CL", "rt.cl")
err := os.Rename(nPath, bPath)
if err != nil {
log.Fatal(err)
}
err = os.Rename(oPath, nPath)
if err != nil {
log.Fatal(err)
}
patchURL := "https://gist.githubusercontent.com/blurbdust/77bddb721489fa4359b7af17f68321a0/raw/ffd0b23ed0972dd609d816ee9f3e6a064a59504a/rt.patch"
// Download the patch file and save it to the temporary file
resp, err := http.Get(patchURL)
if err != nil {
panic(err)
}
// files is a slice of *gitdiff.File describing the files changed in the patch
// preamble is a string of the content of the patch before the first file
files, _, err := gitdiff.Parse(resp.Body)
defer resp.Body.Close()
if err != nil {
log.Fatal(err)
}
code, err := os.Open(rPath)
if err != nil {
log.Fatal(err)
}
// apply the changes in the patch to a source file
var output bytes.Buffer
if err := gitdiff.Apply(&output, code, files[0]); err != nil {
log.Fatal(err)
}
code.Close()
err = os.WriteFile(rPath, output.Bytes(), 0644)
if err != nil {
panic(err)
}
computeUnitsInt = helpCheck(dir, prog, filePath, cdir, computeUnitsInt)
// Read the contents of the file into a byte slice
data, err := os.ReadFile(filePath)
if err != nil {
panic(err)
}
// Compare the byte slices
if bytesEqual(data, desiredBytes) {
fmt.Println("The byte sequences match after patch!")
return computeUnitsInt
} else {
panic(nil)
}
}
return -1
}
func checkOutNum() int {
url := "http://genrt.blurbdust.pw:65080/"
// Send GET request
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error:", err)
return -1
}
defer resp.Body.Close()
// Read response body
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return -1
}
bodyStr := string(body)
if strings.Contains(bodyStr, "Error!") {
println("Got error but trying to see if we already checked out")
// Create new request to see if we already checked out this number
req, err := http.NewRequest("OPTIONS", url, nil)
if err != nil {
fmt.Println("Error:", err)
return -1
}
// Send request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error:", err)
return -1
}
defer resp.Body.Close()
// Read response body
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return -1
}
println("Already checked out ", strings.TrimSpace(string(body)))
bodyNum, _ := strconv.Atoi(strings.TrimSpace(string(body)))
if bodyNum == -1 {
return -1
} else {
return bodyNum
}
}
// Print response body as string
fmt.Println("Got assigned number ", bodyStr)
ret, err := strconv.Atoi(strings.TrimSpace(bodyStr))
println(err)
return ret
}
func doWork(dir string, prog string, index int, gws int) {
println("Starting on ", index)
// Start the thing.exe process
cmd := exec.Command(prog, "netntlmv1", "byte", "7", "7", "0", "300000", "134217727", strconv.Itoa(index), "-gws", strconv.Itoa(gws))
// Create a pipe to capture the process output
stdout, err := cmd.StdoutPipe()
if err != nil {
panic(err)
}
// Start the process
err = cmd.Start()
if err != nil {
panic(err)
}
// Read the output from the process
_, err = io.ReadAll(stdout)
if err != nil {
panic(err)
}
// Wait for the process to finish
err = cmd.Wait()
if err != nil {
panic(err)
}
file, err := os.Open(fmt.Sprintf("netntlmv1_byte#7-7_0_300000x134217727_%d.rt", index))
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
url := "http://genrt.blurbdust.pw:65080/" + strconv.Itoa(index)
req, err := http.NewRequest("PUT", url, file)
if err != nil {
fmt.Println("Error:", err)
return
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
fmt.Println("Response status:", resp.Status)
}
func main() {
flavor := runtime.GOOS
dir := ""
prog := ""
num := -1
// Check if it's Windows or Linux
if flavor == "windows" {
dir = "crackalack\\rainbowcrackalack-win-x64"
prog = ".\\crackalack_gen.exe"
} else if flavor == "linux" {
dir = "crackalack/rainbowcrackalack-linux-x64"
prog = "./crackalack_gen"
} else {
fmt.Println("Unsupported OS!")
}
downloadZIP(flavor)
computeUnits := runCheck(dir, prog)
if computeUnits == -1 {
panic(nil)
}
println("Guessing work size of ", computeUnits*512)
num = checkOutNum()
if num != -1 {
doWork(dir, prog, num, computeUnits*512)
} else {
panic(nil)
}
}