initial commit

This commit is contained in:
quackerd 2022-04-28 17:18:55 +08:00
parent 24bb806d83
commit 7ad92f2b49
5 changed files with 157 additions and 0 deletions

118
crargo.go Normal file
View File

@ -0,0 +1,118 @@
package main
import (
"bufio"
"bytes"
"fmt"
"log"
"os"
"strconv"
"sync/atomic"
"time"
"github.com/mholt/archiver"
)
func crack(tid int, file []byte, fn string, passwords []string, found **string, stop *bool, total *uint64, exited *int32) {
fmt.Println("Thread", tid, ": starting with", len(passwords), "passwords...")
rar := archiver.NewRar()
rar.ContinueOnError = false
rar.ImplicitTopLevelFolder = true
rar.OverwriteExisting = true
rar.MkdirAll = false
for i := 0; i < len(passwords); i++ {
if *stop {
goto end
}
cur_pass := passwords[i]
rar.Password = cur_pass
reader := bytes.NewReader(file)
err := rar.Open(reader, 0)
if err != nil {
log.Fatal(err)
}
_, err = rar.Read()
if err == nil {
*found = &passwords[i]
goto end
}
rar.Close()
atomic.AddUint64(total, 1)
}
end:
fmt.Println("Thread", tid, ": stopped.")
atomic.AddInt32(exited, 1)
}
func main() {
if len(os.Args) != 4 {
log.Fatal("Invalid arguments. Usage: go run crargo.go [file path] [dictionary path] [thread count]")
}
fn := os.Args[1]
dictfn := os.Args[2]
var dict []string
threads, err := strconv.Atoi(os.Args[3])
if err != nil || threads <= 0 {
log.Fatal("Invalid thread count: \"", os.Args[3], "\"")
}
fmt.Println("Cracking \"", fn, "\" with dict \"", dictfn, "\" using ", threads, " threads...")
fmt.Println("Reading archive...")
fb, err := os.ReadFile(fn)
if err != nil {
log.Fatal(err)
}
fmt.Println("Reading dictionary...")
dictf, err := os.Open(dictfn)
if err != nil {
log.Fatal(err)
}
scanner := bufio.NewScanner(dictf)
for scanner.Scan() {
dict = append(dict, scanner.Text())
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
fmt.Println("Processed", len(dict), "dictionary entries.")
each_thread := len(dict) / threads
var found *string = nil
var stop bool = false
var total uint64 = 0
var exited int32 = 0
for i := 0; i < threads; i++ {
go crack(i, fb, fn, dict[each_thread*i:each_thread*(i+1)], &found, &stop, &total, &exited)
}
var sec int = 0
for {
time.Sleep(1 * time.Second)
sec++
if found != nil {
fmt.Print("Found password: \"", *found, "\"\n")
stop = true
for int(atomic.LoadInt32(&exited)) < threads {
}
break
} else if int(atomic.LoadInt32(&exited)) == threads {
fmt.Println("No password found!")
break
} else {
tot := atomic.LoadUint64(&total)
fmt.Println("main: total tries: ", tot, "(", tot/uint64(sec), " req/s)")
}
}
}

13
go.mod Normal file
View File

@ -0,0 +1,13 @@
module github.com/mholt/archiver/cmd/arc/v2
go 1.18
require (
github.com/dsnet/compress v0.0.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/mholt/archiver v3.1.1+incompatible // indirect
github.com/nwaples/rardecode v1.1.3 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
)

18
go.sum Normal file
View File

@ -0,0 +1,18 @@
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU=
github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc=
github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=

8
test.dict Normal file
View File

@ -0,0 +1,8 @@
dflkhjaslhdkjf
gjhklhjkdf
sdfkjhshk
asdkjahskjd
!@#!@$%@#!@
asdfkjhasdhkjfk
yourmom
#!@!$@#!@#

BIN
test.rar Normal file

Binary file not shown.