Skip to content

Commit a3680e9

Browse files
authored
Merge pull request #4 from wowitsjack/patch-1
Create sage_getwebkit.sh
2 parents de80b97 + 370d583 commit a3680e9

File tree

6 files changed

+874
-43
lines changed

6 files changed

+874
-43
lines changed

browser_builders/sage_getwebkit.sh

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#!/bin/bash
2+
3+
# Check for and install missing dependencies
4+
install_missing_deps() {
5+
local missing_deps=""
6+
7+
# List of essential commands and their corresponding packages
8+
declare -A essential_cmds=( ["dialog"]="dialog" ["sudo"]="sudo" ["git"]="git" ["wget"]="wget" ["cmake"]="cmake" ["ninja-build"]="ninja-build" ["apt-get"]="apt" )
9+
10+
# Check each command and record missing ones
11+
for cmd in "${!essential_cmds[@]}"; do
12+
if ! command -v $cmd &> /dev/null; then
13+
missing_deps+="${essential_cmds[$cmd]} "
14+
fi
15+
done
16+
17+
# Install missing dependencies, if any
18+
if [ -n "$missing_deps" ]; then
19+
echo "The following dependencies are missing and will be installed: $missing_deps"
20+
sudo apt-get update
21+
sudo apt-get install -y $missing_deps
22+
else
23+
echo "All essential dependencies are already installed."
24+
fi
25+
}
26+
27+
# Initial setup
28+
clear
29+
echo "Checking and installing missing dependencies..."
30+
install_missing_deps
31+
32+
# Request sudo access at the beginning
33+
echo "Requesting administrative access for initial setup..."
34+
sudo -v
35+
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
36+
37+
# Function to execute commands within dialog boxes, showing output in a progress box
38+
execute_command() {
39+
local cmd=$1
40+
local title=$2
41+
dialog --title "$title" --infobox "Preparing execution..." 10 70
42+
eval "$cmd" 2>&1 | dialog --title "$title" --progressbox 50 100
43+
}
44+
45+
# Function to display welcome message using dialog
46+
welcome_message() {
47+
dialog --clear --title "Welcome" --msgbox "Welcome to the Setup Wizard. This will guide you through setting up the environment." 10 50
48+
}
49+
50+
# Function to get WebKitGTK version from the user
51+
get_webkitgtk_version() {
52+
WEBKITGTK_VERSION=$(dialog --title "WebKitGTK Version" --inputbox "Enter the version of WebKitGTK you want to build:" 8 40 "2.42.5" 2>&1 >/dev/tty)
53+
}
54+
55+
# Function to show build options menu and capture selections
56+
show_build_options_menu() {
57+
BUILD_OPTIONS=$(dialog --checklist "Choose build options:" 22 76 15 \
58+
"ENABLE_BUBBLEWRAP_SANDBOX" "Bubblewrap Sandbox" ON \
59+
"ENABLE_DOCUMENTATION" "Documentation" OFF \
60+
"ENABLE_DRAG_SUPPORT" "Drag Support" ON \
61+
"ENABLE_GAMEPAD" "Gamepad Support" ON \
62+
"ENABLE_INTROSPECTION" "Introspection" ON \
63+
"ENABLE_JOURNALD_LOG" "Journald Log" ON \
64+
"ENABLE_MINIBROWSER" "Mini Browser" ON \
65+
"ENABLE_PDFJS" "PDF.js" ON \
66+
"ENABLE_QUARTZ_TARGET" "Quartz Target" OFF \
67+
"ENABLE_SPELLCHECK" "Spellcheck" ON \
68+
"ENABLE_TOUCH_EVENTS" "Touch Events" ON \
69+
"ENABLE_VIDEO" "Video" ON \
70+
"ENABLE_WAYLAND_TARGET" "Wayland Target" ON \
71+
"ENABLE_WEBDRIVER" "WebDriver" ON \
72+
"ENABLE_WEB_AUDIO" "Web Audio" ON \
73+
"ENABLE_WEB_CRYPTO" "Web Crypto" ON \
74+
"ENABLE_X11_TARGET" "X11 Target" ON \
75+
"USE_AVIF" "AVIF Images" ON \
76+
"USE_GBM" "GBM" ON \
77+
"USE_GSTREAMER_TRANSCODER" "GStreamer Transcoder" ON \
78+
"USE_GSTREAMER_WEBRTC" "GStreamer WebRTC" OFF \
79+
"USE_GTK4" "GTK4" OFF \
80+
"USE_JPEGXL" "JPEG XL" ON \
81+
"USE_LCMS" "Little CMS" ON \
82+
"USE_LIBHYPHEN" "LibHyphen" ON \
83+
"USE_LIBSECRET" "Libsecret" ON \
84+
"USE_OPENGL_OR_ES" "OpenGL or ES" ON \
85+
"USE_OPENJPEG" "OpenJPEG" ON \
86+
"USE_SOUP2" "Soup2" OFF \
87+
"USE_WOFF2" "WOFF2 Fonts" ON 2>&1 >/dev/tty)
88+
}
89+
90+
# Install all required packages at once, silently, with no user interaction
91+
install_packages() {
92+
packages="libgcrypt20 libgcrypt20-dev libtasn1-6 libtasn1-6-dev unifdef libwebp-dev libgtk-4-dev libsoup3-dev libsoup3 libsoup-3.0-dev libmanette-0.2-dev libxslt1-dev libsecret-1-dev libdrm-dev libgbm-dev libenchant-2-dev libjxl-dev afl++ libstdc++-11-dev build-essential clang llvm-17 libstdc++-12-dev libhyphen-dev libwoff-dev libavif-dev libsystemd-dev liblcms2-dev libgcc-11-dev libseccomp-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good libgstreamer1.0-dev gstreamer1.0-libav gstreamer1.0-plugins-bad libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-good libgstrtspserver-1.0-dev gperf gettext libxt-dev libopenjp2-7-dev gi-docgen libwebkit2gtk-4.1-dev ninja-build"
93+
execute_command "sudo apt-get update && sudo apt-get install -y $packages" "Installing required packages"
94+
}
95+
96+
# Function to clone, build, and install dependencies
97+
git_clone_and_setup() {
98+
local git_url=$1
99+
local folder_name=$2
100+
local setup_commands=$3
101+
local title=$4
102+
execute_command "rm -rf $folder_name && git clone $git_url $folder_name --recursive --shallow-submodules && cd $folder_name && $setup_commands" "$title"
103+
}
104+
105+
# Welcome the user and get necessary input
106+
welcome_message
107+
108+
# Function to create a swapfile
109+
create_swapfile() {
110+
# Ask user for the swapfile size and location
111+
SWAPFILE_DETAILS=$(dialog --title "Swapfile Configuration" --form "Enter the details for the swapfile:" 15 50 0 \
112+
"Size (e.g., 128G):" 1 1 "128G" 1 25 25 0 \
113+
"Location (path):" 2 1 "$(pwd)/swapfile" 2 25 100 0 \
114+
2>&1 >/dev/tty)
115+
116+
# Parse input
117+
SWAPFILE_SIZE=$(echo "$SWAPFILE_DETAILS" | sed -n 1p)
118+
SWAPFILE_LOCATION=$(echo "$SWAPFILE_DETAILS" | sed -n 2p)
119+
120+
# Remove existing swapfile if it exists
121+
[ -f "$SWAPFILE_LOCATION" ] && sudo swapoff "$SWAPFILE_LOCATION" && rm -f "$SWAPFILE_LOCATION"
122+
123+
# Create new swapfile
124+
execute_command "sudo fallocate -l $SWAPFILE_SIZE $SWAPFILE_LOCATION && sudo chmod 600 $SWAPFILE_LOCATION && sudo mkswap $SWAPFILE_LOCATION && sudo swapon $SWAPFILE_LOCATION" "Creating Swapfile"
125+
126+
# Confirmation message
127+
dialog --title "Swapfile Creation" --msgbox "Swapfile created successfully at $SWAPFILE_LOCATION with a size of $SWAPFILE_SIZE." 10 50
128+
}
129+
130+
# Create swapfile as part of the setup process
131+
create_swapfile
132+
133+
get_webkitgtk_version
134+
show_build_options_menu
135+
136+
# Install essential packages
137+
install_packages
138+
139+
# Clone and setup libjxl
140+
git_clone_and_setup "https://github.com/libjxl/libjxl.git" "libjxl" "sudo apt install -y cmake pkg-config libbrotli-dev libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev clang && export CC=clang CXX=clang++ && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF .. && cmake --build . -- -j\$(nproc) && sudo cmake --install ." "Setting up libjxl"
141+
142+
# Clone and setup libbacktrace
143+
git_clone_and_setup "https://github.com/ianlancetaylor/libbacktrace" "libbacktrace" "./configure && make && sudo make install" "Installing libbacktrace"
144+
145+
# Convert dialog output to CMake and Ninja build options
146+
CONVERTED_OPTIONS=""
147+
IFS=' ' read -ra ADDR <<< "$BUILD_OPTIONS"
148+
for option in "${ADDR[@]}"; do
149+
if [[ "$option" == "\"USE_WPE_RENDERER\"" ]]; then
150+
CONVERTED_OPTIONS+="-DUSE_WPE_RENDERER=ON "
151+
else
152+
CONVERTED_OPTIONS+="-D${option//\"/}=ON "
153+
fi
154+
done
155+
156+
# Build and install WebKitGTK using Ninja as per user-selected options, removing any previous extracted folder
157+
BUILD_COMMAND="rm -rf webkitgtk-${WEBKITGTK_VERSION} && wget https://webkitgtk.org/releases/webkitgtk-${WEBKITGTK_VERSION}.tar.xz && tar xf webkitgtk-${WEBKITGTK_VERSION}.tar.xz && cd webkitgtk-${WEBKITGTK_VERSION} && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_SKIP_RPATH=ON -DPORT=GTK -DLIB_INSTALL_DIR=/usr $CONVERTED_OPTIONS -Wno-dev -G Ninja .. && ninja && sudo ninja install"
158+
execute_command "$BUILD_COMMAND" "Building and installing WebKitGTK ${WEBKITGTK_VERSION} with Ninja"
159+
160+
# Function to remove a swapfile
161+
remove_swapfile() {
162+
local location=$(dialog --title "Remove Swapfile" --inputbox "Enter the location of the swap file to remove:" 8 40 "./swapfile" 2>&1 >/dev/tty)
163+
164+
if [ -f "$location" ]; then
165+
# Deactivate the swapfile
166+
sudo swapoff "$location"
167+
168+
# Remove the swapfile
169+
rm -f "$location"
170+
171+
# Display completion message
172+
dialog --title "Swapfile Removal" --msgbox "Swapfile removed successfully from $location." 10 50
173+
else
174+
dialog --title "Swapfile Removal" --msgbox "Swapfile not found at $location." 10 50
175+
fi
176+
}
177+
178+
# Optionally remove the swapfile as part of the cleanup process
179+
# remove_swapfile
180+
181+
# Final message to indicate completion
182+
dialog --clear --title "Completion" --msgbox "All steps completed successfully. Your environment is now set up." 10 50
183+
184+
clear

demo.png

827 KB
Loading

readme.md

Lines changed: 83 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
# SaGe browser fuzzer
1+
2+
# SaGe Browser Fuzzer 🌐💻
23

34
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8328742.svg)](https://doi.org/10.5281/zenodo.8328742)
45

5-
SaGe is a browser fuzzer that can effectively explore browsers' semantics.
6+
Welcome to SaGe Browser Fuzzer, a cutting-edge tool designed for the intricate exploration of web browser semantics 🚀.
7+
8+
Developed with a focus on identifying and cataloging internal browser JS vulnerabilities, SaGe offers an automated, comprehensive suite of features for thorough browser testing via PCSG-guided fuzzing.
9+
10+
## System Requirements 📋
11+
12+
- **Operating System**: Linux (Ubuntu 20.04 LTS and 22.04 LTS highly recommended; other distributions may function but are less tested), MacOS (experimental support), Windows (limited testing).
13+
- **Python**: Version 3.8 or newer.
14+
- **Selenium**: Install via `pip3 install selenium==3.141.0` and `pip3 install urllib3==1.26.5`. Newer versions may also be compatible.
15+
- **Xvfb**: Required for headless operation on Linux, install with `apt install xvfb`.
616

7-
## Requirement
17+
## Installation 🛠
818

9-
- OS: Linux (recommended, well tested in Ubuntu 20.04 LTS and 22.04 LTS); MacOS (supposed to work but not well tested); Windows (not well tested)
10-
- Python 3.8+
11-
- Selenium (``pip3 install selenium==3.141.0`` and ``pip3 install urllib3==1.26.5``. The versions are well tested, but the latest versions should also work.)
12-
- Xvfb (apt install xvfb)
19+
Ensure all dependencies are met.
1320

14-
## Usage
21+
Linux users benefit from an automatic dependency check and installation feature upon initiating SaGe Launcher.
1522

16-
Before running the tool, first set some environment variables to enable PCSG-guided fuzzing:
23+
## Configuration and Usage 🖥
24+
25+
Set environment variables crucial for PCSG-guided fuzzing:
1726

1827
```shell
1928
export COLLECT_TREE_INFO=true
@@ -23,64 +32,95 @@ export INVALID_TREE_PATH="$SAGE_PATH/invalid_tree/invalid_tree.pickle"
2332
export RULE_INFO_PATH="$SAGE_PATH/invalid_tree/global_info.pickle"
2433
```
2534

26-
Next, use ```python main.py --help``` to show how it works.
35+
### Executing SaGe with `sage_launcher.sh`
2736

28-
```
29-
Usage: python main [-options] -o output_dir
30-
31-
Options:
32-
-h, --help show this help message and exit
33-
-f FUZZER, --fuzzer=FUZZER
34-
choose a fuzzer (default: sage)
35-
-b BROWSER, --browser=BROWSER
36-
choose a browser (default: webkitgtk)
37-
-t TIMEOUT, --timeout=TIMEOUT
38-
timeout of each test (ms) (default: 5000ms)
39-
-p PARALLEL, --parallel=PARALLEL
40-
how many instances in parallel (default: 1)
41-
-o OUTPUT_DIR, --output_dir=OUTPUT_DIR
42-
where the result should output
43-
-e TIME_TO_EXIT, --time_to_exit=TIME_TO_EXIT
44-
time to exit the fuzzing (hour)
45-
-x EXECUTION_ITERATION, --execution_iteration=EXECUTION_ITERATION
46-
exit after this iteration
47-
```
37+
Utilize the `sage_launcher.sh` script for streamlined execution.
38+
39+
This script encompasses dependency checks, environmental setup, and execution controls in one command.
40+
41+
42+
### Monitoring live with `sage_watcher.sh`
43+
44+
To monitor fuzzing in real-time, run `./sage_watcher.sh` after starting `sage_launcher.sh` in a second terminal tab/window.
45+
46+
![sage_watcher.sh Demo Image](demo.png)
47+
48+
#### Command-Line Options 🔍
49+
50+
- **Browser Selection**: Choose among `--firefox`, `--webkitgtk`, and `--chromium` for targeted fuzzing.
51+
- **Fuzzer Choice**: Select a fuzzer through `--fuzzer` with options including `domato`, `minerva`, `freedom`, `sage`, `favocado`.
52+
- **Clean Start**: Utilize `--kill-old` to terminate existing instances for a fresh testing environment.
53+
- **Resource Management**: Activate the `--watchdog` for intelligent resource monitoring and management.
54+
- **Session Timing**: Control the fuzzing duration with `--timerpurge`, specifying a numeric value for the session limit.
55+
56+
### Examples for Each Browser 🌍
4857

49-
For each kind of browser, we need to set environment variables to specify the path of the target browser and the path of the corresponding webdriver. What follows are the commands for fuzzing WebKit, Chrome, and Firefox:
58+
#### Fuzzing WebKit
5059

51-
### Fuzzing WebKit
60+
For users interested in WebKit, an example WebKit builder is located in the `browserbuilders` folder. Configure environment variables accordingly:
5261

5362
```shell
5463
export WEBKIT_BINARY_PATH="$WEBKIT_PATH/MiniBrowser"
5564
export WEBKIT_WEBDRIVER_PATH="$WEBKIT_PATH/WebKitWebDriver"
56-
# max timeout for each input is 10000 ms, 10 instances are created for parallel, target browser is webkitgtk, fuzzing outputs are save in $PWD/output
57-
python3 main.py -t 10000 -b webkitgtk -p 10 -o $PWD/output
65+
./sage_launcher.sh --webkitgtk 5
5866
```
5967

60-
### Fuzzing Chrome
68+
#### Fuzzing Chrome
69+
70+
Set up Chrome for fuzzing with the following environment variables and execute the script:
6171

6272
```shell
6373
export CHROMIUM_PATH="$C_PATH/chrome"
6474
export CHROMEDRIVER_PATH="$C_PATH/chromedriver"
65-
# max timeout for each input is 10000 ms, 10 instances are created for parallel, target browser is chrome, fuzzing outputs are save in $PWD/output
66-
python3 main.py -t 10000 -b chromium -p 10 -o $PWD/output
75+
./sage_launcher.sh --chromium 5
6776
```
6877

69-
### Fuzzing Firefox
78+
#### Fuzzing Firefox
79+
80+
Prepare Firefox for fuzzing by setting up its environment variables and start the process:
7081

7182
```shell
7283
export FIREFOXDRIVER_PATH="$F_PATH/geckodriver"
7384
export FIREFOX_PATH="$F_PATH/firefox"
74-
# max timeout for each input is 10000 ms, 10 instances are created for parallel, target browser is firefox, fuzzing outputs are save in $PWD/output
75-
python3 main.py -t 10000 -b firefox -p 10 -o $PWD/output
85+
./sage_launcher.sh --firefox 5
7686
```
7787

88+
89+
## DEMO: WebKit Builder Setup 🛠️
90+
91+
The included WebKitGTK Builder Setup script automates the setup process for building WebKitGTK for use with SaGe, and other dependencies.
92+
93+
It simplifies the process with dialog boxes for user input and displays progress in a clean and interactive manner.
94+
95+
96+
![WebKitBuilder Demo Image](webkitbuilder.png)
97+
98+
### Features:
99+
100+
- **Interactive Dialogs**: Utilizes dialog boxes for inputs and displays like welcome message, WebKitGTK version input, and build options.
101+
- **Dynamic Build Options**: Allows selecting various build options through a checklist dialog.
102+
- **Package Installation**: Installs required packages automatically based on the build environment needs.
103+
- **Dependency Management**: Clones and sets up necessary dependencies like libjxl and libbacktrace.
104+
- **Swapfile Management**: Includes functionality to create and remove a swapfile to facilitate builds on systems with limited RAM.
105+
- **Custom Build Commands**: Converts selected build options into commands for cmake and Ninja, facilitating a tailored build process.
106+
107+
### Usage:
108+
109+
1. **Start the Script**: Run the script with `./browser_builders/sage_getwebkit.sh.sh`.
110+
2. **Follow Dialog Prompts**: Input the desired WebKitGTK version, select build options, and proceed through the setup as guided by the dialogs.
111+
3. **Monitor Progress**: The script displays progress in dialog boxes for each step, including package installations and builds.
112+
4. **Completion**: Upon successful completion, the environment will be set up with the selected configurations.
113+
114+
## Academic Contributions 🎓
115+
116+
Our approach and the detailed workings of SaGe are described in a publication accepted by OOPSLA 2023. For enthusiasts and researchers, a Docker environment is available for replicating our experiments, ensuring a seamless experience in understanding the tool's capabilities.
117+
78118
### Fuzzing other browsers
79119

80120
This tool can adapt to any other browsers that are based on the three browsers. Generally speaking, almost all browsers are built on the top of the above three browsers. If users want to test a browser other than the three, they need to implement a subclass of ``FuzzedBrowser`` in the ``browser_adapters`` directory, and register itself in the ``get_browser()`` function of ``browser_selenium.py``.
81121

82122
## Implementation/Configuration Details
83-
- If you don’t want to use Xvfb, set ``export NO_XVFB=true`` before running ``main.py``.
123+
- If you don’t want to use Xvfb, set ``export NO_XVFB=true`` before running ``go.sh``.
84124
- During fuzzing, suppose we set p=2, this means that we create two (almost) separated browser instances, and each of them creates a new tab for handling one fuzzing input. If a browser crashes, the fuzzer will close it and create a new browser instance for testing.
85125
- Browsers may crash because of long-term running. For stability, the fuzzer will close an instance with 1% probability. Users can use ``CLOSE_BROWSER_PROB`` to change this setting. For example, ``export CLOSE_BROWSER_PROB=0.05`` will set the probability to 5%.
86126

@@ -103,6 +143,6 @@ The paper which describes the design detail of this browser fuzzer is accepted b
103143

104144
The artifact of this paper is available at [zenodo](https://doi.org/10.5281/zenodo.8328742), which includes a docker environment for reproducing the experitmental results in the paper. The artifact passed the OOPSLA'23 Artifact Evaluation and earned all badges.
105145

106-
## Acknowledgement
146+
## Acknowledgements 👏
107147

108-
We build the fuzzer on the top of [Domato](https://github.com/googleprojectzero/domato) for input generation.
148+
We extend our heartfelt gratitude to the Domato project, and Google for their foundational input generation techniques, which have significantly contributed to enhancing SaGe's fuzzing methodologies.

0 commit comments

Comments
 (0)