Skip to content

Commit

Permalink
Merge pull request #31 from surface-security/upstream-to-pr/rev-344c54a
Browse files Browse the repository at this point in the history
Upstream revision 344c54a
  • Loading branch information
fopina authored Apr 12, 2023
2 parents 8908643 + d09ec97 commit cf9f707
Show file tree
Hide file tree
Showing 20 changed files with 368 additions and 565 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: 🔨 Build Test

on:
pull_request:
paths:
- '**.go'
- '**.mod'
workflow_dispatch:

jobs:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ name: 🚨 CodeQL Analysis
on:
workflow_dispatch:
pull_request:
paths:
- '**.go'
branches:
- dev

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: ubuntu-latest-16-cores
permissions:
actions: read
contents: read
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/dockerhub-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ on:

jobs:
docker:
runs-on: ubuntu-latest
runs-on: ubuntu-latest-16-cores
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get Github tag
id: meta
run: |
echo "::set-output name=tag::$(curl --silent "https://api.github.com/repos/projectdiscovery/httpx/releases/latest" | jq -r .tag_name)"
curl --silent "https://api.github.com/repos/projectdiscovery/httpx/releases/latest" | jq -r .tag_name | xargs -I {} echo TAG={} >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand All @@ -32,9 +32,9 @@ jobs:
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm
push: true
tags: projectdiscovery/httpx:latest,projectdiscovery/httpx:${{ steps.meta.outputs.tag }}
tags: projectdiscovery/httpx:latest,projectdiscovery/httpx:${{ steps.meta.outputs.TAG }}
3 changes: 3 additions & 0 deletions .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: 🧪 Functional Test

on:
pull_request:
paths:
- '**.go'
- '**.mod'
workflow_dispatch:

jobs:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: 🙏🏻 Lint Test

on:
pull_request:
paths:
- '**.go'
- '**.mod'
workflow_dispatch:

jobs:
Expand All @@ -16,7 +19,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.3.1
uses: golangci/golangci-lint-action@v3.4.0
with:
version: latest
args: --timeout 5m
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/sonarcloud.yml

This file was deleted.

16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM golang:1.19.4-alpine AS builder
ARG BUILD_SOURCE_TAG=latest
# Base
FROM golang:1.20.2-alpine AS builder

RUN apk add --no-cache git build-base gcc musl-dev
RUN go install -v github.com/projectdiscovery/httpx/cmd/httpx@${BUILD_SOURCE_TAG}
WORKDIR /app
COPY . /app
RUN go mod download
RUN go build ./cmd/httpx

FROM alpine:3.17.0
FROM alpine:3.17.2
RUN apk -U upgrade --no-cache \
&& apk add --no-cache bind-tools ca-certificates
COPY --from=builder /go/bin/httpx /usr/local/bin/
COPY --from=builder /app/httpx /usr/local/bin/

ENTRYPOINT ["httpx"]
ENTRYPOINT ["httpx"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ MATCHERS:
-mlc, -match-line-count string match response body with specified line count (-mlc 423,532)
-mwc, -match-word-count string match response body with specified word count (-mwc 43,55)
-mfc, -match-favicon string[] match response with specified favicon hash (-mfc 1494302000)
-ms, -match-string string match response with specified string (-ms admin)
-ms, -match-string string match response with specified string (case insensitive) (-ms admin)
-mr, -match-regex string match response with specified regex (-mr admin)
-mcdn, -match-cdn string[] match host with specified cdn provider (oracle, google, azure, cloudflare, cloudfront, fastly, incapsula, leaseweb, akamai, sucuri)
-mrt, -match-response-time string match response with specified response time in seconds (-mrt '< 1')
Expand Down
3 changes: 2 additions & 1 deletion cmd/functional-test/testcases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ 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
https://scanme.sh?a=1*1 {{binary}} -silent
https://scanme.sh:443 {{binary}} -asn
7 changes: 7 additions & 0 deletions cmd/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/httpx/runner"
errorutil "github.com/projectdiscovery/utils/errors"
)

func main() {
Expand Down Expand Up @@ -58,3 +59,9 @@ func main() {
httpxRunner.RunEnumeration()
httpxRunner.Close()
}

func init() {
if os.Getenv("DEBUG") != "" {
errorutil.ShowStackTrace = true
}
}
3 changes: 2 additions & 1 deletion cmd/integration-test/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (h *httpxLibrary) Execute() error {

httpxRunner.RunEnumeration()

expected := "https://scanme.sh:443"
// httpx removes default ports for simplicity Ref: https://pkg.go.dev/github.com/projectdiscovery/httpx/common/stringz#RemoveURLDefaultPort
expected := "https://scanme.sh"

if got != expected {
return errIncorrectResult(expected, got)
Expand Down
9 changes: 7 additions & 2 deletions common/httpx/httpx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
retryablehttp "github.com/projectdiscovery/retryablehttp-go"
pdhttputil "github.com/projectdiscovery/utils/http"
stringsutil "github.com/projectdiscovery/utils/strings"
urlutil "github.com/projectdiscovery/utils/url"
"golang.org/x/net/context"
"golang.org/x/net/http2"
)
Expand Down Expand Up @@ -331,11 +332,15 @@ func (h *HTTPX) NewRequest(method, targetURL string) (req *retryablehttp.Request

// NewRequest from url
func (h *HTTPX) NewRequestWithContext(ctx context.Context, method, targetURL string) (req *retryablehttp.Request, err error) {
req, err = retryablehttp.NewRequestWithContext(ctx, method, targetURL, nil)
urlx, err := urlutil.ParseURL(targetURL, h.Options.Unsafe)
if err != nil {
return
return nil, err
}

req, err = retryablehttp.NewRequestFromURLWithContext(ctx, method, urlx, nil)
if err != nil {
return nil, err
}
// Skip if unsafe is used
if !h.Options.Unsafe {
// set default user agent
Expand Down
7 changes: 3 additions & 4 deletions common/stringz/stringz.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,18 @@ func RemoveURLDefaultPort(rawURL string) string {
return rawURL
}

if u.Scheme == urlutil.HTTP && u.Port == "80" || u.Scheme == urlutil.HTTPS && u.Port == "443" {
u.Port = ""
if u.Scheme == urlutil.HTTP && u.Port() == "80" || u.Scheme == urlutil.HTTPS && u.Port() == "443" {
u.TrimPort()
}
return u.String()
}

func GetInvalidURI(rawURL string) (bool, string) {
if _, err := url.Parse(rawURL); err != nil {
if u, err := urlutil.Parse(rawURL); err == nil {
return true, u.RequestURI
return true, u.GetRelativePath()
}
}

return false, ""
}

Expand Down
Loading

0 comments on commit cf9f707

Please sign in to comment.