欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

使用Go语言编写一个简单的SSH爆破工具

最编程 2024-07-05 16:35:37
...
package main import ( "bufio" "fmt" "golang.org/x/crypto/ssh" "log" "os" ) func main() { // SSH服务器的地址 const host = "your.ssh.server:22" // 从文件读取用户名和密码 username, password := readCredentials() // 创建SSH客户端配置 config := &ssh.ClientConfig{ User: username, Auth: []ssh.AuthMethod{ ssh.Password(password), }, HostKeyCallback: ssh.InsecureIgnoreHostKey(), } // 连接到SSH服务器 connection, err := ssh.Dial("tcp", host, config) if err != nil { log.Fatalf("Failed to dial: %s", err) } defer connection.Close() // 连接成功 fmt.Println("SSH connection established.") // 这里可以添加更多的SSH操作,比如执行命令等 } // 从文件中读取用户名和密码 func readCredentials() (string, string) { file, err := os.Open("username.txt") if err != nil { log.Fatalf("Failed to read username file: %s", err) } defer file.Close() scanner := bufio.NewScanner(file) scanner.Scan() username := scanner.Text() file, err = os.Open("password.txt") if err != nil { log.Fatalf("Failed to read password file: %s", err) } defer file.Close() scanner = bufio.NewScanner(file) scanner.Scan() password := scanner.Text() return username, password }

推荐阅读