Source code and details: https://github.com/umutcamliyurt/PortTripper

How it works

On startup PortTripper:

  1. Scans the configured port range and builds a whitelist of ports already in use by real services (first run only).
  2. Draws a cryptographically random sample of up to -maxports ports from the range, excluding whitelisted ports. Using crypto/rand for selection means the open set is unpredictable to an attacker even if they know the configured range.
  3. Binds TCP and UDP listeners on every chosen port.
  4. On TCP: accepts connections, holds them open for a configurable duration, then drops them, wasting the scanner’s threads and file descriptors.
  5. On UDP: reads and discards datagrams without replying, so ports appear open|filtered to scanners rather than closed.

All real service ports are untouched because they are already bound before PortTripper starts, and the auto-generated whitelist tells PortTripper to skip them.

  • Jerry on PieFed@feddit.online
    link
    fedilink
    English
    arrow-up
    26
    ·
    edit-2
    2 days ago

    Things like this that play games scare me. This itself opens a wider attack vector on your server. I’m thinking of possibilities:

    1. In Linux, each TCP connection is a file descriptor. PortTripper holds connections to waste scanner threads, which means it’s holding file descriptors. This could be a good DDOS attack vector. Hit every port with connection requests, requiring a slew of file descriptor creations, and boom, you cause the server to hit the server ulimit cap. New connections cannot be made. The server is half dead.

    2. Memory and CPU consumption. Maintaining thousands of open TCP states takes RAM and CPU. A massive flood can consume all memory. And for what? To annoy a hacker?

    Interestingly enough, just these 2 things can make PortTripper a hacker’s tool.

    1. If a service crashes or reboots, is down for maintenance, or is slow to come up, PortTripper might grab the port before the application comes back up. And then it can’t come back up.

    2. Who’s to say there won’t be vulnerabilities in PortTripper that can cause a buffer overflow, memory leak, or parsing vulnerability in PortTripper’s code or a library it uses? Playing this game opens another attack vector into your server.

    3. If PortTripper can bind to ports 1 through 1023, then it’s running as root or has elevated capabilities. If an attacker exploits a bug in PortTripper or a library it uses, they can get high-level control of the server.

    4. While PortTripper “discards datagrams without replying” in a reflected DDOS attack, millions of discarded packets come in, which means millions of CPU interrupts at the kernel level. This can choke the NIC.

    I think PortTripper is too risky to run just to become a nuisance to someone, IMHO.

    • mic_check_one_two@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      3
      ·
      edit-2
      1 day ago

      Also, unless I’m fundamentally misunderstanding the purpose of this… Wouldn’t this be completely irrelevant if you’re running a reverse proxy anyways? You only need to worry about port mapping if you’re running open ports. But ports 80 and 443 are reserved for http and https traffic, so they’re functionally useless for a potential attacker looking to map your running services.

      Basically, this only “protects” you if you have open ports? Just don’t open ports to begin with. Use a reverse proxy.

      The only way I can see this being useful is to protect against LAN traffic, not WAN. But if they’re able to get on your LAN, you’re probably already in the “unplug everything” stage of damage control. Other honeypots would be better equipped to alert you of the port sniffing on your LAN, instead of simply stalling an attacker by eating your own server’s resources.

        • mic_check_one_two@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 day ago

          My point was that this only really helps if they’re already on your LAN. Ports 80 and 443 (the ports your reverse proxy would use) are functionally useless for an attacker to map. And if they’re already on your LAN, there are honeypots that will do better than simply eating server resources to delay (not stop, just delay) an attacker.

          • atzanteol@sh.itjust.works
            link
            fedilink
            English
            arrow-up
            1
            ·
            18 hours ago

            I’m not sure you understand what a “honeypot” is. The entire point is to set it up somewhere public so that people try to scan and connect to it. It doesn’t protect anything. It’s designed to try to slow-down attackers who probe random systems.

            • mic_check_one_two@lemmy.dbzer0.com
              link
              fedilink
              English
              arrow-up
              2
              ·
              16 hours ago

              I’m not sure you understand what a honeypot is. You only listed one kind, and it is arguably the most useless kind. I don’t care about what happens outside of my WAN, because that is what a firewall is for. I only care about what happens inside the firewall. A good honeypot will act as an early warning system for a breach. It is an attractive target for people who are looking to spread to other devices on the network.

              If an attacker gets into your network, the honeypot is designed to act as an attractive target and alert you when it gets hit. I don’t care if people try to scan my WAN ports. Bots do that all the time. It’s basically a given. But with a reverse proxy, you’re only opening ports 80 and 443. Those are basically useless for an attacker, because it only tells them that you’re running something on http and https. And that could be anything.

              If I’m running a honeypot, it’s going to be to alert me if something gets breached. It’s going to run on my LAN, not my WAN. If something on my LAN suddenly starts scanning all of my server’s ports, it’s because that thing is a rogue device/attacker. I’m not interested in stalling them. I want to be automatically alerted and to completely shut them out. That’s what a good honeypot will do. A bad honeypot just wastes time and resources, instead of alerting me to the potential breach.

              • atzanteol@sh.itjust.works
                link
                fedilink
                English
                arrow-up
                1
                ·
                12 hours ago

                But with a reverse proxy, you’re only opening ports 80 and 443. Those are basically useless for an attacker, because it only tells them that you’re running something on http and https. And that could be anything.

                That you seem to think a reverse proxy provides some sort of security is a bit… Terrifying.

                • mic_check_one_two@lemmy.dbzer0.com
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  8 hours ago

                  Nope, it just encrypts your traffic with https to avoid MITM attacks, and allows you to avoid opening more than two ports on your WAN. But if you simply open ports for every service, that’s usually a big easy “I’m running {service}” beacon. If I scan your WAN IP and find port 32400 open, I can make a reasonably safe bet that you’re running plex. But ports 80 and 443 won’t tell me anything about which services you’re running, because those are reserved for http and https traffic specifically. So I’d know that you’re running something, but I wouldn’t simply be able to guess which services specifically.

                  Sure, this listed honeypot may be able to help with that by making it appear as if every port is in use. But again, a reverse proxy would accomplish the same thing (without exposing all of your services directly) by simply shrouding all of your services behind 80 and 443.

    • bamboo@lemmy.blahaj.zone
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 day ago

      It’ll probably just be a nuisance for small operations and for larger botnets be a drop in the bucket or not even noticable.

      • SayCyberOnceMore@feddit.uk
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 day ago

        Yeah, I don’t think this would be great on an external boundary with all the internet scanners out there, but maybe in a DMZ it might help as a feed to a boundary blocklist.

        I do see torrent peers trying to scan my network sometimes, so this might be an interesting insight…

    • SayCyberOnceMore@feddit.uk
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 day ago

      I can understand caution before adding something new in case it causes problems, but I think most of your concerns are addressed on the github page.

      I’d prefer this to be written in a compiled language as that would be less likely to fail due to external issues, but I think this would work for someone trying to slow down anyone once they’ve found an open port… and that’s probably the root issue.

      • Jerry on PieFed@feddit.online
        link
        fedilink
        English
        arrow-up
        2
        ·
        22 hours ago

        If successfully attacked and the hacker has elevated rights on your Pi, they are now in your local network and can cause all sorts of grief potentially in the router and on other connected devices.

      • bamboo@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 day ago

        I think what the commenter is saying is if you have something running on a server on an external IP address for like a website that needs to be public, the additional risk of opening up more ports to slow down Internet scanners is not beneficial to you and not worth the risk.

        If you’re deploying an raspberry pi and opening it up to the Internet, and don’t care if it crashes due to overload, thats a bit of effort and cost you incure to keep it running to be a nuisance.for Internet scanners. If you don’t have anything which needs to be publicly accessible to the Internet, the best thing you can do is not open any ports and expend no effort, so that the firewall/ NAT gateway operates in stealth mode which is does inflict some processing and time on the Internet scanner to run waiting for responses to timeout.