SHARE
TWEET

tarpit.go

a guest Jan 24th, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "log"
  5.     "net"
  6. )
  7.  
  8. // "Handle" the connection. Note: The connection is never actually closed; it just remains open forever.
  9. func handle(c net.Conn) {
  10.     b := make([]byte, 1024)
  11.     log.Printf("connection accepted from %s ", c.RemoteAddr())
  12.  
  13.     for {
  14.         // Consume all the content from the connection
  15.         _, err := c.Read(b)
  16.  
  17.         if err != nil {
  18.             log.Printf("error: %s", err.Error())
  19.  
  20.             return
  21.         }
  22.  
  23.         // Print the contnet
  24.         log.Printf("%s", b)
  25.     }
  26. }
  27.  
  28. // A dumb sinkhole.
  29. //
  30. // Works by just accepting the TCP connection but neither closing nor responding to it.
  31. //
  32. // Implemented by stubbing out the DNS server, responding with the machine running this
  33. // service .
  34. func main() {
  35.     ln, err := net.Listen("tcp", ":443")
  36.     if err != nil {
  37.         panic(err)
  38.     }
  39.  
  40.     for {
  41.         c, err := ln.Accept()
  42.  
  43.         if err != nil {
  44.             panic(err)
  45.         }
  46.  
  47.         go handle(c)
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top