mirror of
https://github.com/lunchcat/sif.git
synced 2026-01-13 13:27:30 -08:00
- golang.org/x/crypto v0.26.0 -> v0.46.0 (critical: ssh auth bypass) - golang.org/x/net v0.28.0 -> v0.48.0 (medium: xss vulnerability) - golang.org/x/oauth2 v0.11.0 -> v0.34.0 (high: input validation) - quic-go v0.48.2 -> v0.58.0 (high: panic on undecryptable packets) - golang-jwt/jwt v4.5.1 -> v4.5.2 (high: memory allocation) - cloudflare/circl v1.3.7 -> v1.6.2 (low: validation issues) - refraction-networking/utls v1.5.4 -> v1.8.1 (medium: tls downgrade) - ulikunitz/xz v0.5.11 -> v0.5.15 (medium: memory leak) - klauspost/compress v1.16.7 -> v1.17.4 also fixes go vet warnings for non-constant format strings
107 lines
3.3 KiB
Go
107 lines
3.3 KiB
Go
/*
|
|
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
|
|
: :
|
|
: █▀ █ █▀▀ · Blazing-fast pentesting suite :
|
|
: ▄█ █ █▀ · BSD 3-Clause License :
|
|
: :
|
|
: (c) 2022-2025 vmfunc (Celeste Hickenlooper), xyzeva, :
|
|
: lunchcat alumni & contributors :
|
|
: :
|
|
·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━·
|
|
*/
|
|
|
|
package scan
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/charmbracelet/log"
|
|
"github.com/dropalldatabases/sif/internal/styles"
|
|
"github.com/dropalldatabases/sif/pkg/logger"
|
|
)
|
|
|
|
const commonPorts = "https://raw.githubusercontent.com/dropalldatabases/sif-runtime/main/ports/top-ports.txt"
|
|
|
|
func Ports(scope string, url string, timeout time.Duration, threads int, logdir string) ([]string, error) {
|
|
log.Printf("%s", styles.Separator.Render("🚪 Starting "+styles.Status.Render("port scanning")+"..."))
|
|
|
|
sanitizedURL := strings.Split(url, "://")[1]
|
|
if logdir != "" {
|
|
if err := logger.WriteHeader(sanitizedURL, logdir, scope+" port scanning"); err != nil {
|
|
log.Errorf("Error creating log file: %v", err)
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
portlog := log.NewWithOptions(os.Stderr, log.Options{
|
|
Prefix: "Ports 🚪",
|
|
})
|
|
|
|
portlog.Infof("Starting %s port scanning", scope)
|
|
|
|
var ports []int
|
|
switch scope {
|
|
case "common":
|
|
resp, err := http.Get(commonPorts)
|
|
if err != nil {
|
|
log.Errorf("Error downloading ports list: %s", err)
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
scanner := bufio.NewScanner(resp.Body)
|
|
scanner.Split(bufio.ScanLines)
|
|
for scanner.Scan() {
|
|
if port, err := strconv.Atoi(scanner.Text()); err == nil {
|
|
ports = append(ports, port)
|
|
}
|
|
}
|
|
case "full":
|
|
ports = make([]int, 65536)
|
|
for i := range ports {
|
|
ports[i] = i
|
|
}
|
|
}
|
|
|
|
var openPorts []string
|
|
var wg sync.WaitGroup
|
|
wg.Add(threads)
|
|
for thread := 0; thread < threads; thread++ {
|
|
go func(thread int) {
|
|
defer wg.Done()
|
|
|
|
for i, port := range ports {
|
|
if i%threads != thread {
|
|
continue
|
|
}
|
|
|
|
log.Debugf("Looking up: %d", port)
|
|
tcp, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", sanitizedURL, port), timeout)
|
|
if err != nil {
|
|
log.Debugf("Error %d: %v", port, err)
|
|
} else {
|
|
openPorts = append(openPorts, strconv.Itoa(port))
|
|
portlog.Infof("%s %s:%s", styles.Status.Render("[tcp]"), sanitizedURL, styles.Highlight.Render(strconv.Itoa(port)))
|
|
tcp.Close()
|
|
}
|
|
}
|
|
}(thread)
|
|
}
|
|
wg.Wait()
|
|
|
|
if len(openPorts) > 0 {
|
|
portlog.Infof("Found %d open ports: %s", len(openPorts), strings.Join(openPorts, ", "))
|
|
} else {
|
|
portlog.Error("Found no open ports")
|
|
}
|
|
|
|
return openPorts, nil
|
|
}
|