Skip to content

Commit

Permalink
fuzzer improvements on redirects and js changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberRoute committed Nov 22, 2023
1 parent 8cf2a1a commit a0da165
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 44 deletions.
5 changes: 4 additions & 1 deletion db/dict_short.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,7 @@
/%EXT%.backup
/%EXT%.bak
/%EXT%.cgi
/%EXT%.conf
/%EXT%.conf
/.gem
/test
/dvwa/
42 changes: 29 additions & 13 deletions pkg/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -27,7 +28,6 @@ func Get(Mu *sync.Mutex, app *config.AppConfig, domain, path string, progress fl
urjoin := "https://" + domain + path
url, err := url.Parse(urjoin)
if err != nil {
//log.Error().Err(err).Msgf("Error parsing URL: %s", urjoin)
app.ZeroLog.Error().Err(err).Msgf("Error parsing URL: %s", urjoin)
}

Expand All @@ -41,25 +41,40 @@ func Get(Mu *sync.Mutex, app *config.AppConfig, domain, path string, progress fl
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return errors.New("Redirect")
}

resp, err := client.Do(get)
if err != nil {
app.ZeroLog.Error().Err(err).Msgf("Error performing request for URL: %s", urjoin)
}
if resp != nil && resp.StatusCode == http.StatusMovedPermanently || resp.StatusCode == http.StatusFound { //status codes 301 302
// Add the RedirectPath field to the payload
redirectPath := resp.Header.Get("Location")
fmt.Println(redirectPath)
payload := &models.Url{Path: urjoin, Progress: progress, Status: float64(resp.StatusCode), RedirectPath: redirectPath}
payloadBuf := new(bytes.Buffer)
err = json.NewEncoder(payloadBuf).Encode(payload)
checkError(err)

dfileHandler(Mu, domain, urjoin, float64(resp.StatusCode), progress, redirectPath)
} else {
// For other status codes
payload := &models.Url{Path: urjoin, Progress: progress, Status: float64(resp.StatusCode)}
payloadBuf := new(bytes.Buffer)
err = json.NewEncoder(payloadBuf).Encode(payload)
checkError(err)

dfileHandler(Mu, domain, urjoin, float64(resp.StatusCode), progress, "")
}

statusCode := float64(resp.StatusCode)
payload := &models.Url{Path: urjoin, Progress: progress, Status: statusCode}
payloadBuf := new(bytes.Buffer)
err = json.NewEncoder(payloadBuf).Encode(payload)
checkError(err)

dfileHandler(Mu, domain, urjoin, statusCode, progress)
if verbose {
app.ZeroLog.Info().Msg(fmt.Sprintf("%s => %s", urjoin, resp.Status))
}
}

func dfileHandler(Mu *sync.Mutex, domain, path string, status float64, progress float32) {
func dfileHandler(Mu *sync.Mutex, domain, path string, status float64, progress float32, redirectPath string) {
Mu.Lock()
defer Mu.Unlock()

Expand All @@ -68,9 +83,10 @@ func dfileHandler(Mu *sync.Mutex, domain, path string, status float64, progress
checkError(err)

newUrl := &models.Url{
Path: path,
Status: status,
Progress: progress,
Path: path,
Status: status,
Progress: progress,
RedirectPath: redirectPath,
}

id := generateNewId(allUrls)
Expand Down Expand Up @@ -116,7 +132,7 @@ func writeUrlsToFile(filename string, allUrls models.AllUrls) error {
})

// Marshal and write the sorted URLs to the file
newUserBytes, err := json.MarshalIndent(allUrls.Urls, "", " ")
newUserBytes, err := json.Marshal(allUrls.Urls)
if err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ type TemplateData struct {

// Urls holds data to be sent to the consumer api endpoint
type Url struct {
Id int `json:"id"`
Path string `json:"path"`
Status float64 `json:"status"`
Progress float32 `json:"progress"`
Data string `json:"data"`
Id int `json:"id"`
Path string `json:"path"`
Status float64 `json:"status"`
Progress float32 `json:"progress"`
Data string `json:"data"`
RedirectPath string `json:"redirectpath"`
}

type AllUrls struct {
Expand Down
64 changes: 39 additions & 25 deletions static/js/fetchurls.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
function fetchUrls() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/consumer", true);
xhr.onload = function () {
if (this.status === 200) {
// Parse JSON response
const data = JSON.parse(this.responseText);
const xhr = new XMLHttpRequest();
xhr.open("GET", "/consumer", true);
xhr.onload = function () {
if (this.status === 200) {
// Parse JSON response
const data = JSON.parse(this.responseText);

// Get container element
const container = document.getElementById("container");
var bar = document.querySelector(".progress-bar");
var speedElement = document.getElementById("data");
// Clear loading message and append data
container.innerHTML = "";
data.Urls.forEach(url => {
// Get container element
const container = document.getElementById("container");
var bar = document.querySelector(".progress-bar");
var speedElement = document.getElementById("data");
// Clear loading message and append data
container.innerHTML = "";
data.Urls.forEach(url => {
// Update the speedElement for each URL
bar.style.width = url.progress + "%";
speedElement.innerText = url.data;
bar.innerText = url.progress.toFixed(0) + "%"; // format the percentage to one decimal place
if (url.status === 200) { // only display 200 status codes in green
container.innerHTML += `<p>${url.id} <a href="${url.path}" target="_blank">${url.path}</a> - <span style="color: green;"> http code: ${url.status} progress: ${url.progress} ${url.data}</span></p>`;
}
});
} else {
console.error("Error fetching data");
}
}
xhr.send();
}
bar.innerText = url.progress.toFixed(0) + "%";
if (url.status === 200 || url.status === 301 || url.status === 302) {
let urlDisplay;
if (url.status === 301) {
// For 301 status code, use redirectpath
urlDisplay = `<p>${url.id} <a href="${url.path}" target="_blank">${url.path}</a> - <span style="color: orange;">REDIRECTS TO:</span> <a href="${url.redirectpath}" target="_blank">${url.redirectpath}</a> - <span style="color: green;"> http code: ${url.status} progress: ${url.progress} ${url.data}</span></p>`;
} else if (url.status === 302) {
// For 302 status code, concatenate path and redirectpath
let targetPath = url.redirectpath ? url.path + url.redirectpath : url.path;
urlDisplay = `<p>${url.id} <a href="${url.path}" target="_blank">${url.path}</a> - <span style="color: orange;">REDIRECTS TO:</span> <a href="${targetPath}" target="_blank">${targetPath}</a> - <span style="color: green;"> http code: ${url.status} progress: ${url.progress} ${url.data}</span></p>`;
} else {
// For other status codes (200), use the original path
urlDisplay = `<p>${url.id} <a href="${url.path}" target="_blank">${url.path}</a> - <span style="color: green;"> http code: ${url.status} progress: ${url.progress.toFixed(0)}% ${url.data}</span></p>`;
}

container.innerHTML += urlDisplay;
}
});
// Update the overall progress bar and data element
} else {
console.error("Error fetching data");
}
};
xhr.send();
}

// Call fetchUrls() when page is loaded
// Call fetchUrls() when the page is loaded
window.onload = fetchUrls;
setInterval(fetchUrls, 1000);

0 comments on commit a0da165

Please sign in to comment.