-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,419 additions
and
699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cmd | ||
|
||
import ( | ||
"cube/core" | ||
"cube/core/probemodule" | ||
"cube/gologger" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var probeCli *cobra.Command | ||
|
||
func runProbe(cmd *cobra.Command, args []string) { | ||
globalopts, opt, _ := parseProbeOptions() | ||
|
||
probemodule.StartProbe(opt, globalopts) | ||
} | ||
|
||
func parseProbeOptions() (*core.GlobalOption, *probemodule.ProbeOption, error) { | ||
globalOpts, err := parseGlobalOptions() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
probeOption := probemodule.NewProbeOption() | ||
|
||
probeOption.PluginName, err = probeCli.Flags().GetString("plugin") | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("invalid value for plugin: %v", err) | ||
} | ||
|
||
probeOption.Port, err = probeCli.Flags().GetString("port") | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("invalid value for scan port: %v", err) | ||
} | ||
|
||
probeOption.Ip, err = probeCli.Flags().GetString("service") | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("invalid value for target-ip: %w", err) | ||
} | ||
probeOption.IpFile, err = probeCli.Flags().GetString("service-file") | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("invalid value for target-file: %w", err) | ||
} | ||
return globalOpts, probeOption, nil | ||
} | ||
|
||
func init() { | ||
probeCli = &cobra.Command{ | ||
Use: "probe", | ||
Long: "long Desc", //TODO | ||
Short: "probe pentest env", | ||
Run: runProbe, | ||
Example: `cube probe -s 192.168.1.1 -x oxid | ||
cube probe -s 192.168.1.1 -x oxid,zookeeper,ms17010 | ||
cube probe -s 192.168.1.1/24 -x X | ||
`, | ||
} | ||
|
||
probeCli.Flags().StringP("port", "", "", "target port") | ||
probeCli.Flags().StringP("plugin", "x", "", "plugin to scan(e.g. oxid,ms17010)") | ||
probeCli.Flags().StringP("service", "s", "", "service ip(in the nmap format: 10.0.0.1, 10.0.0.5-10, 192.168.1.*, 192.168.10.0/24)") | ||
probeCli.Flags().StringP("service-file", "S", "", "File to probe for(e.g. ip.txt)") | ||
|
||
if err := crackCli.MarkFlagRequired("plugin"); err != nil { | ||
gologger.Errorf("error on marking flag as required: %v", err) | ||
} | ||
|
||
rootCmd.AddCommand(probeCli) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package crackmodule | ||
|
||
import ( | ||
"context" | ||
"cube/config" | ||
"cube/core" | ||
"cube/gologger" | ||
"fmt" | ||
"net" | ||
"sync" | ||
"time" | ||
) | ||
|
||
type IpAddr struct { | ||
Ip string | ||
Port string | ||
PluginName string | ||
} | ||
|
||
var ( | ||
mutex sync.Mutex | ||
AliveAddr []IpAddr | ||
ipList []IpAddr | ||
) | ||
|
||
func CheckPort(ctx context.Context, threadNum int, delay float64, ips []string, pluginNames []string, port string) []IpAddr { | ||
//指定插件端口的时候,只允许加载一个插件 | ||
if len(port) > 0 { | ||
for _, ip := range ips { | ||
ipList = append(ipList, IpAddr{ | ||
Ip: ip, | ||
Port: port, | ||
PluginName: pluginNames[0], | ||
}) | ||
} | ||
} else { | ||
for _, plugin := range pluginNames { | ||
for _, ip := range ips { | ||
ipList = append(ipList, IpAddr{ | ||
Ip: ip, | ||
Port: GetPort(plugin), | ||
PluginName: plugin, | ||
}) | ||
} | ||
} | ||
|
||
} | ||
|
||
var addrChan = make(chan IpAddr, threadNum*2) | ||
var wg sync.WaitGroup | ||
wg.Add(len(ipList)) | ||
|
||
for i := 0; i < threadNum; i++ { | ||
go func() { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case addr, ok := <-addrChan: | ||
if !ok { | ||
return | ||
} | ||
if GetTCP(addr.PluginName) { | ||
//TCP的时候检查端口,UDP跳过 | ||
SaveAddr(check(addr)) | ||
} | ||
wg.Done() | ||
select { | ||
case <-ctx.Done(): | ||
case <-time.After(time.Duration(core.RandomDelay(delay)) * time.Second): | ||
} | ||
} | ||
} | ||
}() | ||
} | ||
|
||
for _, addr := range ipList { | ||
addrChan <- addr | ||
} | ||
close(addrChan) | ||
wg.Wait() | ||
|
||
return AliveAddr | ||
} | ||
|
||
func check(addr IpAddr) (bool, IpAddr) { | ||
alive := false | ||
gologger.Debugf("tcp port conn check: %s:%s", addr.Ip, addr.Port) | ||
_, err := net.DialTimeout("tcp", fmt.Sprintf("%v:%v", addr.Ip, addr.Port), config.TcpConnTimeout) | ||
if err == nil { | ||
gologger.Infof("Open %s:%s", addr.Ip, addr.Port) | ||
alive = true | ||
} | ||
return alive, addr | ||
} | ||
|
||
//func checkUDP(addr IpAddr) (bool, IpAddr) { | ||
// //https://github.com/bronzdoc/gops | ||
// //alive := true | ||
// gologger.Debugf("skip udp port conn check: %s:%s", addr.Ip, addr.Port) | ||
// time.Sleep(time.Millisecond * 10) | ||
// | ||
// return true, addr | ||
//} | ||
|
||
func SaveAddr(alive bool, addr IpAddr) { | ||
if alive { | ||
mutex.Lock() | ||
AliveAddr = append(AliveAddr, addr) | ||
mutex.Unlock() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.