mosers
/
eaas-vde-proxy
Archiviert
1
0
Fork 0

Start passthrough proxies automatically [Close #14]

main
Simon Moser vor 3 Jahren
Ursprung a3d950ebbc
Commit 4eca9d5ce8
Signiert von: mosers
GPG-Schlüssel-ID: 96B3365A234B500C

@ -10,6 +10,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io" "io"
"net" "net"
"os"
"proxy/cmd" "proxy/cmd"
"proxy/util" "proxy/util"
"time" "time"
@ -30,6 +31,8 @@ func main() {
newmac := flag.String("newmac", "52:54:00:12:34:aa", "MAC after change") newmac := flag.String("newmac", "52:54:00:12:34:aa", "MAC after change")
passthrough := flag.Bool("passthrough", false, "Whether to pass every traffic through") passthrough := flag.Bool("passthrough", false, "Whether to pass every traffic through")
proxy := flag.String("proxy", "1", "Number of the proxy switch") proxy := flag.String("proxy", "1", "Number of the proxy switch")
pidfile := flag.String("pidfile", "", "Location to write the pid to")
logfile := flag.String("logfile", "", "Location to write output to")
flag.Parse() flag.Parse()
log.SetLevel(log.Level(*logLvl)) log.SetLevel(log.Level(*logLvl))
OldMac, _ = net.ParseMAC(*oldmac) OldMac, _ = net.ParseMAC(*oldmac)
@ -39,6 +42,14 @@ func main() {
log.SetFormatter(&log.TextFormatter{ log.SetFormatter(&log.TextFormatter{
DisableTimestamp: true, DisableTimestamp: true,
}) })
if *logfile != "" {
if f, err := os.OpenFile(*logfile, os.O_WRONLY | os.O_CREATE, 0755); err != nil {
log.Error("Error opening logfile ", *logfile)
} else {
log.SetOutput(f)
}
}
util.WritePIDFile(*pidfile)
c1 := cmd.New("vde_plug", "/run/vde/sw_main.sock") c1 := cmd.New("vde_plug", "/run/vde/sw_main.sock")
c2 := cmd.New("vde_plug", "/run/vde/sw_proxy"+*proxy+".sock") c2 := cmd.New("vde_plug", "/run/vde/sw_proxy"+*proxy+".sock")
c1.Execute() c1.Execute()

Binäre Datei nicht angezeigt.

@ -7,6 +7,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv"
) )
// WritePcap writes the provided data to a given pcap file // WritePcap writes the provided data to a given pcap file
@ -32,3 +33,12 @@ func WriteBinary(file string, data []byte) {
log.Errorf("Error writing binary file %s", file) log.Errorf("Error writing binary file %s", file)
} }
} }
func WritePIDFile(filename string) {
if filename == "" {
return
}
if err := ioutil.WriteFile(filename, []byte(strconv.Itoa(os.Getpid())), 0644); err != nil {
log.Errorf("Error writing PID file %s", filename)
}
}

@ -2,6 +2,7 @@
# QEMU/VDE network environment preparation script # QEMU/VDE network environment preparation script
RUN='/run/vde' RUN='/run/vde'
qemu=/opt/qemu/build/qemu-system-x86_64 qemu=/opt/qemu/build/qemu-system-x86_64
proxy=`dirname "$(readlink -f "$0")"`/../proxy/proxy
# PID identifiers # PID identifiers
all="$RUN/*.pid" all="$RUN/*.pid"
@ -11,6 +12,9 @@ alpine="$RUN/vm_alpine_*.pid"
alpine1="$RUN/vm_alpine_1.pid" alpine1="$RUN/vm_alpine_1.pid"
alpine2="$RUN/vm_alpine_2.pid" alpine2="$RUN/vm_alpine_2.pid"
kali="$RUN/vm_kali.pid" kali="$RUN/vm_kali.pid"
proxy2="$RUN/proxy_2.pid"
proxy3="$RUN/proxy_3.pid"
proxies="$RUN/proxy_*.pid"
case "$1" in case "$1" in
@ -26,13 +30,19 @@ start)
slirpvde -D -H 10.0.0.2 --daemon -s $RUN/sw_main.sock -p $RUN/net_slirp.pid slirpvde -D -H 10.0.0.2 --daemon -s $RUN/sw_main.sock -p $RUN/net_slirp.pid
;;& ;;&
alpine1 | alpine | vms | all) alpine1 | alpine | vms | all)
$qemu -m 512 -nic vde,mac='52:54:00:12:34:56',sock=$RUN/sw_proxy1.sock -hda alpine1.qcow2 -daemonize -vnc :1 -pidfile $RUN/vm_alpine_1.pid $qemu -m 512 -nic vde,mac='52:54:00:12:34:56',sock=$RUN/sw_proxy1.sock -hda alpine1.qcow2 -daemonize -vnc :1 -pidfile $alpine1
;;& ;;&
alpine2 | alpine | vms | all) alpine2 | alpine | vms | all)
$qemu -m 512 -nic vde,mac='52:54:00:12:34:66',sock=$RUN/sw_proxy2.sock -hda alpine2.qcow2 -daemonize -vnc :2 -pidfile $RUN/vm_alpine_2.pid $qemu -m 512 -nic vde,mac='52:54:00:12:34:66',sock=$RUN/sw_proxy2.sock -hda alpine2.qcow2 -daemonize -vnc :2 -pidfile $alpine2
;;& ;;&
kali | vms | all) kali | vms | all)
$qemu -m 1024 -nic user -nic vde,mac='52:54:00:12:34:76',sock=$RUN/sw_proxy3.sock -hda kali.qcow2 -daemonize -vnc :3 -pidfile $RUN/vm_kali.pid $qemu -m 1024 -nic user -nic vde,mac='52:54:00:12:34:76',sock=$RUN/sw_proxy3.sock -hda kali.qcow2 -daemonize -vnc :3 -pidfile $kali
;;&
proxy2 | proxies | all)
$proxy -proxy 2 -passthrough -logfile $RUN/proxy_2.log -pidfile $proxy2 &
;;&
proxy3 | proxies | all)
$proxy -proxy 3 -passthrough -logfile $RUN/proxy_3.log -pidfile $proxy3 &
;; ;;
*) *)
echo "Usage: envctl start {all|network|vms|alpine|alpine1|alpine2|kali}" echo "Usage: envctl start {all|network|vms|alpine|alpine1|alpine2|kali}"