|
| 1 | +package Processor |
| 2 | + |
| 3 | +import ( |
| 4 | + "GScan/infoscan/dao" |
| 5 | + "GScan/pkg" |
| 6 | + "GScan/pkg/logger" |
| 7 | + "bytes" |
| 8 | + "encoding/json" |
| 9 | + "errors" |
| 10 | + "fmt" |
| 11 | + "io" |
| 12 | + "net/http" |
| 13 | + "net/url" |
| 14 | + "regexp" |
| 15 | + "strings" |
| 16 | +) |
| 17 | + |
| 18 | +type WXDomainCheck struct { |
| 19 | + dao.IProcessorDAO |
| 20 | + JobID uint |
| 21 | + Scheduler pkg.QueueScheduler[*dao.Page] |
| 22 | + Client http.Client |
| 23 | +} |
| 24 | + |
| 25 | +func (w *WXDomainCheck) Run() { |
| 26 | + w.Client = http.Client{} |
| 27 | + w.Client.CheckRedirect = func(req *http.Request, via []*http.Request) error { |
| 28 | + return http.ErrUseLastResponse |
| 29 | + } |
| 30 | + w.Scheduler.Init() |
| 31 | + w.Scheduler.Run() |
| 32 | + workerChan := w.Scheduler.WorkerChan() |
| 33 | + for { |
| 34 | + w.Scheduler.WorkerReady(workerChan) |
| 35 | + select { |
| 36 | + case page := <-workerChan: |
| 37 | + res, ok := w.check(page.URL) |
| 38 | + if !ok { |
| 39 | + result := dao.ProcessResult{ |
| 40 | + Type: "微信域名检测", |
| 41 | + JobID: page.JobID, |
| 42 | + PageID: page.ID, |
| 43 | + Data: res, |
| 44 | + } |
| 45 | + w.AddResult(&result) |
| 46 | + logger.PF(logger.LINFO, "<DataProcessor>[%s]%s :%s", result.Type, page.URL, result.Data) |
| 47 | + } |
| 48 | + dao.PagePool.Put(page) |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +func (w *WXDomainCheck) Handler(page *dao.Page, data []byte) (*dao.ProcessResult, error) { |
| 54 | + if !page.External { |
| 55 | + return nil, errors.New("no data") |
| 56 | + } |
| 57 | + if strings.Contains(page.Error, "not text") { |
| 58 | + return nil, errors.New("no data") |
| 59 | + } |
| 60 | + npage := dao.PagePool.Get().(*dao.Page) |
| 61 | + marshal, _ := json.Marshal(page) |
| 62 | + if err := json.Unmarshal(marshal, npage); err != nil { |
| 63 | + return nil, err |
| 64 | + } |
| 65 | + w.Scheduler.Submit(npage) |
| 66 | + |
| 67 | + return nil, errors.New("no data") |
| 68 | +} |
| 69 | + |
| 70 | +type WXRESP struct { |
| 71 | + Type string `json:"type"` |
| 72 | + Title string `json:"title"` |
| 73 | + Desc string `json:"desc"` |
| 74 | +} |
| 75 | + |
| 76 | +var re = regexp.MustCompile(`(?m)cgiData = (.*?); |
| 77 | + </script>`) |
| 78 | + |
| 79 | +func (w *WXDomainCheck) check(url0 string) (string, bool) { |
| 80 | + wxurl := fmt.Sprintf("https://mp.weixinbridge.com/mp/wapredirect?url=%s", url.QueryEscape(url0)) |
| 81 | + request, _ := http.NewRequest("GET", wxurl, nil) |
| 82 | + resp, err := w.Client.Do(request) |
| 83 | + if err != nil { |
| 84 | + return err.Error(), true |
| 85 | + } |
| 86 | + if resp.StatusCode != 302 { |
| 87 | + return "StatusCode!=302 可能被风控", true |
| 88 | + } |
| 89 | + if Location, ok := resp.Header["Location"]; ok { |
| 90 | + if !strings.Contains(Location[0], "weixin110.qq.com") { |
| 91 | + return "正常", true |
| 92 | + } |
| 93 | + wxresp, err := http.Get(Location[0]) |
| 94 | + if err != nil { |
| 95 | + return err.Error(), true |
| 96 | + } |
| 97 | + all, err := io.ReadAll(wxresp.Body) |
| 98 | + if err != nil { |
| 99 | + return err.Error(), true |
| 100 | + } |
| 101 | + re.FindAllSubmatch(all, -1) |
| 102 | + submatch := re.FindAllSubmatch(all, -1) |
| 103 | + if len(submatch) == 0 { |
| 104 | + return "检测失败", true |
| 105 | + } |
| 106 | + |
| 107 | + if bytes.Contains(submatch[0][1], []byte("该地址为IP地址")) { |
| 108 | + return "IP地址", true |
| 109 | + } |
| 110 | + jsdata := WXRESP{} |
| 111 | + err = json.Unmarshal(submatch[0][1], &jsdata) |
| 112 | + if err != nil { |
| 113 | + return err.Error(), true |
| 114 | + } |
| 115 | + if jsdata.Type == "empty" { |
| 116 | + return jsdata.Title, false |
| 117 | + } else { |
| 118 | + return jsdata.Desc, false |
| 119 | + } |
| 120 | + } |
| 121 | + return "检测失败 未找到Loc", true |
| 122 | +} |
0 commit comments