Sfoglia il codice sorgente

workaround für design-bestseller.de: vhost als remote zulassen, da deren Apache Log Format etwas anders ist

Tobias von Dewitz 5 anni fa
parent
commit
f1e3702510
2 ha cambiato i file con 22 aggiunte e 3 eliminazioni
  1. 18 3
      apache.go
  2. 4 0
      main.go

+ 18 - 3
apache.go

@@ -3,6 +3,7 @@ package main
 import (
 	"bufio"
 	"log"
+	"net"
 	"os"
 	"strings"
 	"time"
@@ -57,10 +58,15 @@ func apacheLogReplay(logfile string) {
 			time.Sleep(ts.Sub(time.Now()))
 		}
 
-		// fmt.Println(l)
+		//pretty.Println(logEntry)
 		remote := logEntry.Host
-		if logEntry.VirtualHost != "" {
-			remote = logEntry.VirtualHost
+
+		if logEntry.VirtualHost != "" && config.UseVhostAsSource {
+			logEntry.VirtualHost = logEntry.VirtualHost[0:strings.Index(logEntry.VirtualHost, ",")]
+			vhIP := net.ParseIP(logEntry.VirtualHost)
+			if vhIP != nil {
+				remote = logEntry.VirtualHost
+			}
 		}
 		if *useXForwardedAsSource && logEntry.ForwardedFor != "" {
 			remote = logEntry.ForwardedFor
@@ -77,6 +83,7 @@ func apacheLogReplay(logfile string) {
 		if vhost != "" {
 			vhostAndPort := strings.Split(logEntry.VirtualHost, ":")
 			virtualHost = vhostAndPort[0]
+
 		} else {
 			if config.HostName != "" {
 				vhost = config.HostName
@@ -165,6 +172,14 @@ func apacheLogCapture(logfile string) {
 		if vhost != "" {
 			vhostAndPort := strings.Split(logEntry.VirtualHost, ":")
 			virtualHost = vhostAndPort[0]
+
+			if config.UseVhostAsSource {
+				virtualHost = virtualHost[0:strings.Index(virtualHost, ",")]
+				vhIP := net.ParseIP(virtualHost)
+				if vhIP != nil {
+					remote = virtualHost
+				}
+			}
 		} else {
 			if config.HostName != "" {
 				vhost = config.HostName

+ 4 - 0
main.go

@@ -46,6 +46,7 @@ var (
 	requestsFile          = flag.String("requests", "", "CSV file containing requests (IP and URL)")
 	protocol              = flag.String("protocol", "http", "which protocol to parse: http or ajp13")
 	useXForwardedAsSource = flag.Bool("use-x-forwarded", false, "Use the IP address in X-Forwarded-For as source")
+	useVhostAsSource      = flag.Bool("use-vhost-as-source", false, "Use the Vhost as source")
 	trace                 = flag.Bool("trace", false, "Trace the packet capturing")
 	apacheLog             = flag.String("apache-log", "", "Parse an Apache Log file")
 	apacheReplay          = flag.String("apache-replay", "", "Apache log file to replay into the system")
@@ -92,6 +93,7 @@ type Config struct {
 	SleepFor              duration
 	RequestsFile          string
 	UseXForwardedAsSource bool
+	UseVhostAsSource      bool
 	Quiet                 bool
 	Protocol              string
 	Trace                 bool
@@ -139,6 +141,7 @@ func (c Config) print() {
 	fmt.Printf("HostName:              %s\n", c.HostName)
 	fmt.Printf("AccessWatchKey:        %s\n", c.AccessWatchKey)
 	fmt.Printf("UseXForwardedAsSource: %t\n", c.UseXForwardedAsSource)
+	fmt.Printf("UseVhostAsSource:      %t\n", c.UseVhostAsSource)
 	fmt.Printf("Protocol:              %s\n", c.Protocol)
 	fmt.Printf("Reset Live Cap After:  %s\n", c.ResetLiveCaptureAfter.String())
 	fmt.Printf("RPCAddress:            %s\n", c.RPCAddress)
@@ -769,6 +772,7 @@ func loadConfig() {
 	config.SleepFor.Duration = *sleepFor
 	config.RequestsFile = *requestsFile
 	config.UseXForwardedAsSource = *useXForwardedAsSource
+	config.UseVhostAsSource = *useVhostAsSource
 	config.Protocol = *protocol
 	config.ApacheLog = *apacheLog
 	config.ApacheReplay = *apacheReplay