Skip to content

Commit

Permalink
Merge pull request #22 from surface-security/dev-126
Browse files Browse the repository at this point in the history
Update to v1.2.6
  • Loading branch information
fopina authored Feb 9, 2023
2 parents 2f77c39 + da688ea commit f5cff8c
Show file tree
Hide file tree
Showing 51 changed files with 3,788 additions and 720 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 🙏🏻 Lint Test

on:
pull_request:
workflow_dispatch:

jobs:
lint:
name: Lint Test
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Checkout code
uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/[email protected]
with:
version: latest
args: --timeout 5m
working-directory: .
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.vscode
.idea/
.vscode/
cmd/httpx/httpx
/test/output
integration_tests/httpx
integration_tests/integration-test
cmd/functional-test/httpx_dev
cmd/functional-test/functional-test
cmd/functional-test/httpx
cmd/functional-test/*.cfg
13 changes: 13 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ builds:
goarch: '386'
- goos: windows
goarch: 'arm'
- goos: windows
goarch: 'arm64'

binary: '{{ .ProjectName }}'
main: cmd/httpx/httpx.go
Expand All @@ -31,3 +33,14 @@ archives:

checksum:
algorithm: sha256

announce:
slack:
enabled: true
channel: '#release'
username: GoReleaser
message_template: 'New Release: {{ .ProjectName }} {{ .Tag }} is published! Check it out at {{ .ReleaseURL }}'

discord:
enabled: true
message_template: '**New Release: {{ .ProjectName }} {{.Tag}}** is published! Check it out at {{ .ReleaseURL }}'
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.17.0-alpine AS builder
FROM golang:1.19.4-alpine AS builder
WORKDIR /go/src/httpx
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -v -ldflags="-s -w" -o "/httpx" cmd/httpx/httpx.go
RUN CGO_ENABLED=0 go build -v -ldflags="-s -w" -o "/httpx" cmd/httpx/httpx.go


FROM alpine:3.12
Expand Down
83 changes: 83 additions & 0 deletions cmd/functional-test/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package main

import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"

"github.com/logrusorgru/aurora"
"github.com/pkg/errors"

"github.com/projectdiscovery/httpx/internal/testutils"
)

var (
debug = os.Getenv("DEBUG") == "true"
success = aurora.Green("[✓]").String()
failed = aurora.Red("[✘]").String()
errored = false

mainHttpxBinary = flag.String("main", "", "Main Branch Httpx Binary")
devHttpxBinary = flag.String("dev", "", "Dev Branch Httpx Binary")
testcases = flag.String("testcases", "", "Test cases file for Httpx functional tests")
)

func main() {
flag.Parse()

if err := runFunctionalTests(); err != nil {
log.Fatalf("Could not run functional tests: %s\n", err)
}
if errored {
os.Exit(1)
}
}

func runFunctionalTests() error {
file, err := os.Open(*testcases)
if err != nil {
return errors.Wrap(err, "could not open test cases")
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if text == "" {
continue
}
if err := runIndividualTestCase(text); err != nil {
errored = true
fmt.Fprintf(os.Stderr, "%s Test \"%s\" failed: %s\n", failed, text, err)
} else {
fmt.Printf("%s Test \"%s\" passed!\n", success, text)
}
}
return nil
}

func runIndividualTestCase(testcase string) error {
parts := strings.Fields(testcase)

var finalArgs []string
var target string
if len(parts) > 1 {
finalArgs = parts[2:]
target = parts[0]
}
mainOutput, err := testutils.RunHttpxBinaryAndGetResults(target, *mainHttpxBinary, debug, finalArgs)
if err != nil {
return errors.Wrap(err, "could not run httpx main test")
}
devOutput, err := testutils.RunHttpxBinaryAndGetResults(target, *devHttpxBinary, debug, finalArgs)
if err != nil {
return errors.Wrap(err, "could not run httpx dev test")
}
if len(mainOutput) == len(devOutput) {
return nil
}
return fmt.Errorf("%s main is not equal to %s dev", mainOutput, devOutput)
}
23 changes: 23 additions & 0 deletions cmd/functional-test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# reading os type from arguments
CURRENT_OS=$1

if [ "${CURRENT_OS}" == "windows-latest" ];then
extension=.exe
fi

echo "::group::Building functional-test binary"
go build -o functional-test$extension
echo "::endgroup::"

echo "::group::Building httpx binary from current branch"
go build -o httpx_dev$extension ../httpx
echo "::endgroup::"

echo "::group::Building latest release of httpx"
go build -o httpx$extension -v github.com/projectdiscovery/httpx/cmd/httpx
echo "::endgroup::"

echo 'Starting httpx functional test'
./functional-test$extension -main ./httpx$extension -dev ./httpx_dev$extension -testcases testcases.txt
1 change: 1 addition & 0 deletions cmd/functional-test/test-data/raw-request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET /search?q=test HTTP/2
1 change: 1 addition & 0 deletions cmd/functional-test/test-data/request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://scanme.sh
19 changes: 19 additions & 0 deletions cmd/functional-test/testcases.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
scanme.sh {{binary}} -silent
scanme.sh {{binary}} -silent -l test-data/request.txt
scanme.sh {{binary}} -silent -request test-data/raw-request.txt
scanme.sh {{binary}} -silent -title
scanme.sh {{binary}} -silent -sc
scanme.sh {{binary}} -silent -td
scanme.sh {{binary}} -silent -probe
scanme.sh {{binary}} -silent -no-fallback
scanme.sh {{binary}} -silent -cl
scanme.sh {{binary}} -silent -server
scanme.sh {{binary}} -silent -ip
scanme.sh {{binary}} -silent -tls-grab
scanme.sh {{binary}} -silent -unsafe
scanme.sh {{binary}} -silent -x all
scanme.sh {{binary}} -silent -body 'a=b'
scanme.sh {{binary}} -silent -exclude-cdn
scanme.sh {{binary}} -silent -ports https:443
scanme.sh {{binary}} -silent -ztls
https://scanme.sh?a=1*1 {{binary}} -silent
20 changes: 20 additions & 0 deletions cmd/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"os"
"os/signal"
"runtime"
"runtime/pprof"

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/httpx/runner"
Expand All @@ -12,6 +14,24 @@ func main() {
// Parse the command line flags and read config files
options := runner.ParseOptions()

// Profiling related code
if options.Memprofile != "" {
f, err := os.Create(options.Memprofile)
if err != nil {
gologger.Fatal().Msgf("profile: could not create memory profile %q: %v", options.Memprofile, err)
}
old := runtime.MemProfileRate
runtime.MemProfileRate = 4096
gologger.Print().Msgf("profile: memory profiling enabled (rate %d), %s", runtime.MemProfileRate, options.Memprofile)

defer func() {
_ = pprof.Lookup("heap").WriteTo(f, 0)
f.Close()
runtime.MemProfileRate = old
gologger.Print().Msgf("profile: memory profiling disabled, %s", options.Memprofile)
}()
}

httpxRunner, err := runner.New(options)
if err != nil {
gologger.Fatal().Msgf("Could not create runner: %s\n", err)
Expand Down
Loading

0 comments on commit f5cff8c

Please sign in to comment.