CodeX's Terminal Window
  • root@codex
  • 🐙Red Team
    • Red Team OPSEC
      • Initial Recon
      • Weaponization
      • Infrastructure
        • Example Red Team Infra
        • Cobalt Strike Redirectors
        • Using SSH Tunneling to secure C2 infra
      • Phishing
      • Internal Recon
      • Lateral Movement
      • Post-Exploitation
      • Exfiltration
      • Cleanup
    • Red Team TTPs
      • Active Directory
      • Persistence
      • Exfiltration
      • Phishing
      • Windows Bypasses
    • Red Team Dev
      • Extending Havoc C2
        • Third Party Agents
          • 1: Understanding the interface
          • 2: Writing the agent
          • 3: Writing the agent handler
          • 4: Testing the agent
      • Loader Dev
        • In Memory OPSEC
          • PE Structures
          • Memory Permissions and Allocation Types
          • In Memory Signatures
          • Thread Stack
          • Windows Events
          • Userland Hooks
          • AMSI & ETW
        • Evasion Adventures
        • Loader basics
        • Sleep masking
        • Mimikatz vs Windows Defender
        • Indirect syscalls
    • Cobalt Strike
      • Modifying the Sleep Mask Kit
      • Discord Beacon Notifications
      • Evading Hunt-Sleeping-Beacons
      • Beacon Object Files
    • Misc. Interesting Stuff
  • 🛡️Blue Team
    • Detecting Cobalt Strike
      • Sleep Mask Kit IOCs
      • Hunting Beacon in the heap
      • Decrypting C2 traffic with known key
  • 🚩CTF Solutions
    • Cyber Defenders Discovery Camp 2021
      • 👁️‍🗨️Lets Go Hunting
      • 🐧Linux Rules The World!
      • 📻Going active
      • 🗄️File it away
      • 😷Behind the mask
  • Box challenges
    • 📦Box Writeups
  • Me myself and I
    • root@codex #
Powered by GitBook
On this page
  • Why do I need to protect my C2 infra?
  • Securing my teamservers
  1. Red Team
  2. Red Team OPSEC
  3. Infrastructure

Using SSH Tunneling to secure C2 infra

Pesky AV vendors keep scanning my stuff >:C

PreviousCobalt Strike RedirectorsNextPhishing

Last updated 3 years ago

Why do I need to protect my C2 infra?

Because scanner monkeys (and sometimes pesky security vendors) like to scan the internet for certain C2 signatures e.g. Cobalt Strike teamservers and investigate them by trying to access their offensive capabilities such as system profilers and stagers. One such example is who went and started fingerprinting Cobalt Strike teamservers using an anomalous space in NanoHTTPD. Or the time I woke up to this monstrosity:

and this:

User : me *
Computer Name : W7SB64-01
External IP : 184.185.5.53
Internal IP : 172.16.28.12
Arch : x64, @CodeX

Securing my teamservers

Whitelist IP Ranges

Disable Payload staging

SSH Tunneling

This is the response when you try to login to a non Cobalt Strike server with the Cobalt Strike client:

But this is what you get if you try logging into a real teamserver with an incorrect password:

I'm not entirely sure how efficient it would be to fingerprint teamservers this way, but I dont want ANYBODY trying to fingerprint my box as a Cobalt Strike teamserver (maybe because I borrowed this box from a friend, and he really doesnt want his IP to get blacklisted as a teamserver). So, what can I do to prevent login attempts?

All I need to do to login, is create an SSH tunnel from the server to my box with the following command:

ssh user@my.ip.here -L 50050:127.0.0.1:50050

Now everything I send to 127.0.0.1:50050 will actually go to my.ip.here:50050 thanks to that SSH tunnel, so I can login normally with the Cobalt Strike client!

You can further combine this with redirectors to further keep vendors away from your teamserver:

Which according to is Comodo messing with my beacons >:C

The most simple way to prevent random stuff from getting to my teamserver was to whitelist IP ranges I expected traffic to come from. So normally I would whitelist the IP ranges of say, a country or state I expected some callbacks to come from. That way, if random security vendors (Or ) start masscanning the internet, my IP won't even be contactable.

So the first thing I did was disable payload staging. Since anyone can easily use this feature to grab a copy of your artifacts, payload staging can be an OPSEC concern. According to , this can be done by setting host_stage to false in the Malleable C2 profile. I know, not being able to stage an entire beacon in a 12kb binary is a little bit sad, but at least AV vendors arent able to instantly get a copy of my artifacts, and building detections for my artifact kit profiles. But then, theres also another way of detecting team servers: by logging in normally

I could just use a nonstandard port that isnt 50050 for my login, but there's still the chance that someone stumbles across it while scanning a larger port range. So, I decided to use a very simple trick to prevent people from being able to try to login: . So by setting up iptables rules to block all traffic to my login port from 0.0.0.0, and a rule that allows traffic to that port from 127.0.0.1. This way, outsiders who try to connect to it will just get connection refused.

🐙
this blackhat article
these guys
the official Cobalt Strike documentation
SSH tunneling
Cobalt Strike Redirectors
these people
Not the best thing to be woken up by
Connected!