Skip to content

Commit

Permalink
优化sc,ss的输出逻辑, 存活b段输出到bcidr中, 存活c段输出到ccidr中
Browse files Browse the repository at this point in the history
  • Loading branch information
M09Ic committed Oct 8, 2022
1 parent 256107e commit c18dc86
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 80 deletions.
1 change: 1 addition & 0 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ require (
github.com/panjf2000/ants/v2 v2.5.0
golang.org/x/net v0.0.0-20190603091049-60506f45cf65
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
4 changes: 4 additions & 0 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
10 changes: 5 additions & 5 deletions v2/internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func SmartMod(target *ipcs.CIDR, config Config) {

// 输出启发式扫描探针
probeconfig := fmt.Sprintf("Smart port probes: %s ", strings.Join(config.PortProbeList, ","))
if config.IsASmart() {
if config.IsBSmart() {
probeconfig += ", Smart IP probes: " + fmt.Sprintf("%v", config.IpProbeList)
}
Log.Important(probeconfig)
Expand Down Expand Up @@ -132,11 +132,11 @@ func SmartMod(target *ipcs.CIDR, config Config) {
return
}

if config.SmartFile != nil && config.Mod != SUPERSMARTC {
WriteSmartResult(config.SmartFile, iplist.Strings())
if config.IsBSmart() {
WriteSmartResult(config.SmartBFile, iplist.Strings())
}
if config.File != nil && config.Mod == SUPERSMARTC {
WriteScReuslt(config.File, iplist.Strings())
if config.IsCSmart() {
WriteSmartResult(config.SmartCFile, iplist.Strings())
}

if Opt.Noscan || config.Mod == SUPERSMARTC {
Expand Down
19 changes: 0 additions & 19 deletions v2/internal/core/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
func NewIpGenerator(config Config) *IpGenerator {
var alivemap sync.Map
gen := IpGenerator{
//excludeIP: config.ExcludeMap,
alivedMap: &alivemap,
ipProbe: config.IpProbeList,
}
Expand Down Expand Up @@ -47,25 +46,13 @@ func (gen *IpGenerator) smartIpGenerator(cidr *ipcs.CIDR) {
for C = 1; C < 255; C++ {
for B = 0; B <= (fin-start)/256; B++ {
outIP = ipcs.Int2Ip(start + 256*B + C)
//if isnotAlive(ipcs.Int2Ip(start+256*B), gen.alivedMap) && !gen.excludeIP[start+256*B+C] {
if isnotAlive(ipcs.Int2Ip(start+256*B), gen.alivedMap) {
gen.ch <- outIP
}
}
}
}

//func (gen *IpGenerator) IPsGenerator(ips []string) {
// for _, cidr := range ips {
// tmpalive := Opt.AliveSum
// gen.defaultIpGenerator(cidr)
// if getMask(cidr) != 32 {
// Log.Importantf("Processed CIDR: %s, found %d ports", cidr, Opt.AliveSum-tmpalive)
// syncFile()
// }
// }
//}

func (gen *IpGenerator) sSmartGenerator(cidr *ipcs.CIDR) {
start, fin := cidr.Range()
//ch := make(chan string)
Expand All @@ -75,15 +62,9 @@ func (gen *IpGenerator) sSmartGenerator(cidr *ipcs.CIDR) {
//go func() {
for c = 0; c < 255; c++ {
for b = 0; b <= finb-startb; b++ {
//println(int2ip(start + b*65536 + c*256 + 1))
//ip := int2ip(start + b*65536 + c + 1)
if isnotAlive(ipcs.Int2Ip(start+b*65536+256), gen.alivedMap) {
//println(int2ip(start + b*65536 + c*256 + 1))
for _, p := range gen.ipProbe {
gen.ch <- ipcs.Int2Ip(start + b*65536 + c*256 + p)
//if !gen.excludeIP[start+b*65536+c*256+p] {
//
//}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion v2/internal/core/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func RunTask(config Config) {
for _, ip := range config.CIDRs {
SmartMod(ip, config)
}
} else {
Log.Warn("no validate ip/cidr")
}
default:
createDefaultScan(config)
Expand Down Expand Up @@ -167,7 +169,7 @@ func guessSmartTime(cidr *ipcs.CIDR, config Config) int {
var spc, ippc int
var mask int
spc = len(config.PortProbeList)
if config.IsBSmart() {
if config.IsCSmart() {
ippc = 1
} else {
ippc = len(config.IpProbeList)
Expand Down
28 changes: 18 additions & 10 deletions v2/internal/core/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ func (r *Runner) Run() {

func (r *Runner) runWithCMD() {
config := r.Config
if config.Mod == SUPERSMARTB {
config.FileOutputf = SUPERSMARTB
}

if config.Filename != "" {
logs.Log.Warn("The result file has been specified, other files will not be created.")
}

if config.Filename == "" && config.IsBSmart() {
config.SmartBFilename = GetFilename(&config, "bcidr")
}
if config.Filename == "" && config.IsSmart() {
config.SmartFilename = GetFilename(&config, "cidr")
config.SmartCFilename = GetFilename(&config, "ccidr")
}
if config.Filename == "" && config.HasAlivedScan() {
config.AlivedFilename = GetFilename(&config, "alived")
Expand Down Expand Up @@ -251,13 +251,15 @@ func (r *Runner) runWithWorkFlow(workflowMap WorkflowMap) {
logs.Log.Warn("The result file has been specified, other files will not be created.")
}

if config.Filename == "" && config.IsBSmart() {
config.SmartBFilename = GetFilename(config, "bcidr")
}
if config.Filename == "" && config.IsSmart() {
config.SmartFilename = GetFilename(config, "cidr")
config.SmartCFilename = GetFilename(config, "ccidr")
}
if config.Filename == "" && config.HasAlivedScan() {
config.AlivedFilename = GetFilename(config, "alived")
}

if config.Filenamef != "" {
config.Filename = GetFilename(config, config.FileOutputf)
}
Expand Down Expand Up @@ -301,8 +303,11 @@ func (r *Runner) Close(config *Config) {

if r.HiddenFile {
Chtime(config.Filename)
if config.SmartFilename != "" {
Chtime(config.SmartFilename)
if config.SmartBFile != nil && config.SmartBFile.InitSuccess {
Chtime(config.SmartBFilename)
}
if config.SmartCFile != nil && config.SmartCFile.InitSuccess {
Chtime(config.SmartBFilename)
}
}

Expand All @@ -314,8 +319,11 @@ func (r *Runner) Close(config *Config) {
if config.File != nil && config.File.InitSuccess {
logs.Log.Importantf("Results: " + config.Filename)
}
if config.SmartFile != nil && config.SmartFile.InitSuccess {
logs.Log.Important("Smart result: " + config.SmartFilename)
if config.SmartBFile != nil && config.SmartBFile.InitSuccess {
logs.Log.Important("B CIDRs result: " + config.SmartBFilename)
}
if config.SmartCFile != nil && config.SmartCFile.InitSuccess {
logs.Log.Important("c CIDRs result: " + config.SmartCFilename)
}
if config.AliveFile != nil && config.AliveFile.Initialized {
logs.Log.Important("Alived result: " + config.AlivedFilename)
Expand Down
43 changes: 24 additions & 19 deletions v2/pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ type Config struct {
// output
FilePath string `json:"-"`
Filename string `json:"-"`
SmartFilename string `json:"-"`
SmartBFilename string `json:"-"`
SmartCFilename string `json:"-"`
AlivedFilename string `json:"-"`
File *File `json:"-"`
SmartFile *File `json:"-"`
SmartBFile *File `json:"-"`
SmartCFile *File `json:"-"`
ExtractFile *File `json:"-"`
AliveFile *File `json:"-"`
Tee bool `json:"-"`
Expand Down Expand Up @@ -142,15 +144,25 @@ func (config *Config) InitFile() error {
config.ExtractFile, err = newFile(config.Filename+"_extract", config.Compress)
}

// -af 参数下的启发式扫描结果handler初始化
if config.SmartFilename != "" {
config.SmartFile, err = newFile(config.SmartFilename, config.Compress)
// -af 参数下的启发式扫描结果file初始化
if config.SmartBFilename != "" {
config.SmartBFile, err = newFile(config.SmartBFilename, config.Compress)
if err != nil {
return err
}

config.SmartFile.Write(fmt.Sprintf("{\"config\":%s,\"data\":[", config.ToJson("smart")))
config.SmartFile.ClosedAppend = "]}"
config.SmartBFile.Write(fmt.Sprintf("{\"config\":%s,\"data\":[", config.ToJson("smartb")))
config.SmartBFile.ClosedAppend = "]}"
}

if config.SmartCFilename != "" {
config.SmartCFile, err = newFile(config.SmartCFilename, config.Compress)
if err != nil {
return err
}

config.SmartCFile.Write(fmt.Sprintf("{\"config\":%s,\"data\":[", config.ToJson("smartc")))
config.SmartCFile.ClosedAppend = "]}"
}

if config.AlivedFilename != "" {
Expand Down Expand Up @@ -220,8 +232,8 @@ func (config *Config) Close() {
if config.File != nil {
config.File.Close()
}
if config.SmartFile != nil {
config.SmartFile.Close()
if config.SmartBFile != nil {
config.SmartBFile.Close()
}
if config.AliveFile != nil {
config.AliveFile.Close()
Expand All @@ -232,7 +244,7 @@ func (config *Config) Close() {
}

func (config *Config) IsScan() bool {
if config.IP != "" || config.ListFile != "" || config.JsonFile != "" || config.Mod == "a" {
if config.IP != "" || config.ListFile != "" || config.JsonFile != "" {
return true
}
return false
Expand All @@ -245,21 +257,14 @@ func (config *Config) IsSmart() bool {
return false
}

func (config *Config) IsSmartScan() bool {
if utils.SliceContains([]string{SUPERSMART, SMART}, config.Mod) {
return true
}
return false
}

func (config *Config) IsASmart() bool {
func (config *Config) IsBSmart() bool {
if utils.SliceContains([]string{SUPERSMART, SUPERSMARTB}, config.Mod) {
return true
}
return false
}

func (config *Config) IsBSmart() bool {
func (config *Config) IsCSmart() bool {
if utils.SliceContains([]string{SMART, SUPERSMARTC}, config.Mod) {
return true
}
Expand Down
25 changes: 12 additions & 13 deletions v2/pkg/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ var pingcommaflag bool
var sccommaflag bool

func WriteSmartResult(file *File, ips []string) {
file.SafeWrite(commaStream(ips, &smartcommaflag))
file.SafeSync()
if file != nil {
file.SafeWrite(commaStream(ips, &smartcommaflag))
file.SafeSync()
}
}

func WriteAlivedResult(file *File, ips []string) {
file.SafeWrite(commaStream(ips, &pingcommaflag))
file.SafeSync()
}

func WriteScReuslt(file *File, ips []string) {
file.SafeWrite(commaStream(ips, &sccommaflag))
file.SafeSync()
if file != nil {
file.SafeWrite(commaStream(ips, &pingcommaflag))
file.SafeSync()
}
}

func HasStdin() bool {
Expand Down Expand Up @@ -108,16 +107,16 @@ func GetFilename(config *Config, name string) string {
var basename string
var basepath string

if config.Filename != "" {
return config.Filename
}

if config.FilePath == "" {
basepath = utils.GetExcPath()
} else {
basepath = config.FilePath
}

if config.Filename != "" {
return config.Filename
}

if config.Filenamef == "auto" {
basename = path.Join(basepath, "."+getAutoFilename(config, name)+".dat")
} else if config.Filenamef == "hidden" {
Expand Down
2 changes: 1 addition & 1 deletion v2/pkg/result_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func LoadResultFile(file *os.File) interface{} {
}

content = bytes.TrimSpace(content) // 去除前后空格
if bytes.Contains(content, []byte("\"smart\",")) || bytes.Contains(content, []byte("\"ping\",")) {
if bytes.Contains(content, []byte("\"smartb\",")) || bytes.Contains(content, []byte("\"smartc\",")) || bytes.Contains(content, []byte("\"ping\",")) {
// 解析启发式扫描结果
content = autofixjson(content)
data, err = loadSmartResult(content)
Expand Down
20 changes: 8 additions & 12 deletions v2/pkg/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ type Workflow struct {
Ports string `json:"ports"`
Mod string `json:"mod"`
Ping bool `json:"ping"`
//Arp bool `json:"arp"`
NoScan bool `json:"no-scan"`
IpProbe string `json:"ipprobe"`
SmartProbe string `json:"portprobe"`
Exploit string `json:"exploit"`
Version int `json:"version"`
File string `json:"file"`
Path string `json:"path"`
Tags []string `json:"tags"`
NoScan bool `json:"no-scan"`
IpProbe string `json:"ipprobe"`
SmartProbe string `json:"portprobe"`
Exploit string `json:"exploit"`
Version int `json:"version"`
File string `json:"file"`
Path string `json:"path"`
Tags []string `json:"tags"`
}

func ParseWorkflowsFromInput(content []byte) []*Workflow {
Expand Down Expand Up @@ -68,9 +67,6 @@ func (w *Workflow) PrepareConfig(rconfig Config) *Config {
config.Ports = rconfig.Ports
}

//if w.Arp {
// config.AliveSprayMod = append(config.AliveSprayMod, "arp")
//}
if w.Ping {
config.AliveSprayMod = append(config.AliveSprayMod, "icmp")
}
Expand Down

0 comments on commit c18dc86

Please sign in to comment.