C2 detection: review of the old module and the plan for a new one

  • This page is the original review and plan. It is kept as a record.

  • What was built from it is described in beaconing detection.

  • The review was done on revision f21589a7f, on 24 October 2026.

  • The two dataset/test-cc captures are simulations. Their author confirmed this.

  • No malware was run, no traffic was captured and the running Slips was not changed for this review.

Recommendation

  • Keep the original idea: describe how one client talks to one service again and again, using timing, duration and size.

  • Keep these values as numbers. Don’t turn them into a small set of letters before detecting.

  • Start with simple statistics that find the usual interval and allow for:

    • variation in the timing.

    • missed connections.

    • bursts and quiet periods.

  • This finds beacon-like traffic without a large set of malware examples.

  • Then use other evidence to decide how suspicious the channel is.

  • Add a small trained model once there are good examples of both C2 and normal automatic traffic.

What can’t be done:

  • Two channels that behave in the same way can’t be told apart just because one of them is malware.

  • Regular timing shows that a program is doing it, not that the program is malware.

  • BAYWATCH also treats telling normal and malicious beacons apart as the main problem.

Problems in the old module

The code that was reviewed:

Problem

What it causes

The module only accepts flows with the text established in flow.state. Zeek gives finished TCP connections the state SF.

These flows are skipped. In a test, the model was called zero times for SF, once for Established, and once, wrongly, for Not Established.

Training pads with the number 0. Running pads with the character "0", which becomes the number 45. The letter a also becomes 0, and the model ignores zeros (mask_zero=True).

Training and running don’t agree on what “nothing here” looks like, and padding is mixed with real letters. A new model needs its own padding value, used in the same way in both.

The input is cut with sequence[:500].

After the first 500 characters, nothing new reaches the model. Two sequences with different endings give the same input.

Confidence is min(1, number_of_characters / 100).

Punctuation and long gap symbols are counted as flows. The confidence says nothing about the number of connections, the time covered or the error rate.

The model threshold is fixed at 0.99.

Nobody measured what this value means on new networks or how many false alerts it gives. It is not a 99% chance that the channel is C2.

The full, growing string of letters is stored and published, even though the model ignores the end of it.

Long strings are copied and sent again and again. The model also checks the same padded 500 characters again and again.

The timing history belongs to one profile and time window.

A channel is cut at every time window. Slow beacons, and beacons that come back, are harder to see.

The padding problem can be measured with the rnn_model.h5 that comes with Slips:

  • For the same 42 character sequence from capture 2, the model gives about 0.99977 with the padding used when running, and 0.22467 with the padding used in training.

  • This test skips the broken state check, to look at the padding only.

  • It doesn’t show which of the two results is right. It also doesn’t show that the simulated beacon is malware.

  • Only changing the padding is not safe. The model has to be trained and tested again.

What the test captures contain

Zeek was run offline on both captures. The table is about the main TCP channel of each. Sizes are the total application bytes that Zeek reports, which is what the letters use.

Measurement

Capture 1

Capture 2

Total capture duration

665.08 seconds

67.50 seconds

Main channel

147.32.80.37 → 141.193.213.21:443/tcp

147.32.80.37 → 141.193.213.20:443/tcp

Connections in that channel

297

22

Median interval between starts

2.204 seconds

3.029 seconds

Interval range

2.180–4.429 seconds

2.276–3.796 seconds

Total bytes per connection

4,720–4,753

6,842–6,869

Intervals within ±25% of their median

99.3%

95.2%

Old periodicity letters after the first two flows

263 h, 28 H, 4 y

12 H, 8 y

  • Both captures use the TLS server name (SNI) testing.com.

  • Capture 1 also has two connections to 141.193.213.20.

    • Two connections are not enough to call it a repeating channel.

    • They use the same SNI as the main channel.

    • When all 299 connections are put together by SNI, the doubled intervals go away. The range becomes 2.180–2.744 seconds and every interval is within ±25% of the median.

    • So the longer gaps in the figure come from the client changing between two server IPs, not from missed connections.

    • This is a good reason to keep both the view per IP and a view per service.

  • Capture 2 also has 241 UDP connections, mostly DNS. They must not be labeled C2 just because they are in the same capture.

Measured intervals and legacy letter counts

  • The green area is only an example of a tolerance. It is not a tested threshold.

  • These captures test strict and slightly irregular timing.

  • They don’t test:

    • beacons that are hours apart.

    • long quiet periods.

    • one long encrypted connection.

    • false alerts on real normal traffic.

To get the same Zeek logs, run from the root of the repository:

mkdir -p output/cc-strategy/capture-1 output/cc-strategy/capture-2
zeek -C -r dataset/test-cc/test-cc-capture-1.pcap LogAscii::use_json=T 'Log::default_logdir=output/cc-strategy/capture-1'
zeek -C -r dataset/test-cc/test-cc-capture-2.pcap LogAscii::use_json=T 'Log::default_logdir=output/cc-strategy/capture-2'

Why numbers are better than letters

The letters lose information:

  • There are only three size groups, three duration groups and four periodicity groups.

  • Everything above 1,100 bytes is in the same size group.

  • An interval of 2 seconds and one of 4 seconds get the same . character.

  • Close to a limit, a very small change gives a different letter.

  • Turning the number of a letter into a float doesn’t bring the lost value back.

So read the original values of the flow:

Measurement

Why it is useful

Seconds between the starts of connections

Finds the interval without assuming a malware family or a fixed number of seconds.

Seconds from the end of one connection to the start of the next

Shows a program that sleeps for a fixed time after an answer. Without it, a slow server looks like irregular timing. Overlapping connections are flagged separately.

Bytes and packets in each direction

Describe the repeated exchange. With the directions kept apart, a small request that stays the same is still seen when the answer size changes.

Connection duration

Helps tell quick check-ins, long polling and large transfers apart.

Variation of intervals, sizes and durations

Shows how regular the channel is, while still allowing a command or a large answer now and then.

Number of connections, time covered, gaps and last activity

Tells a pattern seen a few times from one seen many times, and a paused channel from a changed one.

Result of the connection and protocol information

Tells answered connections from retries. Adds hints like a rare destination or unusual TLS or HTTP.

How to store them:

  • Keep timestamps as float64 or as integer microseconds. A float32 is not precise enough for epoch timestamps.

  • Keep byte and packet counts as integers. Values computed from them can be float32.

  • A log transform like log1p(bytes) helps compare very small and very large values. Keep the original values too, to explain the evidence.

Timing: repeating activity with interruptions

Finding the interval:

  • Use the median of the recent intervals of the channel as its usual interval.

  • Measure the spread with the median absolute deviation and with quantiles. A few unusual connections change them less than they change a mean and standard deviation.

  • utils.py already has these.

Score these separately:

  1. How regular the intervals are. Compare start to start, and end to start for connections that don’t overlap. Trying two ways gives more chances to match, so take that into account when setting thresholds.

  2. Whether the exchange repeats. Do the request size, answer size and duration repeat? One large answer to a command should not hide the small check-ins around it.

  3. How long it lasts. Are there enough connections over enough time? Two regular connections are not enough.

  4. Whether it comes back. Does the same behaviour return after a gap or after a burst?

What to remember:

  • Keep a short, a medium and a long history. The short one lets the interval change. The long ones keep what was learned over quiet periods.

  • Keep the channel across Slips time windows, and save it so it is still there after a restart. Limit how long it is kept and how much memory it uses.

States of a channel:

  • Start with four: collecting, recurring, paused and changed.

  • They describe what is known so far. They are not “normal” or “malicious” labels.

  • A quiet period should lower the confidence that the channel is active, without forgetting how it behaved.

Missed connections:

  • Only accept a small, limited number of missed intervals in one gap, and lower the score for each.

  • Don’t let a very short interval explain every long gap as thousands of missed connections.

  • A long pause should be its own state.

Things to be careful with:

  • Some malware sleeps a random time after each answer. Other malware follows a clock. The first kind slowly drifts, by design. A method that expects a fixed clock, or only looks for a Fourier peak, misses it.

  • Joining all connections that are close together into one burst would hide a beacon that really is fast. Compare the original connections with the bursts, and keep both.

  • No interval is “the C2 interval”. Once per second and once every six hours can both be suspicious.

  • Twelve connections that are one hour apart need at least eleven hours. The history must be kept long enough for the slowest interval and the lowest number of connections that Slips claims to support.

Which methods to compare

Method

Where it fits

Interval and size statistics, plus the four states above

Build this first. It is cheap, the evidence is easy to explain, and no malware labels are needed to find repeating behaviour. Its thresholds still have to be tested on normal traffic.

Logistic regression, or shallow gradient boosted trees, on a summary of each channel

The first trained models to compare, once the labels are good. They can use timing, sizes, gaps and other information without a large sequence network. Compare their false alerts and how long they take to detect. Neither is the best by default.

Hidden Markov or semi-Markov model

A later test, if modelling the active and quiet states and how long they last helps enough to be worth the extra work.

GRU, TCN or MiniRocket on the numbers

A later comparison, when there are enough separate labeled sequences. Give them the real time gaps and decide how sequences of different lengths are handled. A larger model has to be worth its CPU and memory.

Keep this work in the C2 detector:

  • The service behaviour anomaly detection answers another question: does a host get connections from unexpected clients, or at unusual times?

  • The two can share statistics and storage code.

  • C2 detection should not wait for the training period of that module.

Training when there are few malware examples

Three things that are easy to mix up:

  • Measuring a channel. Compute its interval and variation from the traffic. This doesn’t say the channel is normal.

  • Setting thresholds for false alerts. Use trusted normal traffic, mostly automatic traffic like updates, monitoring, sync, backups, DNS and telemetry. Set the thresholds on a part of it that was kept aside.

  • Learning what C2 looks like. Use checked labels from real malware captures and from simulations. Record where each label came from. Test real malware and simulations separately.

Don’t assume clean traffic:

  • Don’t treat the first hour or day of a host as clean. A host that is already infected must still be detected.

  • Reports from peers are extra information. They are not connections seen locally, and not trusted labels.

Problems in the old training script:

  • Every label with Botnet or Malware in it is used as a positive example.

  • With the default steps, 2,228 of the 7,631 rows of the main TSV file are kept.

  • Only 59 of the kept labels contain CC. The other positives include DNS, spam and connection attempts.

  • Some of them may be C2 too, but they have to be checked first and not just relabeled.

  • The rows are split randomly. 75 of the 446 test inputs are exactly the same as an input in training. They may not be copies from the same capture, but the test is less independent because of them.

  • The Optuna part tries its choices on the test split again and again. So the test split is used for tuning, not for a final test.

For the new module:

  1. Get the original flows of the known old C2 channels where they still exist. The old letters can’t be turned back into exact numbers. Where the flows are gone, keep the old datasets only to compare with.

  2. Label these separately: real C2 channels, other traffic of the malware, normal automatic traffic, traffic made by people, and channels nobody is sure about. Don’t force the unsure ones into a class.

  3. Make simulated variations:

    • strict timing, and jitter to one side or to both sides.

    • missed connections, pauses and changing intervals.

    • bursts for tasks, changing servers and failed connection attempts.

    • both normal and malicious uses of similar schedules.

    • Simulations show what is covered. They don’t prove that real malware is detected, and they don’t replace real normal traffic.

  4. Split by whole capture or session. Where possible also split by malware family, device and time of collection. Keep every window and every simulated copy of a session on the same side of the split.

  5. Tune on training and validation only. Keep unseen families, later captures and other networks for the final test. Say how uncertain the result is when there are few separate malicious channels.

What to measure:

  • precision and recall.

  • false alerts per host per day.

  • time until the first detection.

  • CPU and memory.

  • Accuracy on a small mixed set is not enough for a detector that watches many normal channels.

Proposed settings and limits

  • These were proposals. See the settings that exist now.

  • First values have to be tested. Two simulations are not enough to call a value a safe default.

Setting

What it changes

Lowest number of connections

Connections needed before repeating behaviour is reported. Start comparing around 8–12. Lower reports sooner, on less proof.

Allowed interval variation

How far a gap can be from the interval, as a part of it. With 0.25 and an interval of 60 seconds, 45–75 seconds is accepted. This is a tolerance of the detector. It is not the jitter percentage set in a C2 tool.

Part of the gaps that must match

For example 80%. Allows some gaps and bursts, without letting a few matching gaps decide.

Shortest and longest interval

The intervals to look at. A wide range gives slow beacons a chance, but needs a longer history and more connections.

Pause and missed connection limits

How long a quiet channel is kept, and how many missed intervals can be accepted. Stops forgetting too early, and stops any traffic from being called periodic.

Recent connections kept and channel limit

Keeps the memory fixed no matter how long the capture is. A first version could compare 128 connections per channel and 4,096 channels, stored as compact numbers, with a counter of dropped channels.

Check interval and new connections needed

Limits the costly checks. For example after four new connections, and at most once every five seconds per channel. Adding a connection must stay cheap.

Evidence cooldown

Limits repeated evidence for a pattern that didn’t change. Keep the count, the last time seen and the flow UIDs, and don’t set one evidence per connection.

Where the data comes from:

  • Use the new_flow messages that already exist. Don’t add another growing string to Redis.

  • Only use the flow from the side of the host that started it.

  • Count each flow UID once, and handle flows that arrive a little out of order.

  • Use the parsed result of the connection. Don’t search for text in state names, which differ per tool.

What a channel is:

  • The network, a stable identity of the local host, the remote IP, the destination port and the protocol. This keeps the original client and service grouping.

  • The temporary source port is ignored.

  • Remote IPs that change can be linked when DNS or SNI shows they are the same service. Keep the record of each IP too.

  • Don’t join unrelated customers just because they share a CDN, a certificate or a provider.

Storage:

  • Keep a limited amount of numbers in memory.

  • Save in small batches, following the SQLite writer lock rules Slips already has.

  • Use the shared statistics code.

  • No Redis history that grows forever, and no reading of the full history on every new flow.

  • These are requirements. The real CPU and memory still have to be measured on the Mac and the Pi.

Limits and rollout

One long connection:

  • One long TLS connection can carry many C2 messages and still be a single Zeek flow.

  • The times of those messages can’t be found from the flow.

  • Finding them needs packet, burst or application information from Zeek.

  • Evidence about long connections is still useful, but it doesn’t give those times.

Steps:

  1. Fix and document how the old module reads and encodes its input, and record how well it really does.

  2. Build the new detector in a test-only mode and compare it with the old one.

  3. Set its thresholds on normal automatic traffic.

  4. Show suspicious channel evidence to the analyst first. Think about stronger automatic blocking only later.

  5. A regular schedule alone is not a reason to block a destination as malicious.

While moving from the old module to the new one:

  • Keep the existing module and configuration names, and give the new number format a version.

  • Compare old and new results without setting the same evidence twice.

  • Keep the letter export for the tools that use it, while detection stops using the full growing strings.

Testing:

  • Use the two test captures to make sure nothing breaks later.

  • Add cases for missed beacons, pauses, slow beacons and one long connection.

  • Measure false alerts on separate normal traffic.

  • Only pick a trained model when it does better in these tests than the simple statistics.