Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gustave/request to Connect to Init-Matching adapted #5

Merged
merged 11 commits into from
Jul 17, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bruteforce
40 changes: 40 additions & 0 deletions cmd/callWorker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"time"
)

type forceData struct {
worker int
wordList string
url string
}

func executeQueryFromFile(data forceData, currentPath chan string) {
for taskData := range currentPath{
queryExecute(data, taskData, "POST")
}
}

func mainRequest(data forceData) {
channel := make(chan string)
wordArray := GetFileContent("../wordList/rootList")

for i := 0 ;i < data.worker; i++ {
go executeQueryFromFile(data, channel)
}
for i := 0; i < len(wordArray); i++ {
channel <- wordArray[i]
}
time.Sleep(1 * time.Second)
close(channel)
}

func main () {
data := forceData {
worker: 3,
wordList: "../wordList/rootList",
url: "http://localhost:3333",
}
mainRequest(data);
}
18 changes: 18 additions & 0 deletions cmd/getFile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"os"
"fmt"
"log"
"strings"
)

func GetFileContent(filePath string) []string{
body, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("unable to read file: %v", err)
}
dataTab := strings.Split(string(body), "\n")
fmt.Println(dataTab[0])
return dataTab
}
35 changes: 35 additions & 0 deletions cmd/queryExecute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"log"
"io/ioutil"
"net/http"
)

func queryExecute(data forceData, path string, method string) {

client := &http.Client{}
req, err := http.NewRequest(method, data.url + path, nil)
if err != nil {
log.Fatal(err)
}

q := req.URL.Query()

req.URL.RawQuery = q.Encode()

resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
}

defer resp.Body.Close()

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

fmt.Println(string(body))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BruteForce
module bruteforce

go 1.19
32 changes: 32 additions & 0 deletions src/query/callWorker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"time"
)

type forceData struct {
worker int
wordList string
url string
}

func executeQueryFromFile(data forceData, currentPath chan string) {
for taskData := range currentPath{
queryExecute(data, taskData, "POST")
}
}

func mainRequest(data forceData) {
channel := make(chan string)
wordArray := GetFileContent("../wordList/rootList")

for i := 0 ;i < data.worker; i++ {
go executeQueryFromFile(data, channel)
}
for i := 0; i < len(wordArray); i++ {
channel <- wordArray[i]
}
time.Sleep(1 * time.Second)
close(channel)
}

35 changes: 35 additions & 0 deletions src/query/queryExecute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"log"
"io/ioutil"
"net/http"
)

func queryExecute(data forceData, path string, method string) {

client := &http.Client{}
req, err := http.NewRequest(method, data.url + path, nil)
if err != nil {
log.Fatal(err)
}

q := req.URL.Query()

req.URL.RawQuery = q.Encode()

resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
}

defer resp.Body.Close()

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

fmt.Println(string(body))
}
18 changes: 18 additions & 0 deletions src/utils/getFile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"os"
"fmt"
"log"
"strings"
)

func GetFileContent(filePath string) []string{
body, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("unable to read file: %v", err)
}
dataTab := strings.Split(string(body), "\n")
fmt.Println(dataTab[0])
return dataTab
}
Loading