mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
42b08db0b0
commit
7c2dc38819
4 changed files with 43 additions and 31 deletions
|
@ -100,7 +100,7 @@ func (s EventsStream) viewSynScanEvent(e session.Event) {
|
||||||
e.Time.Format(eventTimeFormat),
|
e.Time.Format(eventTimeFormat),
|
||||||
core.Green(e.Tag),
|
core.Green(e.Tag),
|
||||||
se.Port,
|
se.Port,
|
||||||
core.Bold(se.Host.IpAddress))
|
core.Bold(se.Address))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EventsStream) View(e session.Event, refresh bool) {
|
func (s *EventsStream) View(e session.Event, refresh bool) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evilsocket/bettercap-ng/core"
|
"github.com/evilsocket/bettercap-ng/core"
|
||||||
|
@ -39,7 +38,9 @@ func NewSynScanner(s *session.Session) *SynScanner {
|
||||||
ss.AddHandler(session.NewModuleHandler("syn.scan IP-RANGE START-PORT END-PORT", "syn.scan ([^\\s]+) (\\d+)([\\s\\d]*)",
|
ss.AddHandler(session.NewModuleHandler("syn.scan IP-RANGE START-PORT END-PORT", "syn.scan ([^\\s]+) (\\d+)([\\s\\d]*)",
|
||||||
"Perform a syn port scanning against an IP address within the provided ports range.",
|
"Perform a syn port scanning against an IP address within the provided ports range.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
var err error
|
if ss.Running() == true {
|
||||||
|
return fmt.Errorf("A scan is already running, wait for it to end before starting a new one.")
|
||||||
|
}
|
||||||
|
|
||||||
list, err := iprange.Parse(args[0])
|
list, err := iprange.Parse(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -176,34 +177,15 @@ func (s *SynScanner) onPacket(pkt gopacket.Packet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if host != nil {
|
if host != nil {
|
||||||
sports := strings.Split(host.Meta.Get("tcp-ports").(string), ",")
|
ports := host.Meta.GetIntsWith("tcp-ports", port, true)
|
||||||
ports := []int{port}
|
host.Meta.SetInts("tcp-ports", ports)
|
||||||
|
|
||||||
for _, s := range sports {
|
|
||||||
n, err := strconv.Atoi(s)
|
|
||||||
if err == nil {
|
|
||||||
ports = append(ports, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ports = core.UniqueInts(ports, true)
|
|
||||||
list := make([]string, len(ports))
|
|
||||||
for i, p := range ports {
|
|
||||||
list[i] = fmt.Sprintf("%d", p)
|
|
||||||
}
|
|
||||||
|
|
||||||
host.Meta.Set("tcp-ports", strings.Join(list, ","))
|
|
||||||
|
|
||||||
NewSynScanEvent(host, port).Push()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NewSynScanEvent(from, host, port).Push()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SynScanner) synScan() error {
|
func (s *SynScanner) synScan() error {
|
||||||
if s.Running() == true {
|
|
||||||
return fmt.Errorf("A scan is already running, wait for it to end before starting a new one.")
|
|
||||||
}
|
|
||||||
|
|
||||||
s.SetRunning(true, func() {
|
s.SetRunning(true, func() {
|
||||||
defer s.SetRunning(false, nil)
|
defer s.SetRunning(false, nil)
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type SynScanEvent struct {
|
type SynScanEvent struct {
|
||||||
Host *network.Endpoint
|
Address string
|
||||||
Port int
|
Host *network.Endpoint
|
||||||
|
Port int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSynScanEvent(h *network.Endpoint, port int) SynScanEvent {
|
func NewSynScanEvent(address string, h *network.Endpoint, port int) SynScanEvent {
|
||||||
return SynScanEvent{
|
return SynScanEvent{
|
||||||
Host: h,
|
Address: address,
|
||||||
Port: port,
|
Host: h,
|
||||||
|
Port: port,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,12 @@ package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/evilsocket/bettercap-ng/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
|
@ -43,6 +48,29 @@ func (m *Meta) Get(name string) interface{} {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Meta) GetIntsWith(name string, with int, sorted bool) []int {
|
||||||
|
sints := strings.Split(m.Get(name).(string), ",")
|
||||||
|
ints := []int{with}
|
||||||
|
|
||||||
|
for _, s := range sints {
|
||||||
|
n, err := strconv.Atoi(s)
|
||||||
|
if err == nil {
|
||||||
|
ints = append(ints, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return core.UniqueInts(ints, sorted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Meta) SetInts(name string, ints []int) {
|
||||||
|
list := make([]string, len(ints))
|
||||||
|
for i, n := range ints {
|
||||||
|
list[i] = fmt.Sprintf("%d", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Set(name, strings.Join(list, ","))
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Meta) GetOr(name string, dflt interface{}) interface{} {
|
func (m *Meta) GetOr(name string, dflt interface{}) interface{} {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue