forked from btfak/sniper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
90 lines (72 loc) · 1.83 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"encoding/base64"
"fmt"
"strconv"
)
var message Message
type Message struct {
content []byte
}
func (m *Message) prepareContent() {
m.buildHeader()
if config.Basic.method == "POST" {
m.buildBody()
}
}
func (m *Message) buildHeader() {
var msg, path string
//first line
path = config.Basic.target[0].path
if path == "" {
path = "/"
}
line := fmt.Sprintf("%s%s%s", config.Basic.method+" ", path+"?"+config.Basic.target[0].param+" ", config.Protocol.version+"\r\n")
msg = msg + line
//host
line = "Host: " + config.Basic.target[0].ip + "\r\n"
msg = msg + line
//accept
line = "Accept: */*" + "\r\n"
msg = msg + line
//Accept-Encoding
line = "Accept-Encoding: " + config.Protocol.acceptEncoding + "\r\n"
msg = msg + line
//User-Agent
line = "User-Agent: " + config.Protocol.userAgent + "\r\n"
msg = msg + line
//user-header
for k, v := range config.Header.head {
msg = msg + k + ": " + v + "\r\n"
}
//post
if config.Basic.method == "POST" {
//content-length
line = "Content-Length :" + strconv.Itoa(len(config.Command.postData)) + "\r\n"
msg = msg + line
//content-type
line = "Content-Type :" + config.Command.contentType + "\r\n"
msg = msg + line
}
//Authenticate
if login := config.Authenticate.login; login != "" {
line = "Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte(login)) + "\r\n"
msg = msg + line
}
//Connection
line = "Connection: " + config.Protocol.connection + "\r\n"
msg = msg + line
//blank line
line = "\r\n"
msg = msg + line
m.content = []byte(msg)
}
func (m *Message) buildBody() {
m.content = append(m.content, config.Command.postData...)
if config.Protocol.connection == "close" {
//end of post data
//m.content = append(m.content, []byte("\r\n")...)
//blank line
//m.content = append(m.content, []byte("\r\n")...)
}
}