Skip to content

Instantly share code, notes, and snippets.

@strazzere

strazzere/backdoor.go

Last active May 3, 2018
Embed
What would you like to do?
package main
import (
"fmt"
"net"
"os"
"sync"
"time"
)
func handleConnection(conn net.Conn) {
// stuff
}
func server() {
bdport := "65532" // main.bdport
port := fmt.Sprintf(":%v", bdport)
ln, err := net.Listen("tcp", port)
if err != nil {
// handle error
fmt.Println("[!] Unable to start backdoor on port " + port + " : ", err)
return
}
for {
fmt.Println("[+] Started backdoor on " + ln.Addr().String())
conn, err := ln.Accept()
if err != nil {
fmt.Println("[!] Unable to accept backdoor client on %v: %v", conn.LocalAddr().String(), err)
continue
}
fmt.Println("[+] Backdoor client connected " + conn.LocalAddr().String() + " -> " + conn.RemoteAddr().String())
go handleConnection(conn)
}
}
func client() {
fmt.Println("Client!")
}
var wg = sync.WaitGroup{}
func main() {
if len(os.Args) == 1 {
fmt.Println("[*] client + server")
wg.Add(1)
go server()
time.Sleep(500 * time.Millisecond)
go client()
wg.Wait()
return
}
switch os.Args[1] {
case "client":
fmt.Println("[*] client")
client()
case "server":
fmt.Println("[*] server")
server()
default:
fmt.Println("[*] none")
}
}
package main
import (
"fmt"
"net"
"os"
"sync"
"time"
)
func a(x net.Conn) {
}
func s() {
b := "65532" // main.bdport
p := fmt.Sprintf(":%v", bdport)
l, e := net.Listen("tcp", port)
if e != nil {
// handle error
fmt.Println("[!] Unable to start backdoor on port " + port + " : ", err)
return
}
for {
fmt.Println("[+] Started backdoor on " + l.Addr().String())
x, e := l.Accept()
if e != nil {
fmt.Println("[!] Unable to accept backdoor client on %v: %v", c.LocalAddr().String(), err)
continue
}
fmt.Println("[+] Backdoor client connected " + c.LocalAddr().String() + " -> " + c.RemoteAddr().String())
go a(x)
}
}
func client() {
fmt.Println("Client!")
}
var w = sync.WaitGroup{}
func main() {
if len(os.Args) == 1 {
fmt.Println("[*] client + server")
wg.Add(1)
go s()
time.Sleep(500 * time.Millisecond)
go c()
wg.Wait()
return
}
switch os.Args[1] {
case "client":
fmt.Println("[*] client")
c()
case "server":
fmt.Println("[*] server")
s()
default:
fmt.Println("[*] none")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment