Labs / Linux Exploitation / Frameworks & memory corruption

Lab 1 of 3 · Frameworks & memory corruption

From a raw foothold to a managed C2 session

Stand up a listener, deliver an implant over your foothold, catch its callback as a session, and see the beaconing a defender would catch too.

Start this lab 5 steps

The idea

Rasmus has a signed engagement against Merrivale Freight and a foothold on a logistics host as logi — one SSH shell, gone the moment the link drops. Real engagements do not run off a single raw shell. A tester adds an exploit framework on top of the foothold: Sliver (a modern, open-source C2) or Metasploit (the classic console). The shape is always the same three pieces — a listener on your team server, an implant you deliver to the target, and the session you get when the implant calls home, which you can task and which survives a reconnect.

You will build that shape by hand so you can see each piece. The implant you deploy is an inert stand-in — it carries the marker INERT-C2-BEACON, reports only its own identity, and runs no commands you give it. A real Sliver or Metasploit implant does far more; the point here is the workflow and, no less important, the beaconing pattern it leaves on the wire — the thing a defender watches for. Beaconing is this lab's blue-team half.

Steps

  1. One fragile shell

    You are on Rasmus's Kali box — the team server. The foothold is an SSH login on the logistics host at 10.0.1.20 as logi. Click Start to open a shell there and run id. This is all you have: one shell, lost if the connection drops, with nowhere to task from and no way back in. That is what the framework upgrades.

    kali:~# ssh box 'id'
  2. Stand up the listener

    Every framework starts with a listener (Sliver calls it a listener/job; Metasploit calls it a handler, exploit/multi/handler): a port on your team server waiting for implants to call home. Start one on the Kali box on 10.0.1.10:8443. Here it is a plain listener that logs every callback to a file; in Sliver you would run http -L 10.0.1.10 -l 8443, in Metasploit you would set LHOST/LPORT and run.

    kali:~# : > /tmp/c2.log; setsid bash -c 'for n in $(seq 1 60); do nc -l -p 8443 >> /tmp/c2.log 2>/dev/null; done' >/dev/null 2>&1 </dev/null & sleep 1; echo 'listener up on 10.0.1.10:8443 (log /tmp/c2.log)'
  3. Deliver and launch the implant

    In a framework you would generate an implant pinned to your listener (Sliver generate --http 10.0.1.10:8443, Metasploit msfvenom), then deliver it over whatever access you have. You already have the foothold, so deliver it over that: the implant mvr-agent is staged on the box, and you launch it over the SSH foothold so it runs there and calls home. (It is the inert stand-in — it reports its identity and nothing more.)

    kali:~# ssh box 'nohup /usr/local/bin/mvr-agent >/dev/null 2>&1 </dev/null & echo launched-pid-$!'
  4. Catch the callback

    Back on the team server, read the listener log. Within a few seconds the implant's first callback lands — in framework terms, a session has opened. It reports the marker INERT-C2-BEACON and its identity (host=box user=logi): the first thing you do with any fresh session is confirm what called home and as whom — the post-exploitation recon a real session would start with (Sliver whoami/info, Metasploit getuid/sysinfo).

    kali:~# for w in $(seq 1 25); do grep -q INERT-C2-BEACON /tmp/c2.log 2>/dev/null && break; sleep 1; done; echo '--- session callbacks ---'; cat /tmp/c2.log
  5. The pattern a defender catches

    The implant does not call once — it beacons, calling home again and again on an interval. Watch the log fill with seq=1, seq=2, seq=3… to the same address, spaced a few seconds apart. That regularity is the single most useful thing a defender has: beaconing. What Merrivale's blue team should do:

    • Hunt the rhythm in the flows. Repeated, regularly-spaced, low-volume connections from one internal host to one external address are the classic beacon signature — surface them from NetFlow or proxy logs, jitter and all. An EDR agent catches the other side: a logistics service launching bash that opens a raw socket is not normal.
    • Filter egress. The implant only works because the box may open an arbitrary outbound connection. Allow outbound only to known destinations and the call-home fails.
    • Hunt the implant at rest. An unexpected executable like mvr-agent in /usr/local/bin, launched by a service account, is the artifact to find and the foothold to close.

    One honest line: running any of this against a system whose owner has not authorised you in writing is unauthorised access, an offence under laws like the UK Computer Misuse Act and the United States' CFAA. Rasmus has a signed engagement; that permission is the only thing separating this from a crime.

    kali:~# for w in $(seq 1 30); do [ "$(grep -c INERT-C2-BEACON /tmp/c2.log 2>/dev/null)" -ge 3 ] && break; sleep 1; done; echo '--- beacon pattern ---'; grep -n INERT-C2-BEACON /tmp/c2.log

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab