From e8c320433bf43a748b4f39362e95a56686ffa043 Mon Sep 17 00:00:00 2001 From: wjlin0 Date: Mon, 13 Mar 2023 02:05:37 +0800 Subject: [PATCH] =?UTF-8?q?v1.0.7=20=E6=96=B0=E5=A2=9E=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 + go.mod | 9 ++ go.sum | 73 ++++++++++++ main.go | 6 +- pkg/projectdiscovery/uncover/uncover/util.go | 4 +- pkg/runner/banner.go | 4 +- pkg/runner/handlerPath.go | 3 +- pkg/runner/http.go | 47 -------- pkg/runner/options.go | 61 +++++----- pkg/runner/output.go | 3 - pkg/runner/resume.go | 15 +-- pkg/runner/run.go | 72 +++++------- pkg/runner/scan.go | 81 ++++++++++++-- pkg/runner/util.go | 110 +++++++++++++++---- pkg/util/dict.go | 48 -------- pkg/util/util.go | 73 ++++++++++-- 16 files changed, 378 insertions(+), 233 deletions(-) delete mode 100644 pkg/runner/http.go delete mode 100644 pkg/util/dict.go diff --git a/README.md b/README.md index c84b401..c87ddfa 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Flags: 速率: -rh, -rate-http int 允许每秒钟最大http请求数 (default 100) +更新: + -update 更新版本 ``` ## 安装 diff --git a/go.mod b/go.mod index 2a4673a..12277b5 100644 --- a/go.mod +++ b/go.mod @@ -20,18 +20,27 @@ require ( github.com/projectdiscovery/utils v0.0.10-0.20230217185600-008d111dd1c1 github.com/remeh/sizedwaitgroup v1.0.0 github.com/stretchr/testify v1.8.1 + github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible golang.org/x/net v0.6.0 ) require ( github.com/Mzack9999/go-http-digest-auth-client v0.6.1-0.20220414142836-eb8883508809 // indirect + github.com/apex/log v1.9.0 // indirect github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect github.com/aymerick/douceur v0.2.0 // indirect + github.com/c4milo/unpackit v0.1.0 // indirect github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dsnet/compress v0.0.1 // indirect github.com/golang/snappy v0.0.4 // indirect + github.com/google/go-github v17.0.0+incompatible // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/gorilla/css v1.0.0 // indirect + github.com/gosuri/uilive v0.0.4 // indirect + github.com/gosuri/uiprogress v0.0.1 // indirect + github.com/klauspost/compress v1.16.0 // indirect + github.com/klauspost/pgzip v1.2.5 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mholt/archiver v3.1.1+incompatible // indirect diff --git a/go.sum b/go.sum index fd7e6d8..e98d77b 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,20 @@ github.com/Mzack9999/go-http-digest-auth-client v0.6.1-0.20220414142836-eb8883508809 h1:ZbFL+BDfBqegi+/Ssh7im5+aQfBRx6it+kHnC7jaDU8= github.com/Mzack9999/go-http-digest-auth-client v0.6.1-0.20220414142836-eb8883508809/go.mod h1:upgc3Zs45jBDnBT4tVRgRcgm26ABpaP7MoTSdgysca4= +github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0= +github.com/apex/log v1.9.0/go.mod h1:m82fZlWIuiWzWP04XCTXmnX0xRkYYbCdYn8jbJeLBEA= +github.com/apex/logs v1.0.0/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDwo= +github.com/aphistic/golf v0.0.0-20180712155816-02c07f170c5a/go.mod h1:3NqKYiepwy8kCu4PNA+aP7WUV72eXWJeP9/r3/K9aLE= +github.com/aphistic/sweet v0.2.0/go.mod h1:fWDlIh/isSE9n6EPsRmC0det+whmX6dJid3stzu0Xys= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= +github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 h1:GKTyiRCL6zVf5wWaqKnf+7Qs6GbEPfd4iMOitWzXJx8= +github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8/go.mod h1:spo1JLcs67NmW1aVLEgtA8Yy1elc+X8y5SRW1sFW4Og= +github.com/c4milo/unpackit v0.1.0 h1:91pWJ6B3svZ4LOE+p3rnyucRK5fZwBdF/yQ/pcZO31I= +github.com/c4milo/unpackit v0.1.0/go.mod h1:pvXCMYlSV8zwGFWMaT+PWYkAB/cvDjN2mv9r7ZRSxEo= github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 h1:ox2F0PSMlrAAiAdknSRMDrAr8mfxPCfSZolH+/qQnyQ= github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08/go.mod h1:pCxVEbcm3AMg7ejXyorUXi6HQCzOIBf7zEDVPtw0/U4= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= @@ -13,26 +24,52 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q= github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo= github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w= github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg= github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= +github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= +github.com/gosuri/uilive v0.0.4 h1:hUEBpQDj8D8jXgtCdBu7sWsy5sbW/5GhuO8KBwJ2jyY= +github.com/gosuri/uilive v0.0.4/go.mod h1:V/epo5LjjlDE5RJUcqx8dbw+zc93y5Ya3yg8tfZ74VI= +github.com/gosuri/uiprogress v0.0.1 h1:0kpv/XY/qTmFWl/SkaJykZXrBBzwwadmW8fRb7RJSxw= +github.com/gosuri/uiprogress v0.0.1/go.mod h1:C1RTYn4Sc7iEyf6j8ft5dyoZ4212h8G1ol9QQluh5+0= github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hooklift/assert v0.1.0 h1:UZzFxx5dSb9aBtvMHTtnPuvFnBvcEhHTPb9+0+jpEjs= +github.com/hooklift/assert v0.1.0/go.mod h1:pfexfvIHnKCdjh6CkkIZv5ic6dQ6aU2jhKghBlXuwwY= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= +github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE= +github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -41,11 +78,16 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= +github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU= github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU= github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= @@ -61,9 +103,12 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc= github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -92,21 +137,37 @@ github.com/projectdiscovery/utils v0.0.10-0.20230217185600-008d111dd1c1 h1:ZxRyl github.com/projectdiscovery/utils v0.0.10-0.20230217185600-008d111dd1c1/go.mod h1:dZqlayNwgCGn2HgYfKrI71RjBEyKsEPovrU+UDfpQWw= github.com/remeh/sizedwaitgroup v1.0.0 h1:VNGGFwNo/R5+MJBf6yrsr110p0m4/OX4S3DCy7Kyl5E= github.com/remeh/sizedwaitgroup v1.0.0/go.mod h1:3j2R4OIe/SeS6YDhICBy22RWjJC5eNCJ1V+9+NVNYlo= +github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA= github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= +github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= +github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0= +github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk= +github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk= +github.com/tj/go-buffer v1.1.0/go.mod h1:iyiJpfFcR2B9sXu7KvjbT9fpM4mOelRSDTbntVj52Uc= +github.com/tj/go-elastic v0.0.0-20171221160941-36157cbbebc2/go.mod h1:WjeM0Oo1eNAjXGDx2yma7uG2XoyRZTq1uv3M/o7imD0= +github.com/tj/go-kinesis v0.0.0-20171128231115-08b17f58cb1b/go.mod h1:/yhzCV0xPfx6jb1bBgRFjl5lytqVqZXEaeqWP8lTEao= +github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= +github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible h1:guTq1YxwB8XSILkI9q4IrOmrCOS6Hc1L3hmOhi4Swcs= +github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible/go.mod h1:waFwwyiAhGey2e+dNoYQ/iLhIcFqhCW7zL/+vDU1WLo= github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= @@ -119,6 +180,7 @@ go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg= @@ -127,6 +189,7 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -137,11 +200,14 @@ golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfS golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -160,6 +226,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -177,11 +244,17 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/djherbis/times.v1 v1.3.0 h1:uxMS4iMtH6Pwsxog094W0FYldiNnfY/xba00vq6C2+o= gopkg.in/djherbis/times.v1 v1.3.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 1dba93f..4a19acd 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/projectdiscovery/gologger" "github.com/wjlin0/pathScan/pkg/runner" + "github.com/wjlin0/pathScan/pkg/util" "os" "os/signal" "path/filepath" @@ -15,13 +16,16 @@ func main() { gologger.Print().Msg(fmt.Sprintf("无法创建Runner: %s", err.Error())) os.Exit(0) } + if run == nil { + os.Exit(0) + } c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func() { for range c { gologger.Info().Msg("CTRL+C 按下: Exiting") - filename := runner.RandStr(30) + ".cfg" + filename := util.RandStr(30) + ".cfg" fmt.Println(filepath.Join(runner.DefaultResumeFolderPath(), filename)) err := run.Cfg.MarshalResume(filename) if err != nil { diff --git a/pkg/projectdiscovery/uncover/uncover/util.go b/pkg/projectdiscovery/uncover/uncover/util.go index d5cfad5..94cf6ab 100644 --- a/pkg/projectdiscovery/uncover/uncover/util.go +++ b/pkg/projectdiscovery/uncover/uncover/util.go @@ -1,8 +1,8 @@ package uncover import ( - "io" "github.com/projectdiscovery/retryablehttp-go" + "io" ) func NewHTTPRequest(method, url string, body io.Reader) (*retryablehttp.Request, error) { @@ -10,6 +10,6 @@ func NewHTTPRequest(method, url string, body io.Reader) (*retryablehttp.Request, if err != nil { return nil, err } - request.Header.Set("User-Agent", "Uncover - FOSS Project (github.com/projectdiscovery/uncover)") + request.Header.Set("User-Agent", "PathScan - FOSS Project (github.com/wjlin0/pathScan)") return request, nil } diff --git a/pkg/runner/banner.go b/pkg/runner/banner.go index b860281..417f2f8 100644 --- a/pkg/runner/banner.go +++ b/pkg/runner/banner.go @@ -6,11 +6,11 @@ const banner = ` __ __ ____ ___ ___ _ / /_ / / / __/____ ___ _ ___ / _ \/ _ // __// _ \ _\ \ / __// _ // _ \ - / .__/\_,_/ \__//_//_//___/ \__/ \_,_//_//_/ v1.0.6 + / .__/\_,_/ \__//_//_//___/ \__/ \_,_//_//_/ v1.0.7 /_/ ` -const Version = `1.0.6` +const Version = `1.0.7` // showBanner is used to show the banner to the user func showBanner() { diff --git a/pkg/runner/handlerPath.go b/pkg/runner/handlerPath.go index dc31def..88d7578 100644 --- a/pkg/runner/handlerPath.go +++ b/pkg/runner/handlerPath.go @@ -3,6 +3,7 @@ package runner import ( "github.com/projectdiscovery/fileutil" "github.com/projectdiscovery/gologger" + "github.com/wjlin0/pathScan/pkg/util" "io" "net/http" "strings" @@ -71,7 +72,7 @@ func (r *Runner) getAllPaths() map[string]struct{} { func (r *Runner) getFilePath(filename string) []string { - path := DataRoot("dict", "v"+Version, filename) + path := util.DataRoot("dict", "v"+Version, filename) out, err := fileutil.ReadFile(path) if err != nil { return nil diff --git a/pkg/runner/http.go b/pkg/runner/http.go deleted file mode 100644 index 8ee19d0..0000000 --- a/pkg/runner/http.go +++ /dev/null @@ -1,47 +0,0 @@ -package runner - -import ( - "github.com/wjlin0/pathScan/pkg/result" - "io" - "net/http" - "net/url" - "regexp" -) - -func (r *Runner) GoTargetPath(target, path string) (*result.TargetResult, error) { - reg := regexp.MustCompile(`(.*?)`) - _url, err := url.JoinPath(target, path) - if err != nil { - return nil, err - } - req, err := http.NewRequest("GET", _url, nil) - if err != nil { - return nil, err - } - req.Header.Set("User-Agent", r.GetUserAgent()) - resp, err := r.client.Do(req) - if err != nil { - return nil, err - } - server := resp.Header.Get("Server") - - defer resp.Body.Close() - body, _ := io.ReadAll(resp.Body) - t := reg.FindAllStringSubmatch(string(body), -1) - title := "" - if len(t) == 0 { - } else if len(t[0]) <= 1 { - } else if len(t[0]) == 2 { - title = t[0][1] - } - - re := &result.TargetResult{ - Target: target, - Path: path, - Title: title, - Status: resp.StatusCode, - BodyLen: len(string(body)), - Server: server, - } - return re, nil -} diff --git a/pkg/runner/options.go b/pkg/runner/options.go index dc85b6c..06463fb 100644 --- a/pkg/runner/options.go +++ b/pkg/runner/options.go @@ -23,31 +23,32 @@ type Options struct { Path goflags.StringSlice `json:"path"` PathFile goflags.StringSlice `json:"path_file"` - PathRemote string `json:"path_remote"` - ResumeCfg string `json:"resume_cfg"` - Output string `json:"output"` - RateHttp int `json:"rate_http"` - Retries int `json:"retries"` - Proxy string `json:"proxy"` - ProxyAuth string `json:"proxy_auth"` - NoColor bool `json:"no_color"` - Verbose bool `json:"verbose"` - Silent bool `json:"silent"` - OnlyTargets bool `json:"only_targets"` - EnableProgressBar bool `json:"enable_progress_bar"` - SkipCode bool `json:"skip_code"` - SkipHost bool `json:"skip_host"` - ErrUseLastResponse bool `json:"err_use_last_response"` - Csv bool `json:"csv,omitempty"` - ClearResume bool `json:"clear_resume"` - Version bool `json:"version"` - Uncover bool `json:"uncover"` - UncoverQuery goflags.StringSlice `json:"uncover_query"` - UncoverEngine goflags.StringSlice `json:"uncover_engine"` - UncoverDelay int `json:"uncover_delay"` - UncoverLimit int `json:"uncover_limit"` - UncoverField string `json:"uncover_field"` - UncoverOutput string `json:"uncover_output"` + PathRemote string `json:"path_remote"` + ResumeCfg string `json:"resume_cfg"` + Output string `json:"output"` + RateHttp int `json:"rate_http"` + Retries int `json:"retries"` + Proxy string `json:"proxy"` + ProxyAuth string `json:"proxy_auth"` + NoColor bool `json:"no_color"` + Verbose bool `json:"verbose"` + Silent bool `json:"silent"` + OnlyTargets bool `json:"only_targets"` + EnableProgressBar bool `json:"enable_progress_bar"` + SkipCode bool `json:"skip_code"` + SkipHost bool `json:"skip_host"` + ErrUseLastResponse bool `json:"err_use_last_response"` + Csv bool `json:"csv,omitempty"` + ClearResume bool `json:"clear_resume"` + Version bool `json:"version"` + Uncover bool `json:"uncover"` + UncoverQuery goflags.StringSlice `json:"uncover_query"` + UncoverEngine goflags.StringSlice `json:"uncover_engine"` + UncoverDelay int `json:"uncover_delay"` + UncoverLimit int `json:"uncover_limit"` + UncoverField string `json:"uncover_field"` + UncoverOutput string `json:"uncover_output"` + UpdatePathScanVersion bool `json:"update"` } var defaultProviderConfigLocation = filepath.Join(folderutil.HomeDirOrDefault("."), ".config/pathScan/provider-config.yaml") @@ -55,7 +56,7 @@ var defaultProviderConfigLocation = filepath.Join(folderutil.HomeDirOrDefault(". func ParserOptions() *Options { options := &Options{} set := goflags.NewFlagSet() - set.SetDescription("PathScan Go 扫描工具") + set.SetDescription("PathScan Go 扫描、信息收集工具") set.CreateGroup("Input", "输入", set.StringSliceVarP(&options.Url, "target", "t", nil, "目标(以逗号分割)", goflags.NormalizedStringSliceOptions), set.StringSliceVarP(&options.UrlFile, "target-file", "tf", nil, "从文件中,读取目标", goflags.FileStringSliceOptions), @@ -102,6 +103,9 @@ func ParserOptions() *Options { set.CreateGroup("rate", "速率", set.IntVarP(&options.RateHttp, "rate-http", "rh", 100, "允许每秒钟最大http请求数"), ) + set.CreateGroup("update", "更新", + set.BoolVar(&options.UpdatePathScanVersion, "update", false, "更新版本"), + ) //set.CreateGroup("") _ = set.Parse() if !options.Silent { @@ -118,11 +122,6 @@ func ParserOptions() *Options { } } - if options.ClearResume { - _ = os.RemoveAll(DefaultResumeFolderPath()) - gologger.Print().Msgf("clear success: %s", DefaultResumeFolderPath()) - os.Exit(0) - } return options } diff --git a/pkg/runner/output.go b/pkg/runner/output.go index e1fdf9d..4150e89 100644 --- a/pkg/runner/output.go +++ b/pkg/runner/output.go @@ -25,9 +25,6 @@ func CSVHeaders(data *result.TargetResult) ([]string, error) { return headers, nil } -func writeCSVRow(data *result.TargetResult, writer *csv.Writer) { - -} func CSVFields(d *result.TargetResult) ([]string, error) { var fields []string vl := reflect.ValueOf(*d) diff --git a/pkg/runner/resume.go b/pkg/runner/resume.go index b7293d0..750e9e2 100644 --- a/pkg/runner/resume.go +++ b/pkg/runner/resume.go @@ -8,12 +8,11 @@ import ( "github.com/projectdiscovery/fileutil" "github.com/projectdiscovery/gologger" "github.com/wjlin0/pathScan/pkg/result" - "math/rand" + "github.com/wjlin0/pathScan/pkg/util" "os" "path/filepath" "strings" "sync" - "time" ) const defaultResumeFileName = `resume.cfg` @@ -58,16 +57,6 @@ func (cfg *ResumeCfg) MarshalResume(filename string) error { } return os.WriteFile(DefaultResumeFilePath(filename), data, 0644) } -func RandStr(length int) string { - str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - bytes := []byte(str) - result := []byte{} - rand.Seed(time.Now().UnixNano() + int64(rand.Intn(100))) - for i := 0; i < length; i++ { - result = append(result, bytes[rand.Intn(len(bytes))]) - } - return string(result) -} func DefaultResumeFolderPath() string { home, err := os.UserHomeDir() @@ -87,7 +76,7 @@ func (cfg *ResumeCfg) CleanupResumeConfig() { } func (cfg *ResumeCfg) ClearResume() { - resumePath := DataRoot("resume") + resumePath := util.DataRoot("resume") dir, err := os.ReadDir(resumePath) if err != nil { return diff --git a/pkg/runner/run.go b/pkg/runner/run.go index 11f1715..5a74c17 100644 --- a/pkg/runner/run.go +++ b/pkg/runner/run.go @@ -1,7 +1,6 @@ package runner import ( - "crypto/tls" "fmt" "github.com/projectdiscovery/clistats" "github.com/projectdiscovery/fileutil" @@ -10,10 +9,10 @@ import ( "github.com/remeh/sizedwaitgroup" ucRunner "github.com/wjlin0/pathScan/pkg/projectdiscovery/uncover/runner" "github.com/wjlin0/pathScan/pkg/result" + "github.com/wjlin0/pathScan/pkg/util" "golang.org/x/net/context" "math/rand" "net/http" - "net/url" "os" "path/filepath" "strings" @@ -34,6 +33,7 @@ type Runner struct { func NewRun(options *Options) (*Runner, error) { run := &Runner{} + var err error if options.ResumeCfg != "" { cfg, err := ParserResumeCfg(options.ResumeCfg) if err != nil { @@ -57,14 +57,35 @@ func NewRun(options *Options) (*Runner, error) { Results: result.NewResult(), } } + if !run.Cfg.Options.UpdatePathScanVersion && !run.Cfg.Options.Silent { + err := CheckVersion() + if err != nil { + gologger.Error().Msgf(err.Error()) + } + } - err := run.Cfg.Options.Validate() + err = run.Cfg.Options.DownloadDict() + if err != nil { + gologger.Error().Msgf(err.Error()) + } + if run.Cfg.Options.UpdatePathScanVersion { + ok, err := run.Cfg.Options.UpdateVersion() + if err != nil && ok == false { + gologger.Error().Msg(err.Error()) + } + return nil, nil + } + if run.Cfg.Options.ClearResume { + _ = os.RemoveAll(DefaultResumeFolderPath()) + gologger.Print().Msgf("clear success: %s", DefaultResumeFolderPath()) + os.Exit(0) + } + err = run.Cfg.Options.Validate() if err != nil { return nil, err } run.Cfg.Options.configureOutput() - run.newClient() - + run.client = newClient(run.Cfg.Options, run.Cfg.Options.ErrUseLastResponse) run.limiter = ratelimit.New(context.Background(), uint(run.Cfg.Options.RateHttp), time.Duration(1)*time.Second) run.wg = sizedwaitgroup.New(run.Cfg.Options.RateHttp) run.targets = run.getAllTargets() @@ -86,49 +107,12 @@ func (r *Runner) GetUserAgent() string { return r.userAgent[rand.Intn(len(r.userAgent))] } -func (r *Runner) newClient() *http.Client { - options := r.Cfg.Options - t := &http.Transport{ - MaxIdleConnsPerHost: -1, - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - MinVersion: tls.VersionTLS10, - }, - DisableKeepAlives: true, - } - if options.Proxy != "" { - proxyUrl, err := url.Parse(options.Proxy) - if err != nil { - gologger.Error().Msg(err.Error()) - } - if options.ProxyAuth != "" { - proxyUrl.User = url.UserPassword(strings.Split(options.ProxyAuth, ":")[0], strings.Split(options.ProxyAuth, ":")[1]) - } - t.Proxy = http.ProxyURL(proxyUrl) - } - client := &http.Client{ - Timeout: 5 * time.Second, - Transport: t, - } - if options.ErrUseLastResponse { - client.CheckRedirect = func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - } - } - r.client = client - return client -} - func (r *Runner) Run() error { targets := r.targets pathUrls := r.paths Retries := r.Cfg.Options.Retries - // 下载远程字典 - err := r.DownloadDict() - if err != nil { - gologger.Error().Msgf(err.Error()) - } + var err error if len(pathUrls) == 1 { r.Cfg.Options.OnlyTargets = true @@ -165,7 +149,7 @@ func (r *Runner) Run() error { return mkdirErr } } - f, err = AppendCreate(r.Cfg.Options.Output) + f, err = util.AppendCreate(r.Cfg.Options.Output) if err != nil { return err } diff --git a/pkg/runner/scan.go b/pkg/runner/scan.go index acfca0e..a79edd4 100644 --- a/pkg/runner/scan.go +++ b/pkg/runner/scan.go @@ -1,21 +1,86 @@ package runner import ( + "crypto/tls" "github.com/projectdiscovery/gologger" + "github.com/wjlin0/pathScan/pkg/result" "io" + "net/http" + "net/url" + "regexp" + "strings" + "time" ) -func (r *Runner) checkAlive(target string) bool { - r.limiter.Take() - resp, err := r.client.Get(target) +func (r *Runner) GoTargetPath(target, path string) (*result.TargetResult, error) { + reg := regexp.MustCompile(`(.*?)`) + _url, err := url.JoinPath(target, path) if err != nil { - gologger.Debug().Msgf("%s 请求 失败", target) - return false + return nil, err } + req, err := http.NewRequest("GET", _url, nil) + if err != nil { + return nil, err + } + req.Header.Set("User-Agent", r.GetUserAgent()) + resp, err := r.client.Do(req) + if err != nil { + return nil, err + } + server := resp.Header.Get("Server") + defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) - if string(body) == "" { - return false + t := reg.FindAllStringSubmatch(string(body), -1) + title := "" + if len(t) == 0 { + } else if len(t[0]) <= 1 { + } else if len(t[0]) == 2 { + title = t[0][1] + } + + re := &result.TargetResult{ + Target: target, + Path: path, + Title: title, + Status: resp.StatusCode, + BodyLen: len(string(body)), + Server: server, + } + return re, nil +} + +func newClient(options *Options, ErrUseLastResponse bool) *http.Client { + client := &http.Client{ + Timeout: 5 * time.Second, + Transport: newTransport(options), + } + if ErrUseLastResponse { + client.CheckRedirect = func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + } + } + return client +} + +func newTransport(options *Options) *http.Transport { + t := &http.Transport{ + MaxIdleConnsPerHost: -1, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + MinVersion: tls.VersionTLS10, + }, + DisableKeepAlives: true, + } + if options.Proxy != "" { + proxyUrl, err := url.Parse(options.Proxy) + if err != nil { + gologger.Error().Msg(err.Error()) + } + if options.ProxyAuth != "" { + proxyUrl.User = url.UserPassword(strings.Split(options.ProxyAuth, ":")[0], strings.Split(options.ProxyAuth, ":")[1]) + } + t.Proxy = http.ProxyURL(proxyUrl) } - return true + return t } diff --git a/pkg/runner/util.go b/pkg/runner/util.go index ed7cb9d..9fe2d5e 100644 --- a/pkg/runner/util.go +++ b/pkg/runner/util.go @@ -3,17 +3,22 @@ package runner import ( "bytes" "fmt" + "github.com/pkg/errors" "github.com/projectdiscovery/fileutil" "github.com/projectdiscovery/gologger" + "github.com/tj/go-update" + "github.com/tj/go-update/progress" + githubUpdateStore "github.com/tj/go-update/stores/github" "github.com/wjlin0/pathScan/pkg/util" "io" - "net/http" "os" "path/filepath" + "runtime" + "strings" "time" ) -func (r *Runner) DownloadDict() error { +func (o *Options) DownloadDict() error { home, err := os.UserHomeDir() if err != nil { @@ -30,24 +35,18 @@ func (r *Runner) DownloadDict() error { return fmt.Errorf("打开 %s 出错:%s\n", path, err.Error()) } - url := "https://github.com/wjlin0/pathScan/releases/download/v" + Version + "/dict.zip" - request, err := http.NewRequest("GET", url, nil) - r.client.CheckRedirect = nil - resp, err := r.client.Do(request) - if !r.Cfg.Options.ErrUseLastResponse { - r.client.CheckRedirect = func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - } - } + dictUrl := "https://github.com/wjlin0/pathScan/releases/download/v" + Version + "/dict.zip" + + client := newClient(o, false) + resp, err := client.Get(dictUrl) if err != nil { - return fmt.Errorf("下载文件出错: %s\n", err.Error()) + return err } - body, err := io.ReadAll(resp.Body) if err != nil { - return fmt.Errorf("下载 %s 文件出错: %s\n", url, err.Error()) + return fmt.Errorf("下载 %s 文件出错: %s\n", dictUrl, err.Error()) } defer resp.Body.Close() reader := bytes.NewReader(body) @@ -60,15 +59,80 @@ func (r *Runner) DownloadDict() error { return nil } -func DataRoot(elem ...string) string { - home, _ := os.UserHomeDir() - var e []string - home = filepath.Join(home, ".config", "pathScan") - e = append(e, home) - e = append(e, elem...) - return filepath.Join(e...) +func (o *Options) UpdateVersion() (bool, error) { + var command string + switch runtime.GOOS { + case "windows": + command = "pathScan.exe" + default: + command = "pathScan" + } + m := &update.Manager{ + Command: command, + Store: &githubUpdateStore.Store{ + Owner: "wjlin0", + Repo: "pathScan", + Version: Version, + }, + } + releases, err := m.LatestReleases() + if err != nil { + return false, errors.Wrap(err, "could not fetch latest release") + } + if len(releases) == 0 { + gologger.Info().Msgf("No new updates found for nuclei engine!") + return true, nil + } + latest := releases[0] + var currentOS string + currentOS = strings.ToUpper(runtime.GOOS[:1]) + runtime.GOOS[1:] + var currentArch string + switch runtime.GOARCH { + case "amd64": + currentArch = "x86_64" + default: + currentArch = runtime.GOARCH + } + final := latest.FindZip(currentOS, currentArch) + if final == nil { + return false, fmt.Errorf("no compatible binary found for %s/%s", currentOS, runtime.GOARCH) + } + tarball, err := final.DownloadProxy(progress.Reader) + if err != nil { + return false, errors.Wrap(err, "could not download latest release") + } + if err := m.Install(tarball); err != nil { + return false, errors.Wrap(err, "could not install latest release") + } + gologger.Info().Msgf("Successfully updated to Nuclei %s\n", latest.Version) + return true, nil } -func AppendCreate(name string) (*os.File, error) { - return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) +func CheckVersion() error { + var command string + switch runtime.GOOS { + case "windows": + command = "pathScan.exe" + default: + command = "pathScan" + } + m := &update.Manager{ + Command: command, + Store: &githubUpdateStore.Store{ + Owner: "wjlin0", + Repo: "pathScan", + Version: Version, + }, + } + releases, err := m.LatestReleases() + if err != nil { + return err + } + if len(releases) != 0 { + gologger.Error().Label("OUT").Msgf("你的版本( v%s )较低. 最新为 %s", Version, releases[0].Version) + } else { + gologger.Info().Msgf("使用 pathScan v%s", Version) + } + return nil + } diff --git a/pkg/util/dict.go b/pkg/util/dict.go deleted file mode 100644 index 0d4ee11..0000000 --- a/pkg/util/dict.go +++ /dev/null @@ -1,48 +0,0 @@ -package util - -import ( - "archive/zip" - "bytes" - "fmt" - "github.com/projectdiscovery/fileutil" - "github.com/projectdiscovery/gologger" - "io" - "os" - "path/filepath" -) - -// Unzip 覆盖解压 -func Unzip(p string, reader *bytes.Reader) error { - - zipReader, err := zip.NewReader(reader, reader.Size()) - if err != nil { - return fmt.Errorf("failed to uncompress zip file: %w", err) - } - for _, f := range zipReader.File { - filePath := filepath.Join(p, filepath.Base(f.Name)) - if f.FileInfo().IsDir() { - err := fileutil.CreateFolders(filePath) - if err != nil { - return fmt.Errorf("无法打开压缩包: %w\n", err) - } - continue - } - file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) - if err != nil { - gologger.Error().Msgf(fmt.Errorf("打开文件是出错: %w\n", err).Error()) - continue - } - fileZip, err := f.Open() - if err != nil { - gologger.Error().Msgf(fmt.Errorf("读取压缩包出错: %w\n", err).Error()) - continue - } - _, err = io.Copy(file, fileZip) - if err != nil { - gologger.Error().Msgf(fmt.Errorf("写入时文件是出错: %w\n", err).Error()) - continue - } - } - return nil - -} diff --git a/pkg/util/util.go b/pkg/util/util.go index 3e51668..cdadd24 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -1,20 +1,73 @@ package util import ( - "errors" + "archive/zip" + "bytes" "fmt" - "net/http" + "github.com/projectdiscovery/gologger" + fileutil "github.com/projectdiscovery/utils/file" + "io" + "math/rand" + "os" + "path/filepath" + "time" ) -func ReconDial(client *http.Client, req *http.Request, i int, max int) (*http.Response, error) { - get, err := client.Do(req) +// Unzip 覆盖解压 +func Unzip(p string, reader *bytes.Reader) error { + + zipReader, err := zip.NewReader(reader, reader.Size()) if err != nil { - if i < max { - i++ - get, err = ReconDial(client, req, i, max) - } else { - err = errors.New(fmt.Sprintf("链接失败超过%v次-> `%v` ", max, req.URL.String())) + return fmt.Errorf("failed to uncompress zip file: %w", err) + } + for _, f := range zipReader.File { + filePath := filepath.Join(p, filepath.Base(f.Name)) + if f.FileInfo().IsDir() { + err := fileutil.CreateFolders(filePath) + if err != nil { + return fmt.Errorf("无法打开压缩包: %w\n", err) + } + continue + } + file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) + if err != nil { + gologger.Error().Msgf(fmt.Errorf("打开文件是出错: %w\n", err).Error()) + continue } + fileZip, err := f.Open() + if err != nil { + gologger.Error().Msgf(fmt.Errorf("读取压缩包出错: %w\n", err).Error()) + continue + } + _, err = io.Copy(file, fileZip) + if err != nil { + gologger.Error().Msgf(fmt.Errorf("写入时文件是出错: %w\n", err).Error()) + continue + } + } + return nil + +} + +func RandStr(length int) string { + str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + strByte := []byte(str) + result := []byte{} + rand.Seed(time.Now().UnixNano() + int64(rand.Intn(100))) + for i := 0; i < length; i++ { + result = append(result, strByte[rand.Intn(len(strByte))]) } - return get, err + return string(result) +} +func DataRoot(elem ...string) string { + home, _ := os.UserHomeDir() + var e []string + home = filepath.Join(home, ".config", "pathScan") + e = append(e, home) + e = append(e, elem...) + return filepath.Join(e...) +} + +func AppendCreate(name string) (*os.File, error) { + return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) }