Skip to content

Commit

Permalink
v1.0.8 新增请求头参数
Browse files Browse the repository at this point in the history
  • Loading branch information
wjlin0 committed Mar 17, 2023
1 parent fb2c38b commit 8762215
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 269 deletions.
6 changes: 3 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ archives:
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
- goos: windows
format: zip
checksum:
algorithm: sha256
snapshot:
Expand All @@ -40,8 +40,8 @@ changelog:
- '^test:'
dockers:
- image_templates:
- "wjlin0/path_scan:latest"
- "wjlin0/path_scan:{{ .Tag }}"
- "wjlin0/path_scan:latest"
dockerfile: Dockerfile
skip_push: false
build_flag_templates:
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

<p align="center">
<img src="https://img.shields.io/github/go-mod/go-version/wjlin0/pathScan?filename=go.mod" alt="">
<a href="https://github.com/wjlin0/pathScan/releases"><img src="https://img.shields.io/github/downloads/wjlin0/pathScan/total" alt=""></a>
<a href="https://github.com/wjlin0/pathScan/graphs/contributors"><img alt="GitHub contributors" src="https://img.shields.io/github/contributors-anon/wjlin0/pathScan"></a>
<a href="https://github.com/wjlin0/pathScan/releases/"><img src="https://img.shields.io/github/release/wjlin0/pathScan" alt=""></a>
<a href="https://github.com/wjlin0/pathScan/issues"><img src="https://img.shields.io/github/issues-raw/wjlin0/pathScan" alt=""></a>
<a href="https://wjlin0.com/"><img src="https://img.shields.io/badge/wjlin0-blog-green" alt=""></a>
<a href="https://github.com/wjlin0/pathScan/releases"><img src="https://img.shields.io/github/downloads/wjlin0/pathScan/total" alt=""></a>
<a href="https://github.com/wjlin0/pathScan/graphs/contributors"><img alt="GitHub contributors" src="https://img.shields.io/github/contributors-anon/wjlin0/pathScan"></a>
<a href="https://github.com/wjlin0/pathScan/releases/"><img src="https://img.shields.io/github/release/wjlin0/pathScan" alt=""></a>
<a href="https://hub.docker.com/repository/docker/wjlin0/path_scan/general" ><img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/wjlin0/path_scan"></a>
<a href="https://wjlin0.com/"><img src="https://img.shields.io/badge/wjlin0-blog-green" alt=""></a>
</p>


# 特征

- 快速发现路径
Expand All @@ -18,7 +17,7 @@
- 可恢复上次扫描进度
- 从网络空间测绘中发现目标
- 支持使用HTTP/SOCKS代理
- 随机UserAgent、证书跳过验证
- 自定义请求头

# 用法

Expand Down Expand Up @@ -48,7 +47,7 @@ Flags:

输出:
-o, -output string 输出文件路径(可忽略)
-c, -csv csv格式输出
-csv csv格式输出
-nc, -no-color 无颜色输出
-vb, -verbose 详细输出模式
-sl, -silent 管道模式
Expand All @@ -72,11 +71,19 @@ Flags:
-ucd, -uncover-delay int 打开查询请求之间的延迟(秒) (default 1)
-uo, -uncover-output string 搜索引擎查询结果保存

请求头参数:
-ua, -user-agent string[] User-Agent
-c, -cookie string cookie
-auth, -authorization string Auth请求头
-header string[] 自定义请求头,以逗号隔开
-hf, -header-file string[] 从文件中加载自定义请求头

速率:
-rh, -rate-http int 允许每秒钟最大http请求数 (default 100)

更新:
-update 更新版本
-update 更新版本
-ud, -update-dict 更新字典版本

```
# 安装pathScan
Expand Down Expand Up @@ -134,6 +141,8 @@ pathScan -uc -ue "fofa" -uq "domain=baidu.com"
pathScan -resume Hc7wUXRoH2G1RjrNgjB2OMzXlXo1Hg.cfg
# 输出
pathScan -t https://www.baidu.com -csv -output 1.csv
# 自定义请求头
pathScan -t http://www.baidu.com -header User-Agent:pathScan/1.8,Cookie:a=1 -header a:1
```


Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const banner = `
__ __ ____
___ ___ _ / /_ / / / __/____ ___ _ ___
/ _ \/ _ // __// _ \ _\ \ / __// _ // _ \
/ .__/\_,_/ \__//_//_//___/ \__/ \_,_//_//_/ v1.0.7
/ .__/\_,_/ \__//_//_//___/ \__/ \_,_//_//_/ v1.0.8
/_/
`

const Version = `1.0.7`
const Version = `1.0.8`

// showBanner is used to show the banner to the user
func showBanner() {
Expand Down
242 changes: 242 additions & 0 deletions pkg/runner/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
package runner

import (
"bufio"
"github.com/projectdiscovery/gologger"
fileutil "github.com/projectdiscovery/utils/file"
"github.com/wjlin0/pathScan/pkg/common/uncover"
"github.com/wjlin0/pathScan/pkg/util"
"io"
"net/http"
"net/url"
"os"
"strings"
)

func (r *Runner) handlerHeader() map[string]interface{} {
headerMap := make(map[string]interface{})
if r.Cfg.Options.UserAgent != nil {
headerMap["User-Agent"] = r.Cfg.Options.UserAgent
}
if r.Cfg.Options.Cookie != "" {
headerMap["Cookie"] = r.Cfg.Options.Cookie
}
if r.Cfg.Options.Authorization != "" {
headerMap["Authorization"] = r.Cfg.Options.Authorization
}
if r.Cfg.Options.Header != nil {
for _, v := range r.Cfg.Options.Header {

split := strings.Split(v, ":")
if len(split) == 2 {
headerMap[split[0]] = split[1]
}
}
}
if r.Cfg.Options.HeaderFile != nil {

for _, v := range r.Cfg.Options.HeaderFile {
split := strings.Split(v, ":")
if len(split) == 2 {
headerMap[split[0]] = split[1]
}
}
}
_, ok := headerMap["User-Agent"]
if !ok {
headerMap["User-Agent"] = []string{"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5", "Mozilla/5.0 (Linux;u;Android 4.2.2;zh-cn;) AppleWebKit/534.46 (KHTML,like Gecko)Version/5.1 Mobile Safari/10600.6.3 (compatible; Baiduspider/2.0;+http://www.baidu.com/search/spider.html)", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)", "Mozilla/5.0 (compatible; Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)", "Mozilla/5.0 (iPhone;CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko)Version/9.0 Mobile/13B143 Safari/601.1 (compatible; Baiduspider-render/2.0;Smartapp; +http://www.baidu.com/search/spider.html)"}
}

return headerMap
}
func (r *Runner) handlerGetTargetPath() map[string]struct{} {
at := make(map[string]struct{})
var resp *http.Response
var err error

if r.Cfg.Options.Path != nil {
for _, p := range r.Cfg.Options.Path {
if _, ok := at[p]; !ok {
p = strings.TrimSpace(p)
at[p] = struct{}{}
}
}
}
if r.Cfg.Options.PathFile != nil {
for _, p := range r.Cfg.Options.PathFile {
if _, ok := at[p]; !ok {
p = strings.TrimSpace(p)
at[p] = struct{}{}
}
}
}
if r.Cfg.Options.PathRemote != "" {
request, _ := http.NewRequest("GET", r.Cfg.Options.PathRemote, nil)
resp, err = r.client.Do(request)
if err == nil {
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {

}
}(resp.Body)
body, _ := io.ReadAll(resp.Body)
for _, p := range strings.Split(string(body), "\n") {
p = strings.Trim(p, "\r")
p = strings.Trim(p, "\n")
if p == "" {
continue
}
if _, ok := at[p]; !ok {
at[p] = struct{}{}
}

}
}
gologger.Debug().Msg("从远程加载字典 完成...")
}

if len(r.targets) == 1 && r.Cfg.Options.Path == nil && r.Cfg.Options.PathFile == nil && r.Cfg.Options.PathRemote == "" {
u := r.handlerGetFilePath("main.txt")
if u != nil {
for _, s := range u {
at[s] = struct{}{}
}
}
}
if len(at) == 0 {
at["/"] = struct{}{}
}
return at
}
func (r *Runner) handlerGetFilePath(filename string) []string {

path := util.DataRoot("dict", "v"+Version, filename)
out, err := fileutil.ReadFile(path)
if err != nil {
return nil
}
var str []string
for o := range out {
str = append(str, o)
}
return str
}
func (r *Runner) handlerGetTargets() map[string]struct{} {
at := make(map[string]struct{})
var resp *http.Response
var err error
if r.Cfg.Options.Url != nil {
for _, u := range r.Cfg.Options.Url {
u = strings.Trim(u, "\r")
u = strings.Trim(u, "\n")
if !strings.HasSuffix(u, "/") {
u, _ = url.JoinPath(u, "/")
}
if !strings.HasPrefix(u, "http") {
u1 := "http://" + u
u2 := "https://" + u
at[u1] = struct{}{}
at[u2] = struct{}{}
} else {
at[u] = struct{}{}
}
}
}
if r.Cfg.Options.UrlFile != nil {
for _, u := range r.Cfg.Options.UrlFile {
u = strings.Trim(u, "\r")
u = strings.Trim(u, "\n")
if !strings.HasSuffix(u, "/") {
u, _ = url.JoinPath(u, "/")
}
if !strings.HasPrefix(u, "http") {
u1 := "http://" + u
u2 := "https://" + u
at[u1] = struct{}{}
at[u2] = struct{}{}
} else {
at[u] = struct{}{}
}
}
}
if r.Cfg.Options.UrlRemote != "" {
resp, err = http.Get(r.Cfg.Options.UrlRemote)
if err == nil {
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
for _, u := range strings.Split(string(body), "\n") {
u = strings.Trim(u, "\r")
u = strings.Trim(u, "\n")
if !strings.HasSuffix(u, "/") {
u, _ = url.JoinPath(u, "/")
}
if !strings.HasPrefix(u, "http") {
u1 := "http://" + u
u2 := "https://" + u
at[u1] = struct{}{}
at[u2] = struct{}{}
} else {
at[u] = struct{}{}
}
}
}
}
if r.Cfg.Options.Silent && fileutil.HasStdin() {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
u := strings.TrimSpace(s.Text())
if u == "" {
continue
}
if !strings.HasSuffix(u, "/") {
u, _ = url.JoinPath(u, "/")
}
if !strings.HasPrefix(u, "http") {
u1 := "http://" + u
u2 := "https://" + u
at[u1] = struct{}{}
at[u2] = struct{}{}
} else {
at[u] = struct{}{}
}
}
os.Stdin.Close()
}
if r.Cfg.Options.Uncover && r.Cfg.Options.UncoverQuery != nil {
if r.Cfg.Options.UncoverEngine == nil {
r.Cfg.Options.UncoverEngine = []string{"quake", "fofa"}
}
gologger.Info().Msgf("正在运行: %s", strings.Join(r.Cfg.Options.UncoverEngine, ","))
ch, err := uncover.GetTargetsFromUncover(r.Cfg.Options.UncoverDelay, r.Cfg.Options.UncoverLimit, r.Cfg.Options.UncoverField, r.Cfg.Options.UncoverOutput, r.Cfg.Options.Csv, r.Cfg.Options.UncoverEngine, r.Cfg.Options.UncoverQuery)
if err != nil {
gologger.Error().Label("WRN").Msg(err.Error())
} else {
for c := range ch {
c = strings.Trim(c, "\r")
c = strings.Trim(c, "\n")
if c == "" {
continue
}
if !strings.HasPrefix(c, "http") {
c1 := "http://" + c
c = "https://" + c
if !strings.HasSuffix(c1, "/") {
c1, _ = url.JoinPath(c1, "/")
}
at[c1] = struct{}{}
}
if !strings.HasSuffix(c, "/") {
c, _ = url.JoinPath(c, "/")
}
at[c] = struct{}{}
}
}

}
for _, skip := range r.Cfg.Options.SkipUrl {
delete(at, skip)
}

return at
}
Loading

0 comments on commit 8762215

Please sign in to comment.