first commit
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| /build/* | ||||
| !/build/.gitkeep | ||||
							
								
								
									
										9
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								LICENSE
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| MIT License | ||||
|  | ||||
| Copyright (c) 2025 Andreas Schulte | ||||
|  | ||||
| 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. | ||||
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| # clickNgo | ||||
|  | ||||
| A minimalistic implementation of **Click'n'Load 2** (as used by [JDownloader](https://jdownloader.org/knowledge/wiki/glossary/cnl2)) written in **Go**. The project is intentionally kept small, follows the **KISS principle**, and has **zero external dependencies**. | ||||
|  | ||||
| ## Installation | ||||
|  | ||||
| To get started with clickNgo, follow these steps: | ||||
|  | ||||
| ```bash | ||||
| git clone https://git.0x0001f346.de/andreas/clickNgo.git | ||||
| cd clickNgo | ||||
| go build -o ./build/ . | ||||
| ``` | ||||
|  | ||||
| ## Usage | ||||
|  | ||||
| Once built, you can run clickNgo with the following command: | ||||
| ```bash | ||||
| build/clickNgo | ||||
| ``` | ||||
|  | ||||
| Simply start the application, click on a corresponding button in your browser, and admire the decrypted links in your terminal. | ||||
							
								
								
									
										0
									
								
								build/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								build/.gitkeep
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										79
									
								
								core/core.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								core/core.go
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										44
									
								
								core/core_test.go
									
									
									
									
									
										Normal 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) | ||||
| 			} | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										25
									
								
								handler/get.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								handler/get.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| package handler | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net/http" | ||||
| ) | ||||
|  | ||||
| func GETIndex(w http.ResponseWriter, r *http.Request) { | ||||
| 	if r.Method != http.MethodGet { | ||||
| 		http.Error(w, "405 Method Not Allowed", http.StatusMethodNotAllowed) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	fmt.Fprintln(w, "clickNgo") | ||||
| } | ||||
|  | ||||
| func GETJdcheckJS(w http.ResponseWriter, r *http.Request) { | ||||
| 	if r.Method != http.MethodGet { | ||||
| 		http.Error(w, "405 Method Not Allowed", http.StatusMethodNotAllowed) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	w.Header().Set("Content-Type", "text/javascript") | ||||
| 	fmt.Fprintln(w, "jdownloader=true; var version='17461';") | ||||
| } | ||||
							
								
								
									
										52
									
								
								handler/post.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								handler/post.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| package handler | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net/http" | ||||
|  | ||||
| 	"git.0x0001f346.de/andreas/clickNgo/core" | ||||
| ) | ||||
|  | ||||
| func POSTFlashAdd(w http.ResponseWriter, r *http.Request) { | ||||
| 	if r.Method != http.MethodPost { | ||||
| 		http.Error(w, "405 Method Not Allowed", http.StatusMethodNotAllowed) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	r.ParseForm() | ||||
| 	URLs := core.ExtractURLsFromString(r.PostFormValue("urls")) | ||||
| 	if len(URLs) == 0 { | ||||
| 		http.Error(w, "400 Bad Request", http.StatusBadRequest) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	printURLs(URLs) | ||||
|  | ||||
| 	fmt.Fprintln(w, "OK") | ||||
| } | ||||
|  | ||||
| func POSTFlashAddcrypted2(w http.ResponseWriter, r *http.Request) { | ||||
| 	if r.Method != http.MethodPost { | ||||
| 		http.Error(w, "405 Method Not Allowed", http.StatusMethodNotAllowed) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	r.ParseForm() | ||||
| 	URLs, err := core.DecryptURLs(r.PostFormValue("jk"), r.PostFormValue("crypted")) | ||||
| 	if err != nil || len(URLs) == 0 { | ||||
| 		http.Error(w, "400 Bad Request", http.StatusBadRequest) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	printURLs(URLs) | ||||
|  | ||||
| 	fmt.Fprintln(w, "OK") | ||||
| } | ||||
|  | ||||
| func printURLs(URLs []string) { | ||||
| 	for _, url := range URLs { | ||||
| 		fmt.Println(url) | ||||
| 	} | ||||
|  | ||||
| 	fmt.Println("") | ||||
| } | ||||
							
								
								
									
										42
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"net/http" | ||||
| 	"os" | ||||
| 	"os/signal" | ||||
| 	"syscall" | ||||
| 	"time" | ||||
|  | ||||
| 	"git.0x0001f346.de/andreas/clickNgo/handler" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	sigChan := make(chan os.Signal, 1) | ||||
| 	signal.Notify(sigChan, syscall.SIGINT) | ||||
|  | ||||
| 	server := &http.Server{ | ||||
| 		Addr: ":9666", | ||||
| 	} | ||||
|  | ||||
| 	go func() { | ||||
| 		http.HandleFunc("/", handler.GETIndex) | ||||
| 		http.HandleFunc("/jdcheck.js", handler.GETJdcheckJS) | ||||
| 		http.HandleFunc("/flash/add", handler.POSTFlashAdd) | ||||
| 		http.HandleFunc("/flash/addcrypted2", handler.POSTFlashAddcrypted2) | ||||
|  | ||||
| 		if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||||
| 			fmt.Printf("[Error] %v\n", err) | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| 	<-sigChan | ||||
|  | ||||
| 	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||||
| 	defer cancel() | ||||
|  | ||||
| 	server.Shutdown(ctx) | ||||
|  | ||||
| 	os.Exit(0) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user