fscan/Plugins/webtitle.go

97 lines
2.4 KiB
Go
Raw Normal View History

2020-12-29 17:17:10 +08:00
package Plugins
import (
"fmt"
"github.com/shadow1ng/fscan/WebScan"
2021-02-21 14:54:40 +08:00
"github.com/shadow1ng/fscan/WebScan/lib"
2020-12-29 17:17:10 +08:00
"github.com/shadow1ng/fscan/common"
"io/ioutil"
"net/http"
"regexp"
"strings"
)
func WebTitle(info *common.HostInfo) error {
2021-02-21 14:54:40 +08:00
var CheckData []WebScan.CheckDatas
2020-12-29 17:17:10 +08:00
if info.Ports == "80" {
info.Url = fmt.Sprintf("http://%s", info.Host)
} else if info.Ports == "443" {
info.Url = fmt.Sprintf("https://%s", info.Host)
} else {
info.Url = fmt.Sprintf("http://%s:%s", info.Host, info.Ports)
}
2021-02-21 14:54:40 +08:00
err, result, CheckData := geturl(info, true, CheckData)
if err != nil {
return err
2020-12-29 17:17:10 +08:00
}
if result == "https" {
2021-02-21 14:54:40 +08:00
err, _, CheckData = geturl(info, true, CheckData)
if err != nil {
return err
2020-12-29 17:17:10 +08:00
}
}
2021-02-21 14:54:40 +08:00
err, _, CheckData = geturl(info, false, CheckData)
if err != nil {
return err
}
WebScan.InfoCheck(info.Url, CheckData)
if common.IsWebCan == false {
2020-12-29 17:17:10 +08:00
WebScan.WebScan(info)
}
return err
2020-12-29 17:17:10 +08:00
}
2021-02-21 14:54:40 +08:00
func geturl(info *common.HostInfo, flag bool, CheckData []WebScan.CheckDatas) (error, string, []WebScan.CheckDatas) {
Url := info.Url
if flag == false {
Url += "/favicon.ico"
}
res, err := http.NewRequest("GET", Url, nil)
2020-12-29 17:17:10 +08:00
if err == nil {
2021-02-21 14:54:40 +08:00
res.Header.Set("User-agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36")
res.Header.Set("Accept", "*/*")
res.Header.Set("Accept-Language", "zh-CN,zh;q=0.9")
res.Header.Set("Accept-Encoding", "gzip, deflate")
if flag == true {
2021-02-21 14:54:40 +08:00
res.Header.Set("Cookie", "rememberMe=1")
}
2021-02-21 14:54:40 +08:00
res.Header.Set("Connection", "close")
resp, err := lib.Client.Do(res)
2020-12-29 17:17:10 +08:00
if err == nil {
defer resp.Body.Close()
var title string
body, _ := ioutil.ReadAll(resp.Body)
re := regexp.MustCompile("<title>(.*)</title>")
find := re.FindAllStringSubmatch(string(body), -1)
if len(find) > 0 {
title = find[0][1]
if len(title) > 100 {
title = title[:100]
}
} else {
title = "None"
}
if flag == true {
2021-02-21 14:54:40 +08:00
result := fmt.Sprintf("WebTitle:%-25v %-3v %v", Url, resp.StatusCode, title)
common.LogSuccess(result)
}
CheckData = append(CheckData, WebScan.CheckDatas{body, fmt.Sprintf("%s", resp.Header)})
2020-12-29 17:17:10 +08:00
if resp.StatusCode == 400 && info.Url[:5] != "https" {
info.Url = strings.Replace(info.Url, "http://", "https://", 1)
2021-02-21 14:54:40 +08:00
return err, "https", CheckData
2020-12-29 17:17:10 +08:00
}
2021-02-21 14:54:40 +08:00
return err, "", CheckData
2020-12-29 17:17:10 +08:00
}
2021-02-21 14:54:40 +08:00
return err, "", CheckData
2020-12-29 17:17:10 +08:00
}
2021-02-21 14:54:40 +08:00
return err, "", CheckData
2020-12-29 17:17:10 +08:00
}