domingo, 27 de agosto de 2023

Running a "stealth" ssh session (Stealth SSH)

Had an authorized assessment where I needed to hop in and out of a bunch of machines fast, without stacking unknown hosts in my known_hosts and without the terminal complaining about color or size every time i dropped into some minimal shell. One line fixed it.

Run:


~ # ssh -tt \ -o UserKnownHostsFile=/dev/null \ -o StrictHostKeyChecking=no \ user@host 'TERM=xterm-256color exec bash -i'

How this command works:
  1. -tt → forces double pseudo-terminal allocation. gives you a full terminal — color, resizing, interactive commands — even against shells that normally choke on TTY.
  2. -o UserKnownHostsFile=/dev/null → tells SSH not to write anything to known_hosts. no local trail piling up from every test box you touch.
  3. -o StrictHostKeyChecking=no → skips host key checking. worth a pause here: this check exists specifically to catch man-in-the-middle attacks, so this flag turns off the one thing that would warn you if the connection was being intercepted. only makes sense on a network you already trust — authorized test environments, or internal automation against hosts that rotate IPs often enough that babysitting known_hosts isn't worth it.
  4. 'TERM=xterm-256color exec bash -i' → sets a full color terminal and drops straight into an interactive bash, bypassing whatever default shell the server has configured.

one thing worth being straight about, since "stealth" in the title oversells it a bit: this only clears your side of the trail — your local known_hosts. nothing changes on the server. auth.log logs the login normally, last shows the session, and remote shell history stays on unless you handle that separately. real stealth means thinking about both ends of the connection, not just the client.

When to use it: pentesting / red team work, so you don't pollute known_hosts jumping between client environments. automation that needs a clean interactive shell. lab environments where IPs rotate often enough that host key checking is more friction than protection.

Other considerations: only use this on authorized networks, no exceptions. prefer key-based auth over passwords, always. on the server side, set up Match in sshd_config to limit what each account can actually run. for a session that survives a dropped connection, pair this with tmux or screen on the remote end.

sexta-feira, 25 de agosto de 2023

Encrypted swap-file

Everyone swaps laptops eventually and forgets one detail: disk encryption doesn't cover swap. You encrypt the whole root partition, sleep fine, then forget the kernel dumps memory pages into an unencrypted file the moment RAM gets tight. If someone grabs your disk after a hibernate, or even after a heavy session that forced swap, that data is sitting there, plain.

Here's how I closed that gap on my own [Gentoo] setup.

Execute:


~ # dd bs=4M count=2560 if=/dev/zero of=swapfile conv=fsync oflag=direct status=progress && chattr +C swapfile && \ lsattr swapfile && chmod 0600 swapfile && ls -l swapfile && cryptsetup luksFormat swapfile ~ # cryptsetup luksOpen swapfile swap_crypt && mkswap /dev/mapper/swap_crypt && swapon /dev/mapper/swap_crypt

How this command works:

on systems with strong privacy requirements, running swap on disk without encryption is a real risk (RAM data exposed on hibernation or physical extraction).

  1. dd bs=4M count=2560 ... → creates a 10GB file (block size × count = total size, adjust count for whatever size you need).
  2. chattr +C swapfile → disables Copy-on-Write. this only does anything on Btrfs — on ext4 the command runs and silently does nothing, so check your filesystem first instead of trusting the flag blindly.
  3. chmod 0600 → strict permissions (rw for the owner only).
  4. cryptsetup luksFormat → creates an encrypted LUKS container.
  5. cryptsetup luksOpen + mkswap + swapon → opens it, formats it as swap, and activates it.

Advantages: protects in-memory data against cold boot attacks and disk forensics — anyone pulling the drive lands on ciphertext instead of raw pages.

Risks: performance overhead from encryption (more noticeable on spinning disks than SSDs) and extra complexity at boot.

To make it persistent: configure it in /etc/crypttab and /etc/fstab (Gentoo/OpenRC) or set up a systemd unit. either way, the LUKS container has to be open before swapon runs — that ordering is the part that actually breaks if you get it wrong.

pass + GPG + git-remote-gcrypt: Encrypted Password Store Sync with GitHub

The idea was simple: keep my passwords in the terminal with pass , version the encrypted files with Git, and maintain an encrypted backu...