Commit: 17427f5796d68ee092e0de9f886c9ad8ea1c4151 Parent: 6550af1b2f12d5c0870c067710d4cca4c43f62a6 Author: Vi Grey Date: 2023-11-21 07:18 UTC Summary: Reduce complexity by removing --host flag * Force localhost listen instead of allowing external listening for simplicity and security's sake * Add text during gen-polyglot.sh build process to let the user know what is going on at what order, especially to make the zip message a little less intense 31.txt | 14 ++++++------ gopher-server/gen-polyglot.sh | 6 ++++-- gopher-server/gopher-server.go | 93 ++++++++++++++++++++++++++++++++++--------------------------------------------- 3 files changed, 51 insertions(+), 62 deletions(-) diff --git a/31.txt b/31.txt index 26cd37b..15f0edf 100644 --- a/31.txt +++ b/31.txt @@ -44,13 +44,13 @@ gopher://localhost:2311 (2311 was chosen because this zine issue's release date is in 2023-11) which can be visited with your gopher client of choice. -If you want to use a different address or different port, you can use -the flag options --host and --port , for instance -`--host mappedhost --port 9070` if you wanted the gopherhole to listen -at gopher://mappedhost:9070 instead of gopher:localhost:2311. You can -also specify a ZIP file instead of using the executable as the ZIP file -by using the --zip flag option, for instance `--zip test.zip` if -you want the gopherhole to serve content from test.zip. +If you want to use a different port, you can use the --port flag +option. For instance, `--port 9070` would be used if you want the +gopherhole to listen at gopher://localhost:9070 instead of +gopher://localhost:2311. You can also specify a ZIP file instead of +using the executable as the ZIP file by using the --zip flag +option, for instance `--zip test.zip` if you want the gopherhole to +serve content from test.zip. If you want to make the ZIP file of this issue a Gopher server for your system, I have included the gopher-server source code and a shell diff --git a/gopher-server/gen-polyglot.sh b/gopher-server/gen-polyglot.sh index 955d5d0..311a03a 100755 --- a/gopher-server/gen-polyglot.sh +++ b/gopher-server/gen-polyglot.sh @@ -29,11 +29,13 @@ else # Build the gopher server executable # Concatenate executable with ZIP file to make polyglot file # Realign offsets of ZIP file so ZIP file works again - echo "Building for gopher-server for $goos/$goarch" && \ + echo "[ Building for gopher-server for $goos/$goarch ]" && \ GOOS="$goos" GOARCH="$goarch" go build -ldflags="-s -w" -o "./gopher-server" && \ + echo "[ Concatenating gopher-server and $1 ]" && \ cat "./gopher-server" "$1" > "cat.zip" && \ + echo "[ Realigning ZIP file offsets of poyglot file ]" && \ zip -F "cat.zip" --out "gopher-server-zip-polyglot.zip" && \ - echo "gopher-server-zip-polyglot.zip Created for $goos/$goarch." && \ + echo "gopher-server-zip-polyglot.zip created for $goos/$goarch!" && \ echo "You can make gopher-server-zip-polyglot.zip executable with:" && \ echo " chmod +x gopher-server-zip-polyglot.zip" echo "You can delete cat.zip." diff --git a/gopher-server/gopher-server.go b/gopher-server/gopher-server.go index 654d308..347b847 100644 --- a/gopher-server/gopher-server.go +++ b/gopher-server/gopher-server.go @@ -37,45 +37,45 @@ import ( const ( DEFAULT_CONTENT = `itmp.0ut #003 - 2023-11 fake 0 i fake 0 -001 Intro ~ t0 /txt/1.txt {ADDR} {PORT} -002 Second Part To Hell Interview ~ t0 /txt/2.txt {ADDR} {PORT} -003 UNIX VIRUSES 25th Anniversary ~ silvio /txt/3.txt {ADDR} {PORT} -004 Hijacking __cxa_finalize to achieve entry point obscuring ~ vrzh /txt/4.txt {ADDR} {PORT} -005 Linux.ElizaCanFix.asm ~ vrzh /txt/5.txt {ADDR} {PORT} -006 Concealing Namespaces Within a File Descriptor ~ Fanda Uchytil /txt/Linux.ElizaCanFix.asm {ADDR} {PORT} -007 Dumping libc memory space to bypass ASLR ~ jonaslyk /txt/7.txt {ADDR} {PORT} -008 ARM32 ELF Sizecoding ~ deater /txt/8.txt {ADDR} {PORT} -009 A Silver Bullet To ELF Projects ~ echel0n /txt/9.txt {ADDR} {PORT} -010 in-memory-only fd-less ELF execution (with Perl) ~ isra /txt/10.txt {ADDR} {PORT} -011 isra_exec_elf64.pl ~ isra /txt/isra_exec_elf64.pl {ADDR} {PORT} -012 u used 2 call me on my polymorphic shell phone ~ ic3qu33n /txt/12.txt {ADDR} {PORT} -013 Weird ELFs, or a tale of breaking parsers once again ~ g1inko /txt/13.txt {ADDR} {PORT} -014 inspect0rGadget.asm - x64 ROP Gadget Finder ~ s01den /txt/14.txt {ADDR} {PORT} -015 Reverse Text Disinfector ~ qkumba /txt/15.test-1.c {ADDR} {PORT} -016 RE of Linux.Nasty.asm ~ qkumba /txt/16.txt {ADDR} {PORT} -017 Linux.Anansi.c ~ sad0p /txt/Linux.Anansi.c {ADDR} {PORT} -018 Linux.Slinger.asm ~ lvti /txt/Linux.Slinger.asm {ADDR} {PORT} -019 LKM Golf ~ rqu & netspooky /txt/19.txt {ADDR} {PORT} -020 easylkb: Easy Linux Kernel Builder ~ ackmage & netspooky /txt/20.txt {ADDR} {PORT} -021 23 Open Problems for Digital Self-Replicators ~ Second Part To Hell /txt/21.txt {ADDR} {PORT} -022 Cramming a Tiny Program into a Tiny ELF File: A Case Study ~ lm978 /txt/22.txt {ADDR} {PORT} -023 silent syscall hooking on arm64 linux by patching svc handler ~ wintermute /txt/23.txt {ADDR} {PORT} -024 HVice - HyperVisor intrusion countermeasure electronics ~ wintermute /txt/24.txt {ADDR} {PORT} -025 BGGP4 Recap ~ Binary Golf Association /txt/25.txt {ADDR} {PORT} -026 LLMorpher ~ Second Part To Hell /txt/26.txt {ADDR} {PORT} -027 QRLog Malware Analysis ~ mauro /txt/27.txt {ADDR} {PORT} -028 HandJar.B ~ r3s1stanc3 /txt/28.txt {ADDR} {PORT} -029 ClassWar ~ r3s1stanc3 /txt/29.txt {ADDR} {PORT} -030 linkin.pl ~ isra /txt/linkin.pl {ADDR} {PORT} -031 Long Live Gopher! This Zine Is Also A Gopher Server ~ Vi Grey /txt/31.txt {ADDR} {PORT} +001 Intro ~ t0 /txt/1.txt localhost {PORT} +002 Second Part To Hell Interview ~ t0 /txt/2.txt localhost {PORT} +003 UNIX VIRUSES 25th Anniversary ~ silvio /txt/3.txt localhost {PORT} +004 Hijacking __cxa_finalize to achieve entry point obscuring ~ vrzh /txt/4.txt localhost {PORT} +005 Linux.ElizaCanFix.asm ~ vrzh /txt/5.txt localhost {PORT} +006 Concealing Namespaces Within a File Descriptor ~ Fanda Uchytil /txt/Linux.ElizaCanFix.asm localhost {PORT} +007 Dumping libc memory space to bypass ASLR ~ jonaslyk /txt/7.txt localhost {PORT} +008 ARM32 ELF Sizecoding ~ deater /txt/8.txt localhost {PORT} +009 A Silver Bullet To ELF Projects ~ echel0n /txt/9.txt localhost {PORT} +010 in-memory-only fd-less ELF execution (with Perl) ~ isra /txt/10.txt localhost {PORT} +011 isra_exec_elf64.pl ~ isra /txt/isra_exec_elf64.pl localhost {PORT} +012 u used 2 call me on my polymorphic shell phone ~ ic3qu33n /txt/12.txt localhost {PORT} +013 Weird ELFs, or a tale of breaking parsers once again ~ g1inko /txt/13.txt localhost {PORT} +014 inspect0rGadget.asm - x64 ROP Gadget Finder ~ s01den /txt/14.txt localhost {PORT} +015 Reverse Text Disinfector ~ qkumba /txt/15.test-1.c localhost {PORT} +016 RE of Linux.Nasty.asm ~ qkumba /txt/16.txt localhost {PORT} +017 Linux.Anansi.c ~ sad0p /txt/Linux.Anansi.c localhost {PORT} +018 Linux.Slinger.asm ~ lvti /txt/Linux.Slinger.asm localhost {PORT} +019 LKM Golf ~ rqu & netspooky /txt/19.txt localhost {PORT} +020 easylkb: Easy Linux Kernel Builder ~ ackmage & netspooky /txt/20.txt localhost {PORT} +021 23 Open Problems for Digital Self-Replicators ~ Second Part To Hell /txt/21.txt localhost {PORT} +022 Cramming a Tiny Program into a Tiny ELF File: A Case Study ~ lm978 /txt/22.txt localhost {PORT} +023 silent syscall hooking on arm64 linux by patching svc handler ~ wintermute /txt/23.txt localhost {PORT} +024 HVice - HyperVisor intrusion countermeasure electronics ~ wintermute /txt/24.txt localhost {PORT} +025 BGGP4 Recap ~ Binary Golf Association /txt/25.txt localhost {PORT} +026 LLMorpher ~ Second Part To Hell /txt/26.txt localhost {PORT} +027 QRLog Malware Analysis ~ mauro /txt/27.txt localhost {PORT} +028 HandJar.B ~ r3s1stanc3 /txt/28.txt localhost {PORT} +029 ClassWar ~ r3s1stanc3 /txt/29.txt localhost {PORT} +030 linkin.pl ~ isra /txt/linkin.pl localhost {PORT} +031 Long Live Gopher! This Zine Is Also A Gopher Server ~ Vi Grey /txt/31.txt localhost {PORT} i fake 0 iFor the html version of this zine, please visit fake 0 hhttps://tmpout.sh/3/ URL:https://tmpout.sh/3/ fake 0` + HOST = "localhost" ) var ( port = 2311 - host = "localhost" zipFlag bool zipFilePath string zipReader *zip.ReadCloser @@ -124,7 +124,7 @@ func sendGeneratedGophermap(reqPath string, conn net.Conn) { itemType = "1" p = filepath.Join(p) + "/" conn.Write([]byte(fmt.Sprintf("1%s\t%s\t%s\t%d\r\n", - filepath.Join(p)+"/", filename, host, port))) + filepath.Join(p)+"/", filename, HOST, port))) case strings.Contains(mimeType, "image/"): // Path is an image if strings.Contains(mimeType, "image/gif") { @@ -138,7 +138,7 @@ func sendGeneratedGophermap(reqPath string, conn net.Conn) { } // so line is txt file line conn.Write([]byte(fmt.Sprintf("%s%s\t%s\t%s\t%d\r\n", - itemType, p, filename, host, port))) + itemType, p, filename, HOST, port))) } } } @@ -166,12 +166,9 @@ func handleGopherConnection(conn net.Conn) { // reqPath is the root gophermap if !zipFlag { // zipFlag was not specified, so should be polyglot ZIP - // Replace {PORT} and {ADDR} of DEFAULT_CONTENT to specified - // values + // Replace {PORT} of DEFAULT_CONTENT to specified value gophermap := strings.Replace(DEFAULT_CONTENT, "{PORT}", strconv.Itoa(port), -1) - gophermap = strings.Replace(gophermap, "{ADDR}", - host, -1) conn.Write([]byte(gophermap)) conn.Write([]byte("\r\n.\r\n")) return @@ -210,11 +207,9 @@ func handleGopherConnection(conn net.Conn) { conn.Write([]byte("3Invalid Request\tfake\tfake\t0\r\n.\r\n")) } -// Start the gopher server at specified host and port (default -// localhost:2311) +// Start listening with the gopher server at specified port (default: 2311) func startGopherServer() { - listener, err := net.Listen("tcp", - fmt.Sprintf("%s:%d", host, port)) + listener, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port)) handleErr(err) for { if conn, err := listener.Accept(); err == nil { @@ -234,8 +229,6 @@ func displayHelp() { Options: -h, --help Print Help (this message) and exit - --host TCP address for gopher server to listen on - (default: "localhost") --port TCP port to listen on (default: 2311) --zip Path to ZIP file that hosts the content (default: this executable file itself) @@ -275,18 +268,12 @@ func init() { handleErr(err) args := os.Args[1:] argsLen := len(args) - // Flag checking (--host, -h, --help, --port, and --zip) + // Flag checking (-h, --help, --port, and --zip) for x := 0; x < argsLen; x++ { switch strings.ToLower(args[x]) { case "-h", "--help": displayHelp() os.Exit(0) - case "--host": - // User specified TCP listening address - hostVal, err := getFlagStrValue(args, x, argsLen) - x++ - handleErr(err) - host = hostVal case "--port": // User specified TCP listening port portVal, err := getFlagPortValue(args, x, argsLen) @@ -307,7 +294,7 @@ func init() { func main() { getZIPFileReader() defer zipReader.Close() - fmt.Printf("Starting Gopherhole at gopher://%s:%d\n", - host, port) + fmt.Printf("Starting Gopherhole at gopher://localhost:%d\n", + port) startGopherServer() }