2019-08-09 10:13:54 +08:00
|
|
|
package httpx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2019-08-14 18:47:18 +08:00
|
|
|
"github.com/elazarl/goproxy"
|
2019-10-28 22:25:23 +08:00
|
|
|
"strings"
|
|
|
|
"HFish/utils/is"
|
|
|
|
"HFish/core/rpc/client"
|
|
|
|
"HFish/core/report"
|
2019-08-09 10:13:54 +08:00
|
|
|
)
|
|
|
|
|
2019-10-28 22:25:23 +08:00
|
|
|
func Start(address string) {
|
|
|
|
proxy := goproxy.NewProxyHttpServer()
|
2019-08-09 10:13:54 +08:00
|
|
|
|
2019-10-28 22:25:23 +08:00
|
|
|
var info string
|
2019-08-09 10:13:54 +08:00
|
|
|
|
2019-10-28 22:25:23 +08:00
|
|
|
proxy.OnRequest().DoFunc(
|
|
|
|
func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
|
|
|
|
info = "URL:" + r.URL.String() + "&&Method:" + r.Method + "&&RemoteAddr:" + r.RemoteAddr
|
|
|
|
|
|
|
|
arr := strings.Split(r.RemoteAddr, ":")
|
|
|
|
|
|
|
|
// 判断是否为 RPC 客户端
|
|
|
|
if is.Rpc() {
|
|
|
|
go client.ReportResult("HTTP", "HTTP代理蜜罐", arr[0], info, "0")
|
|
|
|
} else {
|
|
|
|
go report.ReportHttp("HTTP代理蜜罐", "本机", arr[0], info)
|
|
|
|
}
|
|
|
|
|
|
|
|
return r, nil
|
2019-08-14 18:47:18 +08:00
|
|
|
})
|
2019-10-28 22:25:23 +08:00
|
|
|
|
|
|
|
//proxy.OnResponse().DoFunc(
|
|
|
|
// func(r *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
|
|
|
|
// input, _ := ioutil.ReadAll(r.Body)
|
|
|
|
// info += "Response Info&&||kon||&&Status:" + r.Status + "&&Body:" + string(input)
|
|
|
|
// return r
|
|
|
|
// })
|
|
|
|
|
|
|
|
http.ListenAndServe(address, proxy)
|
2019-08-16 16:08:00 +08:00
|
|
|
}
|