kernel.panic_on_oops = 1
kernel.panic_on_warn = 1
Enable CONFIG_SECURITY_YAMA in your kernel config.
Set /proc/sys/kernel/yama to either:
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE_OVERRIDE=y
CONFIG_CMDLINE="root=/dev/sda1"
kernel.modprobe = ""
CONFIG_RANDOMIZE_BASE=y
“1”: Only users with CAP_SYSLOG see real addresses, everybody else zeros
“2”: Everyone sees just zeros
kernel.dmesg_restrict = 1
foo = realloc(foo, ...);ret = realloc(foo, ...);
if (ret == NULL) {
// [...] handle error
free(foo);
return ENOMEM;
}
foo = ret;static inline void cln_fptr(FILE **f) {
fclose(*f);
}
static void foo(void) {
__attribute__((cleanup(cln_fptr))) FILE *f;
f = fopen("/etc/passwd", "r");
// [...]
}
Key+Nonce reuse will break the security properties of the cipher.
Otherwise, attackers launch timing assaults
against your code.
$ npm audit
$ govulncheck ./...
$ cargo audit
Compile with those flags:
-O2 -D_FORTIFY_SOURCE=2
to enable basic bounds checks for functions like memcpy or strcpy.
int foo();
int foo(void);
$ echo "Hello, world" > /dev/kmsg
[734626.551208] Hello, world# gcc/clang:
$ $CC -fsanitize=address -fsanitize=undefined \
$CFLAGS# meson (> 0.55.0):
$ meson compile -Db_sanitize=address,\
undefined$ ASAN_OPTIONS="log_path=asan.log" ./a.out
$ cat asan.log.438963Use Argon2id with a recommended, universal option
(if acceptable for your use case).
Or tailor to your own Argon2id parameter set
using guide from RFC9106 section 4.
import "math/rand"
func generateAES256Key() ([]byte, error) {
var key = make([]byte, 32)
if _, err := rand.Read(key); err != nil {
return nil, err
}
return key, nil
}dtc -I fs -O dts /proc/device-tree
$ $CC -fsanitize=address $CFLAGS ...$ meson compile -Db_sanitize=address ...$ $CC -fsanitize=undefined $CFLAGS ...
$ meson compile -Db_sanitize=undefined ...
$ cryptsetup --perf-no_read_workqueue \
--perf-no_write_workqueue \
open /dev/disk name> no-read-workqueue
> no-write-workqueue> rootfstype=TYPE/dev/disk /mount/point TYPE defaults 0 0$ mount -t TYPE /dev/disk /mnt/pointMakes sure every single sector on a block
device is authenticated.
It has little overhead but allows no writes!
Like dm-verity, but offers full read-
write access.
It has more overhead since it needs to
maintain a journal!
Although an attacker cannot read your data,
they can change it!
While it’s hard to do,
attackers can exchange blocks
on encrypted disks.
Consider using dm-verity/integrity too!
# List init process namespaces
readlink /proc/1/ns/*
# List target process namespaces (replace <pid>)
readlink /proc/<pid>/ns/*$ wget https://cloud.debian.org/images/cloud/ \
trixie/latest/debian-13-nocloud-amd64.raw
$ qemu-system-x86_64 -M pc,accel=kvm -m 1G \
-drive file=debian-13-nocloud-amd64.raw,if=virtio \
-netdev type=user,hostfwd=tcp::2222-:22,id=net0 \
-device virtio-net,netdev=net0 -smp 4 -nographic
# Upon first boot, root password is configured
VM$ apt update && apt install openssh-server
VM$ echo "PermitRootLogin yes" > \
/etc/ssh/sshd_config.d/root_login.conf
VM$ systemctl restart sshd
$ ssh root@localhost -p 2222# The disk image was deleted by accident
$ ls /srv/disk1.raw
ls: cannot access '/srv/disk1.raw': No such file or directory
# Luckily, PID 1257 still has a reference
$ readlink /proc/1257/fd/* | grep disk
/srv/disk1.raw (deleted)
# Make sure the process does not alter it
# while we read it back
$ kill -STOP 1257
# Read it back
$ cat /proc/1257/fd/18 > /srv/disk1.raw$ /tmp/rootkit --do=evil --foo bar &
[1] 21528
$ ps -o pid,args --pid=21528
PID COMMAND
21528 httpd -DSYSCONFIG
$ cat /proc/21528/cmdline
httpd -DSYSCONFIG$ ps fax
[...]
24320 ? Sl 1:26 /usr/sbin/containerd-shim-runc-v2 [...]
24341 pts/0 Ss+ 0:00 \_ /bin/bash /entry.sh
[...]
$ cat /proc/24341/root/entry.sh
#!/bin/bash
set -e
supervisord -c /etc/supervisord.conf
$ cat /proc/24341/root/etc/hostname
somecontainer$ unshare -Umr
$ mount --bind /bin/bash /usr/sbin/arpd
$ exec /usr/sbin/arpd
$ # A hidden shell$ pidof arpd
1692
$ readlink /proc/1692/exe
/usr/sbin/arpd
$ readlink /proc/$$/ns/mnt /proc/1692/ns/mnt
mnt:[4026531840]
mnt:[4026533296]NO_NEW_PRIVS bit is set$ bwrap --bind / / --tmpfs /mnt /bin/shsigma star gmbh
Eduard-Bodem-Gasse 6, 1st floor
6020 Innsbruck | Austria