This commit is contained in:
影舞者 2023-11-13 16:23:19 +08:00
parent 6bf396d09f
commit 1c631133ad
14 changed files with 41 additions and 38 deletions

View File

@ -106,10 +106,10 @@ func SmbGhostScan(info *common.HostInfo) error {
ip, port, timeout := info.Host, 445, time.Duration(common.Timeout)*time.Second ip, port, timeout := info.Host, 445, time.Duration(common.Timeout)*time.Second
addr := fmt.Sprintf("%s:%v", info.Host, port) addr := fmt.Sprintf("%s:%v", info.Host, port)
conn, err := common.WrapperTcpWithTimeout("tcp", addr, timeout) conn, err := common.WrapperTcpWithTimeout("tcp", addr, timeout)
defer conn.Close()
if err != nil { if err != nil {
return err return err
} }
defer conn.Close()
_, err = conn.Write([]byte(pkt)) _, err = conn.Write([]byte(pkt))
if err != nil { if err != nil {
return err return err

View File

@ -41,10 +41,10 @@ func NetBIOS1(info *common.HostInfo) (netbios NetBiosInfo, err error) {
realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports) realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports)
var conn net.Conn var conn net.Conn
conn, err = common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second) conn, err = common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
return return
} }
defer conn.Close()
err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second)) err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
if err != nil { if err != nil {
return return
@ -89,10 +89,10 @@ func GetNbnsname(info *common.HostInfo) (netbios NetBiosInfo, err error) {
//senddata1 := []byte("ff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00 CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x00\x00!\x00\x01") //senddata1 := []byte("ff\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00 CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x00\x00!\x00\x01")
realhost := fmt.Sprintf("%s:137", info.Host) realhost := fmt.Sprintf("%s:137", info.Host)
conn, err := net.DialTimeout("udp", realhost, time.Duration(common.Timeout)*time.Second) conn, err := net.DialTimeout("udp", realhost, time.Duration(common.Timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
return return
} }
defer conn.Close()
err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second)) err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
if err != nil { if err != nil {
return return

View File

@ -24,10 +24,10 @@ func Findnet(info *common.HostInfo) error {
func FindnetScan(info *common.HostInfo) error { func FindnetScan(info *common.HostInfo) error {
realhost := fmt.Sprintf("%s:%v", info.Host, 135) realhost := fmt.Sprintf("%s:%v", info.Host, 135)
conn, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second) conn, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
return err return err
} }
defer conn.Close()
err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second)) err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
if err != nil { if err != nil {
return err return err

View File

@ -39,11 +39,11 @@ func MS17010Scan(info *common.HostInfo) error {
ip := info.Host ip := info.Host
// connecting to a host in LAN if reachable should be very quick // connecting to a host in LAN if reachable should be very quick
conn, err := common.WrapperTcpWithTimeout("tcp", ip+":445", time.Duration(common.Timeout)*time.Second) conn, err := common.WrapperTcpWithTimeout("tcp", ip+":445", time.Duration(common.Timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
//fmt.Printf("failed to connect to %s\n", ip) //fmt.Printf("failed to connect to %s\n", ip)
return err return err
} }
defer conn.Close()
err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second)) err = conn.SetDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
if err != nil { if err != nil {
//fmt.Printf("failed to connect to %s\n", ip) //fmt.Printf("failed to connect to %s\n", ip)

View File

@ -74,8 +74,8 @@ func PortScan(hostslist []string, ports string, timeout int64) []string {
func PortConnect(addr Addr, respondingHosts chan<- string, adjustedTimeout int64, wg *sync.WaitGroup) { func PortConnect(addr Addr, respondingHosts chan<- string, adjustedTimeout int64, wg *sync.WaitGroup) {
host, port := addr.ip, addr.port host, port := addr.ip, addr.port
conn, err := common.WrapperTcpWithTimeout("tcp4", fmt.Sprintf("%s:%v", host, port), time.Duration(adjustedTimeout)*time.Second) conn, err := common.WrapperTcpWithTimeout("tcp4", fmt.Sprintf("%s:%v", host, port), time.Duration(adjustedTimeout)*time.Second)
defer conn.Close()
if err == nil { if err == nil {
defer conn.Close()
address := host + ":" + strconv.Itoa(port) address := host + ":" + strconv.Itoa(port)
result := fmt.Sprintf("%s open", address) result := fmt.Sprintf("%s open", address)
common.LogSuccess(result) common.LogSuccess(result)

View File

@ -127,10 +127,10 @@ func NewClient(host string, logLevel glog.LEVEL) *Client {
func (g *Client) Login(domain, user, pwd string, timeout int64) error { func (g *Client) Login(domain, user, pwd string, timeout int64) error {
conn, err := common.WrapperTcpWithTimeout("tcp", g.Host, time.Duration(timeout)*time.Second) conn, err := common.WrapperTcpWithTimeout("tcp", g.Host, time.Duration(timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
return fmt.Errorf("[dial err] %v", err) return fmt.Errorf("[dial err] %v", err)
} }
defer conn.Close()
glog.Info(conn.LocalAddr().String()) glog.Info(conn.LocalAddr().String())
g.tpkt = tpkt.New(core.NewSocketLayer(conn), nla.NewNTLMv2(domain, user, pwd)) g.tpkt = tpkt.New(core.NewSocketLayer(conn), nla.NewNTLMv2(domain, user, pwd))

View File

@ -48,10 +48,10 @@ func RedisConn(info *common.HostInfo, pass string) (flag bool, err error) {
flag = false flag = false
realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports) realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports)
conn, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second) conn, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
return flag, err return flag, err
} }
defer conn.Close()
err = conn.SetReadDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second)) err = conn.SetReadDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
if err != nil { if err != nil {
return flag, err return flag, err
@ -84,10 +84,10 @@ func RedisUnauth(info *common.HostInfo) (flag bool, err error) {
flag = false flag = false
realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports) realhost := fmt.Sprintf("%s:%v", info.Host, info.Ports)
conn, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second) conn, err := common.WrapperTcpWithTimeout("tcp", realhost, time.Duration(common.Timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
return flag, err return flag, err
} }
defer conn.Close()
err = conn.SetReadDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second)) err = conn.SetReadDeadline(time.Now().Add(time.Duration(common.Timeout) * time.Second))
if err != nil { if err != nil {
return flag, err return flag, err

View File

@ -33,12 +33,12 @@ func Scan(info common.HostInfo) {
} }
var AlivePorts []string var AlivePorts []string
if common.Scantype == "webonly" || common.Scantype == "webpoc" { if common.Scantype == "webonly" || common.Scantype == "webpoc" {
AlivePorts = NoPortScan(Hosts, info.Ports) AlivePorts = NoPortScan(Hosts, common.Ports)
} else if common.Scantype == "hostname" { } else if common.Scantype == "hostname" {
info.Ports = "139" common.Ports = "139"
AlivePorts = NoPortScan(Hosts, info.Ports) AlivePorts = NoPortScan(Hosts, common.Ports)
} else if len(Hosts) > 0 { } else if len(Hosts) > 0 {
AlivePorts = PortScan(Hosts, info.Ports, common.Timeout) AlivePorts = PortScan(Hosts, common.Ports, common.Timeout)
fmt.Println("[*] alive ports len is:", len(AlivePorts)) fmt.Println("[*] alive ports len is:", len(AlivePorts))
if common.Scantype == "portscan" { if common.Scantype == "portscan" {
common.LogWG.Wait() common.LogWG.Wait()
@ -90,7 +90,7 @@ func Scan(info common.HostInfo) {
wg.Wait() wg.Wait()
common.LogWG.Wait() common.LogWG.Wait()
close(common.Results) close(common.Results)
fmt.Println(fmt.Sprintf("已完成 %v/%v", common.End, common.Num)) fmt.Printf("已完成 %v/%v\n", common.End, common.Num)
} }
var Mutex = &sync.Mutex{} var Mutex = &sync.Mutex{}

View File

@ -67,10 +67,10 @@ func SmbScan2(info *common.HostInfo) (tmperr error) {
func Smb2Con(info *common.HostInfo, user string, pass string, hash []byte, hasprint bool) (flag bool, err error, flag2 bool) { func Smb2Con(info *common.HostInfo, user string, pass string, hash []byte, hasprint bool) (flag bool, err error, flag2 bool) {
conn, err := net.DialTimeout("tcp", info.Host+":445", time.Duration(common.Timeout)*time.Second) conn, err := net.DialTimeout("tcp", info.Host+":445", time.Duration(common.Timeout)*time.Second)
defer conn.Close()
if err != nil { if err != nil {
return return
} }
defer conn.Close()
initiator := smb2.NTLMInitiator{ initiator := smb2.NTLMInitiator{
User: user, User: user,
Domain: common.Domain, Domain: common.Domain,

View File

@ -101,7 +101,7 @@ func ParsePass(Info *HostInfo) {
newport += port + "," newport += port + ","
} }
} }
Info.Ports = newport Ports = newport
} }
} }
} }
@ -140,15 +140,15 @@ func ParseInput(Info *HostInfo) {
IsSave = false IsSave = false
} }
if Info.Ports == DefaultPorts { if Ports == DefaultPorts {
Info.Ports += "," + Webport Ports += "," + Webport
} }
if PortAdd != "" { if PortAdd != "" {
if strings.HasSuffix(Info.Ports, ",") { if strings.HasSuffix(Ports, ",") {
Info.Ports += PortAdd Ports += PortAdd
} else { } else {
Info.Ports += "," + PortAdd Ports += "," + PortAdd
} }
} }
@ -219,35 +219,35 @@ func ParseScantype(Info *HostInfo) {
if !ok { if !ok {
showmode() showmode()
} }
if Scantype != "all" && Info.Ports == DefaultPorts+","+Webport { if Scantype != "all" && Ports == DefaultPorts+","+Webport {
switch Scantype { switch Scantype {
case "wmiexec": case "wmiexec":
Info.Ports = "135" Ports = "135"
case "wmiinfo": case "wmiinfo":
Info.Ports = "135" Ports = "135"
case "smbinfo": case "smbinfo":
Info.Ports = "445" Ports = "445"
case "hostname": case "hostname":
Info.Ports = "135,137,139,445" Ports = "135,137,139,445"
case "smb2": case "smb2":
Info.Ports = "445" Ports = "445"
case "web": case "web":
Info.Ports = Webport Ports = Webport
case "webonly": case "webonly":
Info.Ports = Webport Ports = Webport
case "ms17010": case "ms17010":
Info.Ports = "445" Ports = "445"
case "cve20200796": case "cve20200796":
Info.Ports = "445" Ports = "445"
case "portscan": case "portscan":
Info.Ports = DefaultPorts + "," + Webport Ports = DefaultPorts + "," + Webport
case "main": case "main":
Info.Ports = DefaultPorts Ports = DefaultPorts
default: default:
port, _ := PORTList[Scantype] port, _ := PORTList[Scantype]
Info.Ports = strconv.Itoa(port) Ports = strconv.Itoa(port)
} }
fmt.Println("-m ", Scantype, " start scan the port:", Info.Ports) fmt.Println("-m ", Scantype, " start scan the port:", Ports)
} }
} }

View File

@ -15,6 +15,9 @@ func ParsePort(ports string) (scanPorts []int) {
if port == "" { if port == "" {
continue continue
} }
if PortGroup[port] != "" {
port = PortGroup[port]
}
upper := port upper := port
if strings.Contains(port, "-") { if strings.Contains(port, "-") {
ranges := strings.Split(port, "-") ranges := strings.Split(port, "-")

View File

@ -82,6 +82,7 @@ type PocInfo struct {
} }
var ( var (
Ports string
Path string Path string
Scantype string Scantype string
Command string Command string

View File

@ -20,7 +20,7 @@ func Flag(Info *HostInfo) {
Banner() Banner()
flag.StringVar(&Info.Host, "h", "", "IP address of the host you want to scan,for example: 192.168.11.11 | 192.168.11.11-255 | 192.168.11.11,192.168.11.12") flag.StringVar(&Info.Host, "h", "", "IP address of the host you want to scan,for example: 192.168.11.11 | 192.168.11.11-255 | 192.168.11.11,192.168.11.12")
flag.StringVar(&NoHosts, "hn", "", "the hosts no scan,as: -hn 192.168.1.1/24") flag.StringVar(&NoHosts, "hn", "", "the hosts no scan,as: -hn 192.168.1.1/24")
flag.StringVar(&Info.Ports, "p", DefaultPorts, "Select a port,for example: 22 | 1-65535 | 22,80,3306") flag.StringVar(&Ports, "p", DefaultPorts, "Select a port,for example: 22 | 1-65535 | 22,80,3306")
flag.StringVar(&PortAdd, "pa", "", "add port base DefaultPorts,-pa 3389") flag.StringVar(&PortAdd, "pa", "", "add port base DefaultPorts,-pa 3389")
flag.StringVar(&UserAdd, "usera", "", "add a user base DefaultUsers,-usera user") flag.StringVar(&UserAdd, "usera", "", "add a user base DefaultUsers,-usera user")
flag.StringVar(&PassAdd, "pwda", "", "add a password base DefaultPasses,-pwda password") flag.StringVar(&PassAdd, "pwda", "", "add a password base DefaultPasses,-pwda password")

View File

@ -13,6 +13,5 @@ func main() {
common.Flag(&Info) common.Flag(&Info)
common.Parse(&Info) common.Parse(&Info)
Plugins.Scan(Info) Plugins.Scan(Info)
t := time.Since(start) fmt.Printf("[*] 扫描结束,耗时: %s\n", time.Since(start))
fmt.Printf("[*] 扫描结束,耗时: %s\n", t)
} }