---
description: Pesky AV vendors keep scanning my stuff >:C
---

# Using SSH Tunneling to secure C2 infra

### 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 [these people](https://blog.fox-it.com/2019/02/26/identifying-cobalt-strike-team-servers-in-the-wild/) who went and started fingerprinting Cobalt Strike teamservers using an anomalous space in NanoHTTPD. Or the time I woke up to this monstrosity:

![Not the best thing to be woken up by](https://3005128937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7fGnUKow1kUWdcf20IE0%2Fuploads%2FbH3dOP1IhIf9kqnEgvzO%2Fsystem_profilers.png?alt=media\&token=6eecd1b3-5cf2-40ed-89fe-e4ec505c7b43)

and this:

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

Which according to [this blackhat article](https://www.blackhat.com/docs/us-17/thursday/us-17-Kotler-The-Adventures-Of-Av-And-The-Leaky-Sandbox-wp.pdf) is Comodo messing with my beacons >:C

### Securing my teamservers

#### Whitelist IP Ranges

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 [these guys](https://www.youtube.com/watch?v=nX9JXI4l3-E)) start masscanning the internet, my IP won't even be contactable.

#### Disable Payload staging

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 [the official Cobalt Strike documentation](https://www.cobaltstrike.com/help-malleable-c2), 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

#### SSH Tunneling

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

![](https://3005128937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7fGnUKow1kUWdcf20IE0%2Fuploads%2Fuaw9ufrc6gTkNqmVrREr%2Fconn_failed.png?alt=media\&token=3de50ffa-c8fb-453b-8b98-58ca0ea60f6c)

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

![](https://3005128937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7fGnUKow1kUWdcf20IE0%2Fuploads%2F02p5O9qoLUpCD2wk801l%2Fwrong_pass.png?alt=media\&token=6a0e12f9-3b74-48d8-8ed2-7f6b9857c566)

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?

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: [SSH tunneling](https://www.ssh.com/academy/ssh/tunneling/example). 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.

![](https://3005128937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7fGnUKow1kUWdcf20IE0%2Fuploads%2FKEtuZFAvEMfIkqHOGSPW%2Fconn_refused.png?alt=media\&token=0b7e25bd-6138-47c2-84f9-bd4e4bc2402f)

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!

![Connected!](https://3005128937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7fGnUKow1kUWdcf20IE0%2Fuploads%2Fu4kVQTR46WtxrUgScn8X%2Fconnected.png?alt=media\&token=129bff60-ce37-410a-bea7-40fe01493139)

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

{% content-ref url="cobalt-strike-redirectors" %}
[cobalt-strike-redirectors](cobalt-strike-redirectors)
{% endcontent-ref %}
