• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# written by jhertz
3#
4
5test "$1" = "-h" -o "$1" = "-hh" && {
6  echo 'afl-persistent-config'
7  echo
8  echo $0
9  echo
10  echo afl-persistent-config has no command line options
11  echo
12  echo afl-persistent-config permanently reconfigures the system to a high performance fuzzing state.
13  echo "WARNING: this reduces the security of the system!"
14  echo
15  echo Note that there is also afl-system-config which sets additional runtime
16  echo configuration options.
17  exit 0
18}
19
20echo
21echo "WARNING: This scripts makes permanent configuration changes to the system to"
22echo "         increase the performance for fuzzing. As a result, the system also"
23echo "         becomes less secure against attacks! If you use this script, setup"
24echo "         strong firewall rules and only make SSH available as a network"
25echo "         service!"
26echo
27echo -n "Type \"YES\" to continue: "
28read ANSWER
29if [[ "$ANSWER" != "YES" ]]; then
30  echo Input was not YES, aborting ...
31  exit 1
32fi
33
34echo
35PLATFORM=`uname -s`
36
37# check that we're on Mac
38if [[ "$PLATFORM" = "Darwin" ]] ; then
39
40  # check if UID == 0
41  if [[ "$EUID" -ne 0 ]]; then
42    echo "You need to be root to do this. E.g. use \"sudo\""
43    exit 1
44  fi
45
46  # check if SIP is disabled
47  if [[ ! $(csrutil status | grep "disabled") ]]; then
48    echo "SIP needs to be disabled. Restart and press Command-R at reboot, Utilities => Terminal => enter \"csrutil disable\""
49    exit 1
50  fi
51
52  echo "Checks passed."
53
54  echo "Installing /Library/LaunchDaemons/shm_setup.plist"
55
56  cat << EOF > /Library/LaunchDaemons/shm_setup.plist
57<?xml version="1.0" encoding="UTF-8"?>
58<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
59<plist version="1.0">
60  <dict>
61    <key>Label</key>
62    <string>shmemsetup</string>
63    <key>UserName</key>
64    <string>root</string>
65    <key>GroupName</key>
66    <string>wheel</string>
67    <key>ProgramArguments</key>
68    <array>
69      <string>/usr/sbin/sysctl</string>
70      <string>-w</string>
71      <string>kern.sysv.shmmax=524288000</string>
72      <string>kern.sysv.shmmin=1</string>
73      <string>kern.sysv.shmmni=128</string>
74      <string>kern.sysv.shmseg=48</string>
75      <string>kern.sysv.shmall=131072000</string>
76    </array>
77    <key>KeepAlive</key>
78    <false/>
79    <key>RunAtLoad</key>
80    <true/>
81  </dict>
82</plist>
83EOF
84
85  echo
86  echo "Reboot and enjoy your fuzzing"
87  exit 0
88fi
89
90if [[ "$PLATFORM" = "Linux" ]] ; then
91
92  # check if UID == 0
93  if [[ "$EUID" -ne 0 ]]; then
94    echo "You need to be root to do this. E.g. use \"sudo\""
95    exit 1
96  fi
97
98  echo "Checks passed."
99
100  test -d /etc/sysctl.d || echo Error: /etc/sysctl.d directory not found, cannot install shmem config
101  test -d /etc/sysctl.d -a '!' -e /etc/sysctl.d/99-fuzzing && {
102    echo "Installing /etc/sysctl.d/99-fuzzing"
103    cat << EOF > /etc/sysctl.d/99-fuzzing
104kernel.core_uses_pid=0
105kernel.core_pattern=core
106kernel.randomize_va_space=0
107kernel.sched_child_runs_first=1
108kernel.sched_autogroup_enabled=1
109kernel.sched_migration_cost_ns=50000000
110kernel.sched_latency_ns=250000000
111EOF
112  }
113
114  egrep -q '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub 2>/dev/null || echo Error: /etc/default/grub with GRUB_CMDLINE_LINUX_DEFAULT is not present, cannot set boot options
115  egrep -q '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub 2>/dev/null && {
116    egrep '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub | egrep -q hardened_usercopy=off || {
117      echo "Configuring performance boot options"
118      LINE=`egrep '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub | sed 's/^GRUB_CMDLINE_LINUX_DEFAULT=//' | tr -d '"'`
119      OPTIONS="$LINE ibpb=off ibrs=off kpti=off l1tf=off mds=off mitigations=off no_stf_barrier noibpb noibrs nopcid nopti nospec_store_bypass_disable nospectre_v1 nospectre_v2 pcid=off pti=off spec_store_bypass_disable=off spectre_v2=off stf_barrier=off srbds=off noexec=off noexec32=off tsx=on tsx=on tsx_async_abort=off mitigations=off audit=0 hardened_usercopy=off ssbd=force-off"
120      echo Setting boot options in /etc/default/grub to GRUB_CMDLINE_LINUX_DEFAULT=\"$OPTIONS\"
121      sed -i "s|^GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT=\"$OPTIONS\"|" /etc/default/grub
122    }
123  }
124
125  echo
126  echo "Reboot and enjoy your fuzzing"
127  exit 0
128fi
129
130
131
132echo "Error: Unknown platform \"$PLATFORM\", currently supported are Linux and MacOS."
133exit 1
134