-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implementation of query package and utils with temporary main
- Loading branch information
1 parent
2e47a15
commit 570b74e
Showing
4 changed files
with
49 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
package main | ||
package query | ||
|
||
import ( | ||
"time" | ||
"bruteforce/src/matching" | ||
"bruteforce/src/utils" | ||
"time" | ||
) | ||
|
||
type forceData struct { | ||
worker int | ||
wordList string | ||
url string | ||
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 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") | ||
func MainRequest(data ForceData, criteria matcher.MatchCriteria) { | ||
channel := make(chan string) | ||
wordArray := utils.GetFileContent(data.WordList) | ||
|
||
for i := 0 ;i < data.worker; i++ { | ||
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) | ||
for i := 0; i < len(wordArray); i++ { | ||
channel <- wordArray[i] | ||
} | ||
time.Sleep(1 * time.Second) | ||
close(channel) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
package main | ||
package query | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
func queryExecute(data forceData, path string, method string) { | ||
|
||
func QueryExecute(data ForceData, path string, method string) { | ||
client := &http.Client{} | ||
req, err := http.NewRequest(method, data.url + path, nil) | ||
req, err := http.NewRequest(method, data.Url+path, nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
log.Fatal(err) | ||
} | ||
|
||
q := req.URL.Query() | ||
|
||
req.URL.RawQuery = q.Encode() | ||
|
||
resp, err := client.Do(req) | ||
if err != nil { | ||
fmt.Println(err) | ||
fmt.Println(err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println(string(body)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
package main | ||
package utils | ||
|
||
import ( | ||
"os" | ||
"fmt" | ||
"log" | ||
"log" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func GetFileContent(filePath string) []string{ | ||
body, err := os.ReadFile(filePath) | ||
if err != nil { | ||
log.Fatalf("unable to read file: %v", err) | ||
} | ||
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 | ||
} | ||
} |