1. 程式人生 > >[Go]基於GoProxy實現HTTP代理,攔截智慧樹注入JS實現自動刷課

[Go]基於GoProxy實現HTTP代理,攔截智慧樹注入JS實現自動刷課

這幾天各種網課都快截至了,鄙人也是被逼得煩的不行

雖然網上有刷課的瀏覽器,但是每次換個地方就得重新拷貝一邊

所以就想能不能寫一個HTTP代理,丟在伺服器上,自己不管到哪裡,設定上代理就能刷課

從本質來說其實都是注入JS,跟瀏覽器相比換個注入方式而已

既然要寫HTTP代理,第一時間就想到了大名鼎鼎的GoProxy

首先執行go get來下載庫

go get github.com/snail007/goproxy

  接下來,不多說直接上程式碼

package main
import (
    "strings"
    "fmt"
    "bytes"
    "
net/http" "io/ioutil" "github.com/elazarl/goproxy" ) var Code string = `<script>function query() { if ($("#popbox_title").length > 0) { $(".popboxes_close")[0].click(); console.log('關閉視窗'); } if ($("#chapterList .time_ico.fl").nextAll()[2].children[0].style.width === "
100%" || $("video").get(0).ended) { var num = -1; var text = $("#chapterList .time_ico.fl").parent().nextAll()[++num].id; while (text === "" || text.substr(0, 5) != "video" || text.substr(0, 7) === "video-0") { text = $("#chapterList .time_ico.fl
").parent().nextAll()[++num].id; } $("#chapterList .time_ico.fl").parent().nextAll()[num].click(); } if ($("video").length > 0 && $("video").get(0).playbackRate != 1.5) { console.log('切換到1.5倍'); $(".speedTab15")[0].click(); } if ($("video").get(0).volume > 0) { $(".volumeIcon").click(); } } var divObj=document.createElement("div"); divObj.innerHTML='<h1 style="font-size:25px;">技術支援來自:Lee QQ:925776327<br>專案整體開源,歡迎Fork和Star <a href="https://github.com/leeli73/ZhiHuiShuShuaKe">github.com/leeli73/ZhiHuiShuShuaKe</a><br>你也可以通過Tampermonkey、Fiddler等軟體,向網頁中注入上面Git專案中的Code.js<br>本地版程式下載(無訪問限制版)<a href="https://www.lanzous.com/i237o3e">點選下載</a></h1>'; var first=document.body.firstChild; document.body.insertBefore(divObj,first); window.setInterval(query, 1000);</script>` func main() { proxy := goproxy.NewProxyHttpServer() fmt.Println("Proxy已經成功啟動...智慧樹課程頁面監控中...") fmt.Println("請將你的瀏覽器代理設定為127.0.0.1:8080 設定方法請百度,很簡單!") fmt.Println("支援在內網和外網通過IP訪問代理服務") fmt.Println("技術支援來自:Lee QQ:925776327") fmt.Println("專案整體開源,歡迎Fork和Star 專案地址:https://github.com/leeli73/ZhiHuiShuShuaKe") fmt.Println("你也可以通過Tampermonkey、Fiddler等軟體,向網頁中注入上面Git專案中的Code.js") fmt.Println("如果需要Server版,請聯絡上面的QQ") fmt.Println("如果出現報錯程式碼請不用管他。程式會自動熱重啟。") proxy.Verbose = false //proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm) proxy.OnRequest().DoFunc( func(r *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) { r.Header.Set("X-GoProxy","yxorPoG-X") //fmt.Println(r.Host) if r.URL.Scheme == "https" && !strings.Contains(r.Host,"zhihuishu"){ return r,goproxy.NewResponse(r, goproxy.ContentTypeText,http.StatusForbidden, "為了保證伺服器的能為每個同學提供刷課服務,伺服器已經關閉了你的這個HTTPS請求!tips:人心險惡,為了保證你的資料安全,請儘量避免使用未知的Proxy。") } if !strings.Contains(r.Host,"zhihuishu"){ return r,goproxy.NewResponse(r, goproxy.ContentTypeText,http.StatusForbidden, "為了保證伺服器的能為每個同學提供刷課服務,伺服器已經關閉了你的這個HTTP請求!tips:人心險惡,為了保證你的資料安全,請儘量避免使用未知的Proxy。") } return r,nil }) /*proxy.OnRequest(goproxy.DstHostIs("eol.qhu.edu.cn")).DoFunc( func(r *http.Request,ctx *goproxy.ProxyCtx)(*http.Request,*http.Response) { return r,goproxy.NewResponse(r, goproxy.ContentTypeText,http.StatusForbidden, "Don't waste your time!") })*/ proxy.OnResponse().DoFunc( func(r *http.Response, ctx *goproxy.ProxyCtx)*http.Response{ if strings.Contains(r.Request.URL.Path,"learning/videoList"){ bs, _ := ioutil.ReadAll(r.Body) sbs := string(bs) sbs = sbs + Code fmt.Println("發現課程頁面,刷課程式碼已經成功注入!") bs = []byte(sbs) r.Body = ioutil.NopCloser(bytes.NewReader(bs)) } return r }) http.ListenAndServe(":8080", proxy) }

然後就可以啦,我預設禁止了部分請求來降低伺服器負載,大家可以自主刪除

下面再給大家附帶一個編譯好的二進位制版

https://www.lanzous.com/i237o3e