Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny-Dasilva committed Oct 16, 2023
1 parent 7ad1adc commit 18ceaf5
Show file tree
Hide file tree
Showing 12 changed files with 423 additions and 15 deletions.
37 changes: 32 additions & 5 deletions cycletls/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ import (
"strings"
)

type FormField struct {
Name string
Value string
}

type FormFile struct {
Name string
Filename string
ContentType string
Data interface{} // You can use the empty interface to allow string or byte slice (i.e. []byte) as the data type
}

type FormData struct {
Fields []FormField
Files []FormFile
}


// Options sets CycleTLS client options
type Options struct {
URL string `json:"url"`
Expand All @@ -27,7 +45,8 @@ type Options struct {
Timeout int `json:"timeout"`
DisableRedirect bool `json:"disableRedirect"`
HeaderOrder []string `json:"headerOrder"`
OrderAsProvided bool `json:"orderAsProvided"` //TODO
OrderAsProvided bool `json:"orderAsProvided"` //TODO\
Form FormData `json:"form"` //used for conversion for js
}

type cycleTLSRequest struct {
Expand Down Expand Up @@ -85,8 +104,15 @@ func processRequest(request cycleTLSRequest) (result fullRequest) {
if err != nil {
log.Fatal(err)
}
data := url.Values{}
data.Add("key2", "value2")
for _, field := range request.Options.Form.Fields {
data.Set(field.Name, field.Value)
}

req, err := http.NewRequest(strings.ToUpper(request.Options.Method), request.Options.URL, strings.NewReader(request.Options.Body))
// Encode the form data
encodedData := data.Encode()
req, err := http.NewRequest(strings.ToUpper(request.Options.Method), request.Options.URL, strings.NewReader(encodedData))
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -285,16 +311,17 @@ func readSocket(reqChan chan fullRequest, c *websocket.Conn) {
return
}
request := new(cycleTLSRequest)

err = json.Unmarshal(message, &request)
if err != nil {
log.Print("Unmarshal Error", err)
return
}
log.Print("request", request)


reply := processRequest(*request)
// reply := processRequest(*request)

reqChan <- reply
// reqChan <- reply
}
}

Expand Down
77 changes: 77 additions & 0 deletions cycletls/tests/integration/form.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//go:build integration
// +build integration

package main

import (
//"fmt"
"log"
// "net/http"
// "net/url"
// "strings"
// "io/ioutil"
// "strconv"

cycletls "github.com/Danny-Dasilva/CycleTLS/cycletls"
)


func main() {
client := cycletls.Init()
formData := cycletls.FormData{
Fields: []cycletls.FormField{
{Name: "CustTel", Value: "A"},
{Name: "CustTel", Value: "1111111111"},
{Name: "Size", Value: "small"},
{Name: "Delivery", Value: "11:15"},
{Name: "Comments", Value: "example test paragraph"},
},
}
resp, err := client.Do("https://httpbin.org/post", cycletls.Options{
Body: "",
Ja3: "771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0",
UserAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
Headers: map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
Form: formData,
}, "POST")
if err != nil {
log.Print("Request Failed: " + err.Error())
}

log.Println(resp)
// Create the form data
// data := url.Values{}
// data.Add("key2", "value2")
// for _, field := range formData.Fields {
// data.Set(field.Name, field.Value)
// }

// // Encode the form data
// encodedData := data.Encode()


// // Create the HTTP request
// req, err := http.NewRequest("POST", "https://httpbin.org/post", strings.NewReader(encodedData))
// if err != nil {
// // handle error
// }
// req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
// req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
// // Send the request
// client := &http.Client{}
// resp, err := client.Do(req)
// if err != nil {
// // handle error
// }

// defer resp.Body.Close()

// log.Println(resp)
// body, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// panic(err)
// }

// log.Println(string(body))

}
67 changes: 67 additions & 0 deletions cycletls/tests/integration/form_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//go:build integration
// +build integration

package cycletls_test

import (
//"fmt"
"log"
"testing"
"net/http"
"net/url"
"strings"
"io/ioutil"
cycletls "github.com/Danny-Dasilva/CycleTLS/cycletls"
)


func TestDefaultHeaderOrder(t *testing.T) {
// client := cycletls.Init()
formData := cycletls.FormData{
Fields: []cycletls.FormField{
{Name: "CustTel", Value: "A"},
{Name: "CustTel", Value: "1111111111"},
{Name: "Size", Value: "small"},
{Name: "Toppings", Value: "cheese&delivery"},
{Name: "Delivery", Value: "11:15"},
{Name: "Comments", Value: "example test paragraph"},
},
}
// resp, err := client.Do("https://httpbin.org/forms/post", cycletls.Options{
// Body: "",
// Ja3: "771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-51-57-47-53-10,0-23-65281-10-11-35-16-5-51-43-13-45-28-21,29-23-24-25-256-257,0",
// UserAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0",
// Form: formData,
// }, "POST")
// if err != nil {
// log.Print("Request Failed: " + err.Error())
// }

// Create the form data

data := url.Values{}

for _, field := range formData.Fields {
data.Set(field.Name, field.Value)
}

// Encode the form data
encodedData := data.Encode()

// Create the HTTP request
req, err := http.NewRequest("POST", "https://httpbin.org/forms/post", strings.NewReader(encodedData))
if err != nil {
// handle error
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

// Send the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
// handle error
}
log.Println(resp)

defer resp.Body.Close()
}
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
],
"author": "Danny-Dasilva",
"scripts": {
"build:go:freebsd:amd64": " cross-env GO111MODULE=off GOOS=freebsd GOARCH=amd64 go build -o ./dist/index-freebsd ./src && chmod +x ./dist/index-freebsd",
"build:go:linux:amd64": " cross-env GO111MODULE=off GOOS=linux GOARCH=amd64 go build -o ./dist/index ./src && chmod +x ./dist/index",
"build:go:linux:arm": " cross-env GO111MODULE=off GOOS=linux GOARCH=arm go build -o ./dist/index-arm ./src && chmod +x ./dist/index-arm",
"build:go:linux:arm64": " cross-env GO111MODULE=off GOOS=linux GOARCH=arm64 go build -o ./dist/index-arm64 ./src && chmod +x ./dist/index-arm64",
"build:go:mac:amd64": " cross-env GO111MODULE=off GOOS=darwin GOARCH=amd64 go build -o ./dist/index-mac ./src && chmod +x ./dist/index-mac",
"build:go:windows:amd64": " cross-env GO111MODULE=off GOOS=windows GOARCH=amd64 go build -o ./dist/index.exe ./src",
"build:go": "concurrently npm:build:go:*",
"build": "tsc",
"prebuild:go": "cross-env GO111MODULE=off go get github.com/Danny-Dasilva/CycleTLS/cycletls",
"build:linux": " cross-env GO111MODULE=off GOOS=linux GOARCH=amd64 go build -o ./dist/index ./src && chmod +x ./dist/index",
"build:mac": " cross-env GO111MODULE=off GOOS=darwin GOARCH=amd64 go build -o ./dist/index-mac ./src && chmod +x ./dist/index-mac",
"build:windows": " cross-env GO111MODULE=off GOOS=windows GOARCH=amd64 go build -o ./dist/index.exe ./src",
"build:linux:amd64": " cross-env GO111MODULE=off GOOS=linux GOARCH=amd64 go build -o ./dist/index ./src && chmod +x ./dist/index",
"build:linux:arm": " cross-env GO111MODULE=off GOOS=linux GOARCH=arm go build -o ./dist/index-arm ./src && chmod +x ./dist/index-arm",
"build:linux:arm64": " cross-env GO111MODULE=off GOOS=linux GOARCH=arm64 go build -o ./dist/index-arm64 ./src && chmod +x ./dist/index-arm64",
"build:freebsd:amd64": " cross-env GO111MODULE=off GOOS=freebsd GOARCH=amd64 go build -o ./dist/index-freebsd ./src && chmod +x ./dist/index-freebsd",
"build:mac:amd64": " cross-env GO111MODULE=off GOOS=darwin GOARCH=amd64 go build -o ./dist/index-mac ./src && chmod +x ./dist/index-mac",
"build:windows:amd64": " cross-env GO111MODULE=off GOOS=windows GOARCH=amd64 go build -o ./dist/index.exe ./src",
"build": "concurrently npm:build*",
"build-frontend": "tsc",
"prebuild": "cross-env GO111MODULE=off go get github.com/Danny-Dasilva/CycleTLS/cycletls",
"prepare": "npm run build && npm run build:go",
"test": "jest"
},
Expand Down
29 changes: 29 additions & 0 deletions tes2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"./cycletls"
"log"
"runtime"
"time"
// "net/http"
)

func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

start := time.Now()
defer func() {
log.Println("Execution Time: ", time.Since(start))
}()
client := cycletls.Init()
response, err := client.Do("https://www.google.com", cycletls.Options{
Body: "",
Ja3: "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27,29-23-24,0",
UserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36",
}, "GET")
if err != nil {
log.Print("Request Failed: " + err.Error())
}
log.Println(response.Status,)

}
29 changes: 29 additions & 0 deletions test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"./cycletls"
"log"
"runtime"
"time"
// "net/http"
)

func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

start := time.Now()
defer func() {
log.Println("Execution Time: ", time.Since(start))
}()
client := cycletls.Init()
response, err := client.Do("https://www.google.com", cycletls.Options{
Body: "",
Ja3: "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-17513,29-23-24,0", //something invalid
UserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36",
}, "GET")
if err != nil {
log.Print("Request Failed: " + err.Error())
}
log.Println(response.Body,)

}
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require('fs');

const filePath = './test.go';

fs.readFile(filePath, (err, data) => {
if (err) {
// handle error
return;
}

// encode the file contents as a base64 string
const base64Data = Buffer.from(data).toString('base64');
console.log(base64Data);
});

console.log(fs.readFileSync(filePath, { encoding: 'base64' }))
5 changes: 5 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import requests
files = {'foo': 'bar'}

print(requests.Request('POST', 'http://httpbin.org/post', files=files).prepare().body.decode('utf8'))
print(requests.Request('POST', 'http://httpbin.org/post', files=files).prepare().body.decode('utf8'))
Loading

0 comments on commit 18ceaf5

Please sign in to comment.