├── .gitignore ├── LICENSE ├── README.md ├── TODO ├── config.conf ├── database ├── db.go ├── host.go └── payload.go ├── db_file.db ├── main.go ├── model ├── queries.go └── structs.go ├── screenshot ├── blacklist_example.png ├── host_creation.png ├── payload_creation.png ├── payload_deliver.png └── payload_list.png ├── servers ├── http.go ├── https.go └── vars.go ├── templates ├── .template_dir └── 404.html └── terminal ├── completers.go └── functions.go /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.tmp 3 | *.exe 4 | payloads 5 | certs 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-deliver 2 | 3 | Go-deliver is a payload delivery tool coded in Go. This is the first version and other features will be added in the future. 4 | 5 | 6 | ## Installation 7 | Compile from source: 8 | 9 | 1) Clone this repository. 10 | 2) Install the required dependecies. 11 | 3) Compile and run. 12 | 13 | ## Dependecies 14 | * https://github.com/chzyer/readline 15 | * https://github.com/gorilla/mux 16 | * https://github.com/mattn/go-sqlite3 17 | * https://github.com/olekukonko/tablewriter 18 | * http://gopkg.in/gcfg.v1 19 | 20 | ## Configuration 21 | Currently go-deliver supports only http and https server for payload delivery. More server types will be added later. 22 | To change the port of the http server you can modify the ```config.conf```. 23 | 24 | Sample configuration : 25 | 26 | ``` 27 | [http] 28 | enable = true 29 | port = 8888 30 | template404 = templates/404.html 31 | 32 | [https] 33 | enable = false 34 | port = 8443 35 | template404 = templates/404.html 36 | publickey = certs/server.pem 37 | privatekey = certs/server.key 38 | 39 | ``` 40 | 41 | ## Usage 42 | The main logic behind go-deliver is to deliver different type of payloads to specific IP/Subnet address or block access for specific IP/Subnet. 43 | 44 | Currently you have two types of objects in go-deliver. 45 | * Payload - Used to define an object to deliver. 46 | * Host - Used to define an object to combine with Payload object. 47 | 48 | ### Payload object commands 49 | * Add - Add a new payload to database. 50 | * Delete - Delete a payload from the database. 51 | * List - List all the payloads on the database. 52 | 53 | ### Payload types 54 | ```mshta regsrv32 powershell javascript html text exe``` 55 | 56 | ### Payload Options 57 | * Id - ID of the payload on the database. (Unchangeable) 58 | * Name - Name of the payload. 59 | * Content Type - Content Type that will be sent as a header. 60 | * Host Blacklist - The name of a Host object to be used as a blacklist. 61 | * Host Whitelist - The name of a Host object to be used as a whitelist. 62 | * Data File - Location of a file to be delivered. 63 | * Data B64 - B64 encoded data to be delivered. 64 | * Ptype - Payload type. 65 | * Guid - Unique identifier for every payload. 66 | 67 | Note : ``` If no whitelist or blacklist is specified the payload will get delivered to anyone with the correct URL.``` 68 | 69 | ### Host object commands 70 | * Add - Add a new host object to the database. 71 | * Delete - Delete a host object from the database. 72 | * List - List all the host objects on the database. 73 | 74 | ### Host options 75 | * Id - ID of the host object on the database. (Unchangeable) 76 | * Name - Name of the host object. 77 | * Htype - Host object type. It can be ```IP``` or ```Subnet``` 78 | 79 | ## TODO 80 | * Add more types of servers. 81 | * Add templates and the ability to generate payloads. 82 | * Add one-liner for every payload type. 83 | 84 | Suggestions ??? 85 | 86 | ## Screenshots 87 | ### Payload Creation 88 | 89 |  90 | 91 | ### Payload List 92 | 93 |  94 | 95 | ### Payload Deliver 96 | 97 |  98 | 99 | ### Host Creation 100 | 101 |  102 | 103 | ### Payload with Black List 104 | 105 |  106 | 107 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Version 0.1 2 | 3 | (x) Make payload delivery function. 4 | (x) Make payload creation function. 5 | (x) Make payload list function. 6 | (x) Make payload delete function. 7 | (x) Get payload types from db and make the suggestions based on that. 8 | (x) Get host from db and make suggestions on the payload options. 9 | (x) Make the host add/delete function. 10 | (x) Make the logic of hosts on payload delivery function. 11 | (x) Specify different 403 and 404 Error pages (From config). 12 | 13 | Other versions 14 | (-) Add different listeners like smb,https etc. -------------------------------------------------------------------------------- /config.conf: -------------------------------------------------------------------------------- 1 | [http] 2 | enable = true 3 | port = 8888 4 | template404 = templates/404.html 5 | 6 | [https] 7 | enable = false 8 | port = 8443 9 | template404 = templates/404.html 10 | publickey = certs/server.pem 11 | privatekey = certs/server.key 12 | 13 | -------------------------------------------------------------------------------- /database/db.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import "database/sql" 4 | 5 | var db_filename = "db_file.db" 6 | 7 | var db, _ = sql.Open("sqlite3", db_filename) 8 | 9 | -------------------------------------------------------------------------------- /database/host.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "go-deliver/model" 5 | "fmt" 6 | "log" 7 | "github.com/olekukonko/tablewriter" 8 | "os" 9 | 10 | ) 11 | 12 | func CreateHost(host model.Host) { 13 | tx, _ := db.Begin() 14 | stmt, err_stmt := tx.Prepare(model.CreateHostQuery) 15 | fmt.Println("") 16 | if err_stmt != nil { 17 | log.Fatal(err_stmt) 18 | } 19 | _, err := stmt.Exec(host.Name,host.Htype,host.Data) 20 | tx.Commit() 21 | if err != nil{ 22 | log.Println("ERROR: Error inserting host.") 23 | }else{ 24 | 25 | log.Println(fmt.Sprintf("Host with name %s created successfully.",host.Name)) // Fix the URL output 26 | } 27 | } 28 | 29 | func ListHosts() { 30 | 31 | rows, err := db.Query(model.GetHostsQuery) 32 | 33 | host := model.Host{} 34 | if err != nil { 35 | panic(err) 36 | } 37 | 38 | table := tablewriter.NewWriter(os.Stdout) 39 | table.SetHeader([]string{"Name", "Host Type", "Data"}) 40 | 41 | for rows.Next() { 42 | err := rows.Scan(&host.Id, &host.Name, &host.Htype , &host.Data) 43 | table.Append([]string{ host.Name,host.Htype,host.Data}) 44 | if err != nil { 45 | log.Fatal(err) 46 | } 47 | } 48 | table.Render() 49 | 50 | } 51 | 52 | func DeleteHost(name string) { 53 | tx, _ := db.Begin() 54 | stmt, _ := tx.Prepare(model.DeleteHostQuery) 55 | _, err := stmt.Exec(name) 56 | if err != nil{ 57 | log.Panic(err) 58 | } 59 | tx.Commit() 60 | log.Println(fmt.Sprintf("Success : Host %s deleted .",name)) 61 | } 62 | 63 | func GetData(name string) (string, string){ 64 | 65 | host := model.Host{} 66 | err := db.QueryRow(model.GetHostDataQuery, name).Scan(&host.Htype,&host.Data) 67 | if err != nil { 68 | panic(err) 69 | } 70 | return host.Htype, host.Data 71 | } 72 | 73 | 74 | func GetHostNameCompleter() func(string) []string{ 75 | 76 | return func(line string) []string { 77 | var HostNames []string 78 | var temp string 79 | rows, err := db.Query(model.GetHostNamesCompleterQuery) 80 | if err != nil { 81 | panic(err) 82 | } 83 | 84 | for rows.Next() { 85 | err := rows.Scan(&temp) 86 | HostNames = append(HostNames,temp) 87 | if err != nil { 88 | log.Fatal(err) 89 | } 90 | } 91 | return HostNames 92 | } 93 | } -------------------------------------------------------------------------------- /database/payload.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | 4 | import ( 5 | "net/http" 6 | "fmt" 7 | _ "database/sql" 8 | _"github.com/mattn/go-sqlite3" 9 | "log" 10 | "github.com/gorilla/mux" 11 | "net" 12 | "encoding/base64" 13 | "io/ioutil" 14 | "go-deliver/model" 15 | "math/rand" 16 | "time" 17 | "github.com/olekukonko/tablewriter" 18 | "os" 19 | ) 20 | 21 | 22 | 23 | 24 | var letters = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") 25 | 26 | 27 | func randomInit() { 28 | // There is no reason to use a strong number generator since the payloads already have whitelist/blacklists. 29 | rand.Seed(time.Now().UnixNano()) 30 | } 31 | 32 | 33 | 34 | func CreateTable() { 35 | 36 | // This function will create the requrired databases 37 | 38 | 39 | } 40 | 41 | 42 | func DeletePayload(name string) { 43 | 44 | tx, _ := db.Begin() 45 | stmt, _ := tx.Prepare(model.DeletePayloadQuery) 46 | _, err := stmt.Exec(name) 47 | if err != nil{ 48 | log.Panic(err) 49 | } 50 | tx.Commit() 51 | log.Println(fmt.Sprintf("Success : Payload %s deleted .",name)) 52 | } 53 | 54 | 55 | func RandStringRunes(n int) string { 56 | b := make([]rune, n) 57 | for i := range b { 58 | b[i] = letters[rand.Intn(len(letters))] 59 | } 60 | return string(b) 61 | } 62 | func GetTypeid(ptype string) (int , string) { 63 | 64 | payloadType := model.PayloadType{} 65 | err := db.QueryRow(model.GetPayloadTypeId, ptype).Scan(&payloadType.Type_id,&payloadType.Content_type) 66 | if err != nil { 67 | 68 | fmt.Println(fmt.Sprintf("ERROR: Payload type %s doesn't exist.",ptype)) 69 | return 0,"" 70 | } 71 | return payloadType.Type_id, payloadType.Content_type; 72 | } 73 | 74 | func GetPayloadDeleteCompleter() func(string) []string{ 75 | // This function is used to autocomplete the payload deletion. 76 | return func(line string) []string { 77 | var PayloadNames []string 78 | var temp string 79 | rows, err := db.Query(model.GetPayloadNamesQuery) 80 | if err != nil { 81 | panic(err) 82 | } 83 | 84 | for rows.Next() { 85 | err := rows.Scan(&temp) 86 | PayloadNames = append(PayloadNames,temp) 87 | if err != nil { 88 | log.Fatal(err) 89 | } 90 | } 91 | return PayloadNames 92 | } 93 | } 94 | 95 | 96 | func GetPayloadTypeCompleter() func(string) []string{ 97 | // This function is used to autocomplete the payload deletion. 98 | return func(line string) []string { 99 | var PayloadTypes []string 100 | var temp string 101 | rows, err := db.Query(model.GetPayloadTypesCompleterQuery) 102 | if err != nil { 103 | panic(err) 104 | } 105 | 106 | for rows.Next() { 107 | err := rows.Scan(&temp) 108 | PayloadTypes = append(PayloadTypes,temp) 109 | if err != nil { 110 | log.Fatal(err) 111 | } 112 | } 113 | return PayloadTypes 114 | } 115 | } 116 | 117 | 118 | 119 | func InsertPayload(payload model.Payload){ 120 | randomInit() 121 | 122 | tx, _ := db.Begin() 123 | stmt, err_stmt := tx.Prepare(model.InsertPayloadQuery) 124 | payload.Guid = RandStringRunes(32) 125 | 126 | fmt.Println("") 127 | if err_stmt != nil { 128 | log.Fatal(err_stmt) 129 | } 130 | _, err := stmt.Exec(payload.Name,payload.Content_type,payload.Host_blacklist,payload.Host_whitelist,payload.Data_file,payload.Data_b64,payload.Type_id,payload.Guid,payload.Filename) 131 | tx.Commit() 132 | if err != nil{ 133 | log.Println("ERROR: Error inserting payload.") 134 | }else{ 135 | 136 | log.Println(fmt.Sprintf("Payload with name %s created successfully.",payload.Name)) // Fix the URL output 137 | } 138 | 139 | } 140 | 141 | 142 | func ShowIndex(w http.ResponseWriter,r *http.Request) { 143 | w.WriteHeader(http.StatusOK) 144 | w.Write([]byte("It works !!!")) 145 | } 146 | 147 | func GetPayloads() { 148 | 149 | rows, err := db.Query(model.GetPayloadsQuery) 150 | 151 | payload := model.Payload{} 152 | if err != nil { 153 | panic(err) 154 | } 155 | 156 | table := tablewriter.NewWriter(os.Stdout) 157 | table.SetHeader([]string{"Name", "Path", "Content Type", "Hosts Blacklist" , "Hosts Whitelist"}) 158 | 159 | for rows.Next() { 160 | err := rows.Scan(&payload.Id, &payload.Name, &payload.Guid, &payload.Content_type,&payload.Host_whitelist, &payload.Host_blacklist) 161 | table.Append([]string{payload.Name,fmt.Sprintf("/%s/",payload.Guid),payload.Content_type,payload.Host_whitelist,payload.Host_blacklist}) 162 | if err != nil { 163 | log.Fatal(err) 164 | } 165 | } 166 | table.Render() 167 | } 168 | 169 | 170 | func GetPayload(w http.ResponseWriter,r *http.Request){ 171 | vars := mux.Vars(r) 172 | guid := vars["guid"] 173 | var response []byte 174 | allow := false 175 | 176 | payload := model.Payload{} 177 | err := db.QueryRow(model.GetPayloadQuery, guid).Scan(&payload.Id,&payload.Name,&payload.Content_type,&payload.Host_blacklist,&payload.Host_whitelist,&payload.Data_file,&payload.Data_b64,&payload.Type_id,&payload.Filename) 178 | if err != nil { 179 | log.Println(err) 180 | w.WriteHeader(http.StatusNotFound) 181 | return 182 | } 183 | 184 | ip , _ , _ := net.SplitHostPort(r.RemoteAddr) 185 | 186 | 187 | 188 | if payload.Data_file == ""{ 189 | if payload.Data_b64 != ""{ 190 | data, err := base64.StdEncoding.DecodeString(payload.Data_b64) 191 | if err != nil{ 192 | log.Println("ERROR : Decoding b64 payload failed.") 193 | return 194 | }else{ 195 | response = data 196 | } 197 | 198 | }else{ 199 | log.Println("ERROR : Payload delivery failed. No content or file specified.") 200 | response = []byte("") 201 | } 202 | }else{ 203 | // Write data from file 204 | data, err := ioutil.ReadFile(payload.Data_file) 205 | if err != nil{ 206 | log.Println(fmt.Sprintf("ERROR: Payload file %s not found.", payload.Data_file)) 207 | response = []byte("") 208 | } 209 | response = data 210 | } 211 | 212 | 213 | if payload.Host_whitelist != ""{ 214 | htype , data := GetData(payload.Host_whitelist) 215 | switch htype{ 216 | case "ip": 217 | //Check if remote ip is the same 218 | if data == ip{ 219 | allow = true 220 | } 221 | 222 | case "subnet": 223 | // Check if ip is in subnet 224 | _ , ipNet , _ := net.ParseCIDR(data) 225 | if ipNet.Contains(net.ParseIP(ip)){ 226 | allow = true 227 | } 228 | 229 | } 230 | 231 | }else if payload.Host_blacklist != ""{ 232 | htype , data := GetData(payload.Host_blacklist) 233 | switch htype{ 234 | case "ip": 235 | //Check if remote ip is the same 236 | if data == ip{ 237 | allow = false 238 | }else { 239 | allow = true 240 | } 241 | case "subnet": 242 | // Check if ip is in subnet 243 | _ , ipNet , _ := net.ParseCIDR(data) 244 | if ipNet.Contains(net.ParseIP(ip)){ 245 | allow = false 246 | }else{ 247 | allow = true 248 | } 249 | } 250 | }else { 251 | // If no whitelist or blacklist is defined the payload will get delivered. 252 | allow= true 253 | } 254 | 255 | if allow == true{ 256 | fmt.Println("") // Prints a new line 257 | log.Println(fmt.Sprintf("Delivering payload %s to IP : %s",payload.Name,ip)) 258 | 259 | w.Header().Set("Content-Type",payload.Content_type) 260 | if(payload.Filename != ""){ 261 | w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s",payload.Filename)) 262 | } 263 | 264 | w.WriteHeader(http.StatusOK) 265 | w.Write(response) 266 | }else{ 267 | w.WriteHeader(http.StatusForbidden) 268 | //w.Write([]byte("")) // Will write the 403 template later. 269 | log.Println(fmt.Sprintf("Denied access to IP: %s for %s payload.",ip,payload.Name)) 270 | } 271 | 272 | 273 | } 274 | 275 | func GetPayloadTypes() []model.PayloadType{ 276 | 277 | payloadTypes := []model.PayloadType{} 278 | 279 | rows, err := db.Query(model.GetPayloadTypesQuery) 280 | 281 | payloadType := model.PayloadType{} 282 | 283 | if err != nil { 284 | panic(err) 285 | } 286 | 287 | for rows.Next() { 288 | err := rows.Scan(&payloadType.Type_name,&payloadType.Content_type) 289 | payloadTypes = append(payloadTypes,payloadType) 290 | if err != nil { 291 | log.Fatal(err) 292 | } 293 | } 294 | 295 | return payloadTypes 296 | } -------------------------------------------------------------------------------- /db_file.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x09AL/go-deliver/11b568d624801741175f504388b7c34060ec9977/db_file.db -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | import ( 3 | "go-deliver/terminal" 4 | "go-deliver/model" 5 | "go-deliver/servers" 6 | "log" 7 | _ "database/sql" 8 | _"github.com/mattn/go-sqlite3" 9 | "gopkg.in/gcfg.v1" 10 | "fmt" 11 | b64 "encoding/base64" 12 | ) 13 | 14 | 15 | func main() { 16 | 17 | var b64_banner = "DQogIF9fX19fX19fICAgICAgICAgICAgICAgICBfX19fX19fXyAgICAgICAgIC5fXyAgLl9fICAgICAgICAgICAgICAgICAgICANCiAvICBfX19fXy8gIF9fX18gICAgICAgICAgIFxfX19fX18gXCAgIF9fX18gfCAgfCB8X198X18gIF9fIF9fX19fX19fX19fIA0KLyAgIFwgIF9fXyAvICBfIFwgICBfX19fX18gIHwgICAgfCAgXF8vIF9fIFx8ICB8IHwgIFwgIFwvIC8vIF9fIFxfICBfXyBcDQpcICAgIFxfXCAgKCAgPF8+ICkgL19fX19fLyAgfCAgICBgICAgXCAgX19fL3wgIHxffCAgfFwgICAvXCAgX19fL3wgIHwgXC8NCiBcX19fX19fICAvXF9fX18vICAgICAgICAgIC9fX19fX19fICAvXF9fXyAgPl9fX18vX198IFxfLyAgXF9fXyAgPl9ffCAgIA0KICAgICAgICBcLyAgICAgICAgICAgICAgICAgICAgICAgICBcLyAgICAgXC8gICAgICAgICAgICAgICAgICAgXC8gICAgICAgDQo=" 18 | banner, _ := b64.StdEncoding.DecodeString(b64_banner) 19 | fmt.Println(string(banner)) 20 | 21 | Configuration := model.CFG{} 22 | 23 | err := gcfg.ReadFileInto(&Configuration,"config.conf") 24 | 25 | if err != nil { 26 | log.Fatalf("Failed to parse gcfg data: %s", err) 27 | } 28 | 29 | if(Configuration.Http.Enable == "true"){ 30 | log.Println(fmt.Sprintf("Starting http server on port %d",Configuration.Http.Port)) 31 | go servers.StartHTTPListener(Configuration) 32 | } 33 | if(Configuration.Https.Enable == "true"){ 34 | log.Println(fmt.Sprintf("Starting https server on port %d",Configuration.Https.Port)) 35 | go servers.StartHTTPSListener(Configuration) 36 | } 37 | 38 | 39 | // Start the terminal 40 | terminal.StartTerminal() 41 | 42 | 43 | } -------------------------------------------------------------------------------- /model/queries.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | var CreateTableSql = `CREATE TABLE payloads ( 4 | id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, 5 | name TEXT NOT NULL UNIQUE, 6 | content_type TEXT, 7 | host_blacklist TEXT, 8 | host_whitelist TEXT, 9 | data_file TEXT, 10 | data_b64 TEXT, 11 | type_id INTEGER NOT NULL, 12 | guid TEXT NOT NULL UNIQUE 13 | ); 14 | ` 15 | 16 | var CreateHostSql = `CREATE TABLE hosts ( 17 | id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, 18 | type TEXT NOT NULL, 19 | data TEXT NOT NULL, 20 | restriction_type TEXT NOT NULL, 21 | );` 22 | 23 | var CreateTypesSql = `CREATE TABLE types ( 24 | id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, 25 | name TEXT NOT NULL UNIQUE, 26 | type_template TEXT 27 | content_type TEXT 28 | );` 29 | var DeletePayloadQuery = "DELETE FROM payloads where name == ?;" 30 | 31 | var InsertPayloadQuery = "INSERT INTO payloads VALUES (NULL,?,?,?,?,?,?,?,?,?);" 32 | 33 | var GetPayloadsQuery = "SELECT id, name, guid, content_type,COALESCE(host_blacklist, '') as host_blacklist, COALESCE(host_whitelist, '') as host_whitelist FROM payloads;" 34 | 35 | var GetPayloadQuery = `SELECT id, 36 | name, 37 | content_type, 38 | COALESCE(host_blacklist, '') as host_blacklist, 39 | COALESCE(host_whitelist, '') as host_whitelist, 40 | COALESCE(data_file, '') as data_file, 41 | COALESCE(data_b64, '') as data_b64 , 42 | type_id , 43 | COALESCE(filename, '') as filename 44 | from payloads 45 | WHERE guid=?` 46 | var GetPayloadNamesQuery = "SELECT name FROM payloads;" 47 | var GetPayloadTypesCompleterQuery = "SELECT type_name FROM payload_types;" 48 | var GetHostNamesCompleterQuery = "SELECT name FROM hosts;" 49 | var GetPayloadTypesQuery = "SELECT type_name , content_type FROM payload_types;" 50 | 51 | var GetPayloadTypeId = "SELECT type_id , COALESCE(content_type, '') as content_type FROM payload_types WHERE type_name == ?;"; 52 | 53 | var CreateHostQuery = "INSERT INTO hosts VALUES(NULL,?,?,?)" 54 | 55 | var GetHostsQuery = "SELECT * from hosts;" 56 | 57 | var DeleteHostQuery = "DELETE FROM hosts where name == ?;" 58 | 59 | var GetHostDataQuery = "SELECT type, data FROM hosts WHERE name == ?;" -------------------------------------------------------------------------------- /model/structs.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | 4 | type Payload struct { 5 | Id int 6 | Name string 7 | Content_type string 8 | Host_blacklist string 9 | Host_whitelist string 10 | Data_file string 11 | Data_b64 string 12 | Ptype string 13 | Type_id int 14 | Guid string 15 | Filename string 16 | //one_liner string 17 | 18 | } 19 | 20 | type Host struct { 21 | Id int 22 | Name string 23 | Htype string 24 | Data string 25 | 26 | } 27 | 28 | 29 | type PayloadType struct { 30 | Type_id int 31 | Type_name string 32 | Type_template string 33 | Content_type string 34 | } 35 | 36 | type CFG struct { 37 | Http struct { 38 | Enable string 39 | Port int 40 | Template404 string 41 | } 42 | Https struct { 43 | Enable string 44 | Port int 45 | Template404 string 46 | Publickey string 47 | Privatekey string 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /screenshot/blacklist_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x09AL/go-deliver/11b568d624801741175f504388b7c34060ec9977/screenshot/blacklist_example.png -------------------------------------------------------------------------------- /screenshot/host_creation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x09AL/go-deliver/11b568d624801741175f504388b7c34060ec9977/screenshot/host_creation.png -------------------------------------------------------------------------------- /screenshot/payload_creation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x09AL/go-deliver/11b568d624801741175f504388b7c34060ec9977/screenshot/payload_creation.png -------------------------------------------------------------------------------- /screenshot/payload_deliver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x09AL/go-deliver/11b568d624801741175f504388b7c34060ec9977/screenshot/payload_deliver.png -------------------------------------------------------------------------------- /screenshot/payload_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x09AL/go-deliver/11b568d624801741175f504388b7c34060ec9977/screenshot/payload_list.png -------------------------------------------------------------------------------- /servers/http.go: -------------------------------------------------------------------------------- 1 | package servers 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "github.com/gorilla/mux" 7 | "go-deliver/database" 8 | "go-deliver/model" 9 | "io/ioutil" 10 | ) 11 | 12 | 13 | 14 | 15 | 16 | func StartHTTPListener(Configuration model.CFG) { 17 | 18 | Config = Configuration 19 | listener := mux.NewRouter() 20 | listener.HandleFunc("/",database.ShowIndex).Methods("GET") 21 | listener.HandleFunc("/{guid}/",database.GetPayload).Methods("GET") 22 | listener.NotFoundHandler = http.HandlerFunc(handle404Error) 23 | 24 | server := &http.Server{ 25 | Addr:fmt.Sprintf(":%d",Config.Http.Port), 26 | Handler:listener, 27 | } 28 | 29 | 30 | server.ListenAndServe() 31 | } 32 | 33 | func handle404Error(w http.ResponseWriter, r *http.Request){ 34 | 35 | bData, err := ioutil.ReadFile(Config.Http.Template404) 36 | if err != nil { 37 | w.Write([]byte("What are you lookin for ?")) 38 | 39 | } 40 | w.Write(bData) 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /servers/https.go: -------------------------------------------------------------------------------- 1 | package servers 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "github.com/gorilla/mux" 7 | "go-deliver/database" 8 | "go-deliver/model" 9 | "io/ioutil" 10 | "log" 11 | ) 12 | 13 | 14 | 15 | 16 | 17 | func StartHTTPSListener(Configuration model.CFG) { 18 | 19 | Config = Configuration 20 | listener := mux.NewRouter() 21 | listener.HandleFunc("/",database.ShowIndex).Methods("GET") 22 | listener.HandleFunc("/{guid}/",database.GetPayload).Methods("GET") 23 | listener.NotFoundHandler = http.HandlerFunc(handle404ErrorSSL) 24 | 25 | err := http.ListenAndServeTLS(fmt.Sprintf(":%d",Config.Https.Port), Config.Https.Publickey, Config.Https.Privatekey, listener) 26 | if err != nil { 27 | log.Fatal("Error starting HTTPS Server : ", err) 28 | } 29 | 30 | } 31 | 32 | func handle404ErrorSSL(w http.ResponseWriter, r *http.Request){ 33 | 34 | bData, err := ioutil.ReadFile(Config.Https.Template404) 35 | if err != nil { 36 | w.Write([]byte("What are you lookin for ?")) 37 | 38 | } 39 | w.Write(bData) 40 | 41 | } 42 | -------------------------------------------------------------------------------- /servers/vars.go: -------------------------------------------------------------------------------- 1 | package servers 2 | 3 | import "go-deliver/model" 4 | 5 | var Config model.CFG 6 | 7 | 8 | -------------------------------------------------------------------------------- /templates/.template_dir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x09AL/go-deliver/11b568d624801741175f504388b7c34060ec9977/templates/.template_dir -------------------------------------------------------------------------------- /templates/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |The page you are looking for was not found on this server.
10 | 11 | -------------------------------------------------------------------------------- /terminal/completers.go: -------------------------------------------------------------------------------- 1 | package terminal 2 | 3 | import ( 4 | "github.com/chzyer/readline" 5 | "go-deliver/database" 6 | ) 7 | 8 | var MainCompleter = readline.NewPrefixCompleter( 9 | readline.PcItem("payload", 10 | readline.PcItem("add", 11 | readline.PcItemDynamic(database.GetPayloadTypeCompleter(), 12 | ), 13 | ), 14 | readline.PcItem("delete", 15 | readline.PcItemDynamic(database.GetPayloadDeleteCompleter()), 16 | ), 17 | readline.PcItem("list"), 18 | 19 | ), 20 | readline.PcItem("host", 21 | readline.PcItem("add"), 22 | readline.PcItem("list"), 23 | readline.PcItem("delete", 24 | readline.PcItemDynamic(database.GetHostNameCompleter()),), 25 | ), 26 | // readline.PcItem("listeners") To be implemented later . 27 | ) 28 | 29 | var PayloadCompleter = readline.NewPrefixCompleter( 30 | readline.PcItem("set", 31 | readline.PcItem("name"), 32 | readline.PcItem("content_type"), 33 | readline.PcItem("host_blacklist", 34 | readline.PcItemDynamic(database.GetHostNameCompleter()), 35 | ), 36 | readline.PcItem("host_whitelist", 37 | readline.PcItemDynamic(database.GetHostNameCompleter()), 38 | ), 39 | readline.PcItem("data_file"), 40 | readline.PcItem("data_b64"), 41 | readline.PcItem("ptype"), 42 | readline.PcItem("filename"), 43 | //readline.PcItem("listener"), // This is will be implemented later. 44 | ), 45 | readline.PcItem("unset", 46 | readline.PcItem("content_type"), 47 | readline.PcItem("host_blacklist"), 48 | readline.PcItem("host_whitelist"), 49 | readline.PcItem("data_file"), 50 | readline.PcItem("data_b64"), 51 | readline.PcItem("type"), 52 | //readline.PcItem("listener"), // This is will be implemented later. 53 | ), 54 | readline.PcItem("options"), 55 | readline.PcItem("create"), 56 | readline.PcItem("back"), 57 | 58 | ) 59 | 60 | 61 | var HostCompleter = readline.NewPrefixCompleter( 62 | readline.PcItem("set", 63 | readline.PcItem("name"), 64 | readline.PcItem("htype", 65 | readline.PcItem("ip"), 66 | readline.PcItem("subnet"), 67 | ), 68 | readline.PcItem("restriction_type", 69 | readline.PcItem("whitelist"), 70 | readline.PcItem("blacklist"), 71 | ), 72 | readline.PcItem("data"), 73 | ), 74 | readline.PcItem("options"), 75 | readline.PcItem("create"), 76 | readline.PcItem("back"), 77 | ) -------------------------------------------------------------------------------- /terminal/functions.go: -------------------------------------------------------------------------------- 1 | package terminal 2 | 3 | 4 | import( 5 | "fmt" 6 | "github.com/chzyer/readline" 7 | "strings" 8 | "io" 9 | "go-deliver/model" 10 | "go-deliver/database" 11 | "encoding/json" 12 | "log" 13 | 14 | ) 15 | 16 | var context string = "main" 17 | var prompt string = "go-deliver (\033[0;32m%s\033[0;0m)\033[31m >> \033[0;0m" 18 | 19 | func handleHostCreation(name string, l *readline.Instance){ 20 | host := model.Host{} 21 | host.Name = name 22 | l.Config.AutoComplete = HostCompleter 23 | l.SetPrompt(fmt.Sprintf(prompt,"host-options")) 24 | for {line, err := l.Readline() 25 | if err == readline.ErrInterrupt { 26 | if len(line) == 0 { 27 | break 28 | } else { 29 | continue 30 | } 31 | } else if err == io.EOF { 32 | break 33 | } 34 | 35 | line = strings.TrimSpace(line) 36 | 37 | temp := strings.Split(line," ") 38 | command := temp[0] 39 | switch command{ 40 | case "back": 41 | backMain(l) 42 | return 43 | case "options": 44 | // To be fixed 45 | data, err := json.MarshalIndent(host,"", " ") 46 | if err != nil { 47 | log.Fatal(err) 48 | } 49 | fmt.Printf("%s\n", data) 50 | 51 | case "set": 52 | if len(temp) == 3{ 53 | key := temp[1] 54 | value := temp[2] 55 | switch key{ 56 | case "name": 57 | host.Name = value 58 | case "htype": 59 | host.Htype = value 60 | case "data": 61 | host.Data = value 62 | } 63 | 64 | } 65 | case "unset": 66 | if len(temp) == 2{ 67 | key := temp[1] 68 | switch key{ 69 | case "name": 70 | host.Name = "" 71 | case "htype": 72 | host.Htype = "" 73 | case "data": 74 | host.Data = "" 75 | } 76 | } 77 | case "create": 78 | database.CreateHost(host) 79 | default: 80 | 81 | 82 | } 83 | } 84 | } 85 | 86 | func handlePayloadCreation(ptype string, l *readline.Instance) { 87 | 88 | payload := model.Payload{} 89 | payload.Ptype = ptype 90 | payload.Type_id,payload.Content_type = database.GetTypeid(ptype) 91 | 92 | 93 | l.Config.AutoComplete = PayloadCompleter 94 | l.SetPrompt(fmt.Sprintf(prompt,"payload-options")) 95 | 96 | for { 97 | line, err := l.Readline() 98 | if err == readline.ErrInterrupt { 99 | if len(line) == 0 { 100 | break 101 | } else { 102 | continue 103 | } 104 | } else if err == io.EOF { 105 | break 106 | } 107 | 108 | line = strings.TrimSpace(line) 109 | 110 | temp := strings.Split(line," ") 111 | command := temp[0] 112 | switch command{ 113 | case "back": 114 | backMain(l) 115 | return 116 | case "options": 117 | // To be fixed 118 | data, err := json.MarshalIndent(payload,"", " ") 119 | if err != nil { 120 | log.Fatal(err) 121 | } 122 | fmt.Printf("%s\n", data) 123 | 124 | case "set": 125 | if len(temp) == 3{ 126 | key := temp[1] 127 | value := temp[2] 128 | switch key{ 129 | case "name": 130 | payload.Name = value 131 | case "content_type": 132 | payload.Content_type = value 133 | case "host_whitelist": 134 | payload.Host_whitelist = value 135 | case "host_blacklist": 136 | payload.Host_blacklist = value 137 | case "data_file": 138 | payload.Data_file = value 139 | case "data_b64": 140 | payload.Data_b64 = value 141 | case "ptype": 142 | payload.Ptype = value 143 | case "filename": 144 | payload.Filename = value 145 | } 146 | 147 | } 148 | case "unset": 149 | if len(temp) == 2{ 150 | key := temp[1] 151 | switch key{ 152 | case "name": 153 | payload.Name = "" 154 | case "content_type": 155 | payload.Content_type = "" 156 | case "host_whitelist": 157 | payload.Host_whitelist = "" 158 | case "host_blacklist": 159 | payload.Host_blacklist = "" 160 | case "data_file": 161 | payload.Data_file = "" 162 | case "data_b64": 163 | payload.Data_b64 = "" 164 | case "ptype": 165 | payload.Ptype = "" 166 | case "filename": 167 | payload.Filename = "" 168 | } 169 | } 170 | case "create": 171 | database.InsertPayload(payload) 172 | default: 173 | 174 | 175 | } 176 | } 177 | } 178 | 179 | 180 | 181 | func backMain(l *readline.Instance){ 182 | context = "main" 183 | l.SetPrompt(fmt.Sprintf(prompt,"main")) 184 | l.Config.AutoComplete = MainCompleter 185 | } 186 | 187 | func handleInput(line string ,l *readline.Instance) { 188 | 189 | var ptype string 190 | var command string 191 | line = strings.TrimSpace(line) 192 | temp := strings.Split(line," ") 193 | if len(temp) >1 { 194 | command = temp[1] 195 | } 196 | 197 | switch { 198 | 199 | // Handle the payload functions 200 | case strings.HasPrefix(line, "payload "): 201 | 202 | switch command{ 203 | case "add": 204 | if len(temp) > 2{ 205 | ptype = temp[2] 206 | handlePayloadCreation(ptype,l) 207 | } 208 | case "delete": 209 | if len(temp) > 2{ 210 | name := temp[2] 211 | database.DeletePayload(name) 212 | } 213 | case "list": 214 | log.Println("Listing payloads") 215 | database.GetPayloads() 216 | default: 217 | fmt.Println("Invalid command") 218 | } 219 | 220 | // Handle the Hosts functions 221 | case strings.HasPrefix(line, "host "): 222 | switch command { 223 | case "add": 224 | if len(temp) > 2{ 225 | name := temp[2] 226 | handleHostCreation(name,l) 227 | } 228 | case "list": 229 | log.Println("Listing hosts") 230 | database.ListHosts() 231 | case "delete": 232 | if len(temp) > 2{ 233 | name := temp[2] 234 | database.DeleteHost(name) 235 | } 236 | default: 237 | fmt.Println("Invalid command") 238 | } 239 | 240 | } 241 | 242 | 243 | 244 | } 245 | 246 | func StartTerminal() { 247 | l, err := readline.NewEx(&readline.Config{ 248 | Prompt: fmt.Sprintf(prompt,"main"), 249 | HistoryFile: "history.tmp", 250 | InterruptPrompt: "^C", 251 | EOFPrompt: "exit", 252 | AutoComplete: MainCompleter, 253 | 254 | }) 255 | 256 | 257 | if err != nil { 258 | panic(err) 259 | } 260 | defer l.Close() 261 | 262 | for { 263 | 264 | line, err := l.Readline() 265 | if err == readline.ErrInterrupt { 266 | if len(line) == 0 { 267 | break 268 | } else { 269 | continue 270 | } 271 | } else if err == io.EOF { 272 | break 273 | } 274 | 275 | line = strings.TrimSpace(line) 276 | handleInput(line,l) 277 | 278 | 279 | } 280 | } 281 | 282 | 283 | --------------------------------------------------------------------------------