Last active
May 9, 2016 17:09
-
-
Save mrtc0/1b643de7a2aa4f69eb2eccf63a62044d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
if scanner.Text() == "plz flag" { | |
fmt.Println("flag{xxx}") | |
return | |
} | |
fmt.Println(scanner.Text()) | |
} | |
if err := scanner.Err(); err != nil { | |
fmt.Fprintln(os.Stderr, "reading standard input:", err) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"log" | |
"net" | |
"strconv" | |
) | |
const PORT = 12345 | |
func main() { | |
server, err := net.Listen("tcp", ":"+strconv.Itoa(PORT)) | |
if server == nil { | |
log.Fatal(err) | |
} | |
conns := clientConns(server) | |
for { | |
go handleConn(<-conns) | |
} | |
} | |
func clientConns(listener net.Listener) chan net.Conn { | |
ch := make(chan net.Conn) | |
i := 0 | |
go func() { | |
for { | |
client, err := listener.Accept() | |
if client == nil { | |
log.Fatal(err) | |
continue | |
} | |
i++ | |
fmt.Printf("%d: %v <-> %v\n", i, client.LocalAddr(), client.RemoteAddr()) | |
ch <- client | |
} | |
}() | |
return ch | |
} | |
func handleConn(client net.Conn) { | |
flag := []byte("flag{xxx}") | |
b := bufio.NewReader(client) | |
for { | |
line, err := b.ReadBytes('\n') | |
if string(line) == "plz flag\n" { | |
client.Write(flag) | |
continue | |
} | |
if err != nil { // EOF, or worse | |
break | |
} | |
client.Write(line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment