first commit

This commit is contained in:
2025-02-03 20:48:19 +01:00
commit 4399c4e02e
10 changed files with 278 additions and 0 deletions

79
core/core.go Normal file
View File

@ -0,0 +1,79 @@
package core
import (
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"encoding/hex"
"fmt"
"net/url"
"regexp"
"strings"
"unicode"
)
func DecryptURLs(jk string, crypted string) ([]string, error) {
key, err := convertJKToKey(jk)
if err != nil {
return []string{}, err
}
ciphertext, err := base64.StdEncoding.DecodeString(crypted)
if err != nil {
return []string{}, err
}
block, err := aes.NewCipher([]byte(key))
if err != nil {
return []string{}, err
}
if len(ciphertext)%aes.BlockSize != 0 {
return []string{}, fmt.Errorf("ciphertext has invalid length")
}
mode := cipher.NewCBCDecrypter(block, []byte(key))
mode.CryptBlocks(ciphertext, ciphertext)
return ExtractURLsFromString(fmt.Sprintf("%s", ciphertext)), nil
}
func ExtractURLsFromString(s string) []string {
URLs := []string{}
for _, line := range strings.Split(s, "\n") {
line = strings.TrimSpace(line)
line = strings.Map(func(r rune) rune {
if unicode.IsPrint(r) {
return r
}
return -1
}, line)
parsedURL, err := url.Parse(line)
if err != nil || parsedURL.Scheme == "" || parsedURL.Host == "" {
continue
}
URLs = append(URLs, line)
}
return URLs
}
func convertJKToKey(jk string) (string, error) {
re := regexp.MustCompile(`return '(\d{32})'`)
matches := re.FindStringSubmatch(jk)
if len(matches) < 2 {
return "", fmt.Errorf("no key found for jk: %s", jk)
}
base10key, err := hex.DecodeString(matches[1])
if err != nil {
return "", fmt.Errorf("jk is invalid: %s", jk)
}
return fmt.Sprintf("%s", base10key), nil
}

44
core/core_test.go Normal file
View File

@ -0,0 +1,44 @@
package core
import "testing"
func TestConvertJKToKey(t *testing.T) {
type args struct {
jk string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "36323334313036343130323934373732",
args: args{
jk: "function f(){ return '36323334313036343130323934373732';}",
},
want: "6234106410294772",
wantErr: false,
},
{
name: "36373434353538393131373730353833",
args: args{
jk: "function f(){ return '36373434353538393131373730353833';}",
},
want: "6744558911770583",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := convertJKToKey(tt.args.jk)
if (err != nil) != tt.wantErr {
t.Errorf("convertJKToKey() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("convertJKToKey() = %v, want %v", got, tt.want)
}
})
}
}