Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<p align="center">
<a href="https://github.com/hahwul/dalfox/actions/workflows/go.yml"><img src="https://github.com/hahwul/dalfox/actions/workflows/go.yml/badge.svg"></a>
<a href=""><img src="https://api.codacy.com/project/badge/Grade/17cac7b8d1e849a688577f2bbdd6ecd0"></a>
<a href="https://goreportcard.com/report/github.com/hahwul/dalfox"><img src="https://goreportcard.com/badge/github.com/hahwul/dalfox"></a>
<a href="https://codecov.io/gh/hahwul/dalfox"><img src="https://codecov.io/gh/hahwul/dalfox/branch/main/graph/badge.svg"/></a>
<a href="https://twitter.com/intent/follow?screen_name=hahwul"><img src="https://img.shields.io/twitter/follow/hahwul?style=flat&logo=x"></a>
<a href="https://goreportcard.com/report/github.com/hahwul/dalfox/v2"><img src="https://goreportcard.com/badge/github.com/hahwul/dalfox/v2"></a>
<a href="https://x.com/intent/follow?screen_name=hahwul"><img src="https://img.shields.io/twitter/follow/hahwul?style=flat&logo=x"></a>
<a href=""><img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat"></a>
</p>

Expand Down
2 changes: 0 additions & 2 deletions codecov.yml

This file was deleted.

37 changes: 37 additions & 0 deletions pkg/scanning/entity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package scanning

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestInterfaceGetGfXSS(t *testing.T) {
list, length := InterfaceGetGfXSS()
assert.NotNil(t, list)
assert.Greater(t, length, 0)
}

func TestInterfaceGetEventHandlers(t *testing.T) {
list, length := InterfaceGetEventHandlers()
assert.NotNil(t, list)
assert.Greater(t, length, 0)
}

func TestInterfaceGetTags(t *testing.T) {
list, length := InterfaceGetTags()
assert.NotNil(t, list)
assert.Greater(t, length, 0)
}

func TestInterfaceGetSpecialChar(t *testing.T) {
list, length := InterfaceGetSpecialChar()
assert.NotNil(t, list)
assert.Greater(t, length, 0)
}

func TestInterfaceGetUsefulCode(t *testing.T) {
list, length := InterfaceGetUsefulCode()
assert.NotNil(t, list)
assert.Greater(t, length, 0)
}
106 changes: 106 additions & 0 deletions pkg/scanning/ignore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package scanning

import "testing"

func Test_isAllowType(t *testing.T) {
type args struct {
contentType string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Allowed type - text/html",
args: args{
contentType: "text/html",
},
want: true,
},
{
name: "Not allowed type - application/json",
args: args{
contentType: "application/json",
},
want: false,
},
{
name: "Not allowed type - text/javascript",
args: args{
contentType: "text/javascript",
},
want: false,
},
{
name: "Allowed type with charset - text/html; charset=UTF-8",
args: args{
contentType: "text/html; charset=UTF-8",
},
want: true,
},
{
name: "Not allowed type with charset - application/json; charset=UTF-8",
args: args{
contentType: "application/json; charset=UTF-8",
},
want: false,
},
{
name: "Allowed type - application/xml",
args: args{
contentType: "application/xml",
},
want: true,
},
{
name: "Not allowed type - image/jpeg",
args: args{
contentType: "image/jpeg",
},
want: false,
},
{
name: "Not allowed type - image/png",
args: args{
contentType: "image/png",
},
want: false,
},
{
name: "Not allowed type - text/plain",
args: args{
contentType: "text/plain",
},
want: false,
},
{
name: "Not allowed type - text/css",
args: args{
contentType: "text/css",
},
want: false,
},
{
name: "Not allowed type - application/rss+xml",
args: args{
contentType: "application/rss+xml",
},
want: false,
},
{
name: "Allowed type - text/xml",
args: args{
contentType: "text/xml",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isAllowType(tt.args.contentType); got != tt.want {
t.Errorf("isAllowType() = %v, want %v", got, tt.want)
}
})
}
}
60 changes: 60 additions & 0 deletions pkg/scanning/multicast_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package scanning

import (
"reflect"
"testing"
)

func TestMakeTargetSlice(t *testing.T) {
type args struct {
targets []string
}
tests := []struct {
name string
args args
want map[string][]string
}{
{
name: "Single target",
args: args{
targets: []string{"http://example.com"},
},
want: map[string][]string{
"example.com": {"http://example.com"},
},
},
{
name: "Multiple targets with same hostname",
args: args{
targets: []string{"http://example.com", "https://example.com/path"},
},
want: map[string][]string{
"example.com": {"http://example.com", "https://example.com/path"},
},
},
{
name: "Multiple targets with different hostnames",
args: args{
targets: []string{"http://example.com", "https://another.com"},
},
want: map[string][]string{
"example.com": {"http://example.com"},
"another.com": {"https://another.com"},
},
},
{
name: "Empty targets",
args: args{
targets: []string{},
},
want: map[string][]string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MakeTargetSlice(tt.args.targets); !reflect.DeepEqual(got, tt.want) {
t.Errorf("MakeTargetSlice() = %v, want %v", got, tt.want)
}
})
}
}
124 changes: 124 additions & 0 deletions pkg/scanning/poc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package scanning

import (
"io"
"io/ioutil"
"net/http"
"strings"
"testing"

"github.com/hahwul/dalfox/v2/pkg/model"
)

func TestMakePoC(t *testing.T) {
type args struct {
poc string
req *http.Request
options model.Options
}
tests := []struct {
name string
args args
want string
}{
{
name: "HTTP RAW REQUEST",
args: args{
poc: "http://example.com",
req: func() *http.Request {
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
return req
}(),
options: model.Options{
PoCType: "http-request",
},
},
want: "HTTP RAW REQUEST\nGET / HTTP/1.1\r\nHost: example.com\r\nUser-Agent: Go-http-client/1.1\r\nAccept-Encoding: gzip\r\n\r\n",
},
{
name: "curl with body",
args: args{
poc: "http://example.com",
req: func() *http.Request {
body := ioutil.NopCloser(strings.NewReader("test body"))
req, _ := http.NewRequest(http.MethodPost, "http://example.com", body)
req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("test body")), nil
}
return req
}(),
options: model.Options{
PoCType: "curl",
},
},
want: "curl -i -k -X POST http://example.com -d \"test body\"",
},
{
name: "httpie with body",
args: args{
poc: "http://example.com",
req: func() *http.Request {
body := ioutil.NopCloser(strings.NewReader("test body"))
req, _ := http.NewRequest(http.MethodPost, "http://example.com", body)
req.GetBody = func() (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader("test body")), nil
}
return req
}(),
options: model.Options{
PoCType: "httpie",
},
},
want: "http POST http://example.com \"test body\" --verify=false -f",
},
{
name: "curl without body",
args: args{
poc: "http://example.com",
req: func() *http.Request {
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
return req
}(),
options: model.Options{
PoCType: "curl",
},
},
want: "curl -i -k http://example.com",
},
{
name: "httpie without body",
args: args{
poc: "http://example.com",
req: func() *http.Request {
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
return req
}(),
options: model.Options{
PoCType: "httpie",
},
},
want: "http http://example.com --verify=false",
},
{
name: "default without body",
args: args{
poc: "http://example.com",
req: func() *http.Request {
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
return req
}(),
options: model.Options{
PoCType: "default",
},
},
want: "http://example.com",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MakePoC(tt.args.poc, tt.args.req, tt.args.options); got != tt.want {
t.Errorf("MakePoC() = %v, want %v", got, tt.want)
}
})
}
}
Loading