mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-05-07 11:16:31 +00:00
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package Plugins
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/jlaffaye/ftp"
|
|
"github.com/shadow1ng/fscan/common"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func FtpScan(info *common.HostInfo) (tmperr error) {
|
|
if common.IsBrute {
|
|
return
|
|
}
|
|
starttime := time.Now().Unix()
|
|
flag, err := FtpConn(info, "anonymous", "")
|
|
if flag == true && err == nil {
|
|
return err
|
|
} else {
|
|
errlog := fmt.Sprintf("[-] ftp://%v:%v %v %v", info.Host, info.Ports, "anonymous", err)
|
|
common.LogError(errlog)
|
|
tmperr = err
|
|
if common.CheckErrs(err) {
|
|
return err
|
|
}
|
|
}
|
|
|
|
for _, user := range common.Userdict["ftp"] {
|
|
for _, pass := range common.Passwords {
|
|
pass = strings.Replace(pass, "{user}", user, -1)
|
|
flag, err := FtpConn(info, user, pass)
|
|
if flag == true && err == nil {
|
|
return err
|
|
} else {
|
|
errlog := fmt.Sprintf("[-] ftp://%v:%v %v %v %v", info.Host, info.Ports, user, pass, err)
|
|
common.LogError(errlog)
|
|
tmperr = err
|
|
if common.CheckErrs(err) {
|
|
return err
|
|
}
|
|
if time.Now().Unix()-starttime > (int64(len(common.Userdict["ftp"])*len(common.Passwords)) * info.Timeout) {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return tmperr
|
|
}
|
|
|
|
func FtpConn(info *common.HostInfo, user string, pass string) (flag bool, err error) {
|
|
flag = false
|
|
Host, Port, Username, Password := info.Host, info.Ports, user, pass
|
|
conn, err := ftp.DialTimeout(fmt.Sprintf("%v:%v", Host, Port), time.Duration(info.Timeout)*time.Second)
|
|
if err == nil {
|
|
err = conn.Login(Username, Password)
|
|
if err == nil {
|
|
flag = true
|
|
result := fmt.Sprintf("[+] ftp://%v:%v:%v %v", Host, Port, Username, Password)
|
|
dirs, err := conn.List("")
|
|
//defer conn.Logout()
|
|
if err == nil {
|
|
if len(dirs) > 0 {
|
|
for i := 0; i < len(dirs); i++ {
|
|
if len(dirs[i].Name) > 50 {
|
|
result += "\n [->]" + dirs[i].Name[:50]
|
|
} else {
|
|
result += "\n [->]" + dirs[i].Name
|
|
}
|
|
if i == 5 {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
common.LogSuccess(result)
|
|
}
|
|
}
|
|
return flag, err
|
|
}
|