Show Menu
Cheatography

Destructive Testing Cheat Sheet (DRAFT) by

Destructive Testing

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Outbound Network Traffic on eth0

Tools
netem, tc, qdisc, iptables
Add delay 1000+-10ms to all packets to box 10.0.0.2
#tc qdisc add dev eth0 root handle 1: prio
#tc qdisc add dev eth0 parent 1:3 handle 30: netem delay 1000ms 10ms distri­bution normal
#tc filter add dev eth0 protocol ip parent 1:0 prio 3 u32 match ip dst 10.0.0.2/32 flowid 1:3
Use netem to emulate loss, duplic­ation and corruption
#tc qdisc change dev eth0 handle 30: netem loss 0.1%
#tc qdisc change dev eth0 handle 30: netem duplicate 1%
#tc qdisc change dev eth0 handle 30: netem corrupt 0.1%
Cleanup
#tc qdisc del dev eth0 root
All commands should be run as root

Inbound Network Traffic on eth0

Tools
netem, tc, qdisc, iptables
Notes:
To use netem on incoming traffic we have to use ifb (inter­mediate functional block pseudo­-de­vice). This network device allows attaching queuing discplines to incoming packets.
To load and brinnig up ifb module
#modprobe ifb
#ip link set dev ifb0 up
Add delay 1000+-10ms to all packets from box 10.0.0.2
#tc qdisc add dev eth0 ingress
#tc filter add dev eth0 parent ffff: protocol ip u32 match ip src 10.0.0.2/32 flowid 1:1 action mirred egress redirect dev ifb0
#tc qdisc add dev ifb0 root netem delay 1000ms
Use netem to emulate loss, duplic­ation and corruption
#tc qdisc change dev ifb0 root netem loss 0.1%
#tc qdisc change dev ifb0 root netem duplicate 1%
#tc qdisc change dev ifb0 root netem corrupt 0.1%
Cleanup
#tc qdisc del dev eth0 ingress
#tc qdisc del dev ifb0 root
All commands should be run as root

Simulate Network Cable pull

Block all traffic except SSH
#iptables -A INPUT -i lo -j ACCEPT
#iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
#iptables -A OUTPUT -o lo -j ACCEPT
#iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABL­ISHED -j ACCEPT
#iptables -P INPUT DROP
#iptables -P OUTPUT DROP
Cleanu­p/Flush all rules
#iptables -F
All commands should be run as root in right order
It is better to place in script

Python Script to use X MB of memory on Server

#!/usr/bin/env python

import sys
import time

if len(sys.argv) != 2:
    print "usage: fillmem <number-of-megabytes>"
    sys.exit()

count = int(sys.argv[1])

megabyte = (0,)  (1024  1024 / 8)

data = megabyte * count

while True:
    time.sleep(1)
Credit swiftcoder on stacke­xchange

Fill up disk space on server

dd - non readable - 1GB file
#dd if=/de­v/zero of=fil­e.txt count=1024 bs=1048576
dd - random - readable - 1GB file
#dd if=/de­v/u­random of=fil­e.txt bs=1048576 count=1024

stress

Use 1GB of Memory for 1 hour
stress --vm 2 --vm-bytes 1024M --vm-hang 3600
Use 4 CPUs calcul­ating sqrt of randint for 1 hour
stress --cpu 4 --timeout 3600
Stress IO
stress --io 4
more info: https:­//l­inu­x.d­ie.n­et­/ma­n/1­/stress

Commands can be combined