-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_fuzzing.sh
More file actions
executable file
Β·163 lines (148 loc) Β· 4.78 KB
/
Copy pathrun_fuzzing.sh
File metadata and controls
executable file
Β·163 lines (148 loc) Β· 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Local fuzzing script for SuperBOM
set -e
echo "π SuperBOM Fuzzing Runner"
echo "=========================="
# Check if virtual environment exists
if [ ! -d ".venv" ]; then
echo "β Virtual environment not found. Run 'uv sync' first."
exit 1
fi
# Install fuzzing dependencies if not already installed
echo "π¦ Installing fuzzing dependencies..."
uv sync --group fuzzing
# Function to run random fuzzing
run_random() {
local iterations=${1:-200} # Default 200 iterations
echo "π² Running random fuzzing with ${iterations} iterations per function..."
echo " This tests parsers with malformed input data"
uv run python fuzz/fuzz_parsers.py ${iterations}
}
# Function to run Hypothesis fuzzing
run_hypothesis() {
echo "π¬ Running Hypothesis property-based testing..."
uv run python -m pytest fuzz/fuzz_hypothesis.py -v
}
# Function to run both approaches
run_both() {
local iterations=${1:-200}
run_hypothesis
echo ""
run_random ${iterations}
}
# Function to check for Atheris and run if available
run_atheris() {
echo "π Checking for Atheris availability..."
if uv run python -c "import atheris" 2>/dev/null; then
echo "β
Atheris is available!"
local duration=${1:-60}
echo " Running Atheris fuzzing for ${duration} seconds..."
# Create a simple Atheris fuzzer on the fly
cat > temp_atheris_fuzz.py << 'EOF'
import sys
import atheris
import tempfile
from pathlib import Path
sys.path.insert(0, 'src')
from superbom.utils.parsers import parse_requirements
@atheris.instrument_func
def TestOneInput(data):
try:
content = data.decode('utf-8', errors='ignore')
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write(content)
f.flush()
parse_requirements(f.name)
Path(f.name).unlink()
except:
pass
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
EOF
timeout ${duration}s uv run python temp_atheris_fuzz.py -max_total_time=${duration} || {
local exit_code=$?
if [ $exit_code -eq 124 ]; then
echo "β° Atheris fuzzing completed (timeout reached)"
elif [ $exit_code -eq 130 ]; then
echo "βΉοΈ Atheris fuzzing stopped by user"
else
echo "π₯ Atheris found an issue! Exit code: $exit_code"
fi
}
rm -f temp_atheris_fuzz.py
else
echo "β οΈ Atheris not available on this platform"
echo " Install with: pip install atheris (requires clang on some systems)"
echo " Falling back to random fuzzing..."
run_random ${1:-200}
fi
}
# Main menu
case "${1:-interactive}" in
"random")
run_random ${2:-200}
;;
"hypothesis")
run_hypothesis
;;
"atheris")
run_atheris ${2:-60}
;;
"both")
run_both ${2:-200}
;;
"all")
echo "π― Running all fuzzing approaches..."
run_hypothesis
echo ""
run_random ${2:-200}
echo ""
run_atheris ${3:-60}
;;
"interactive"|*)
echo ""
echo "Choose fuzzing method:"
echo "1) Random fuzzing (cross-platform)"
echo "2) Hypothesis property-based testing"
echo "3) Atheris coverage-guided fuzzing (if available)"
echo "4) Both random + hypothesis"
echo "5) All approaches"
echo ""
read -p "Enter choice (1-5): " choice
case $choice in
1)
read -p "Iterations per function (default 200): " iterations
run_random ${iterations:-200}
;;
2)
run_hypothesis
;;
3)
read -p "Duration in seconds (default 60): " duration
run_atheris ${duration:-60}
;;
4)
read -p "Iterations for random fuzzing (default 200): " iterations
run_both ${iterations:-200}
;;
5)
read -p "Iterations for random fuzzing (default 200): " iterations
read -p "Duration for Atheris in seconds (default 60): " duration
echo "π― Running all fuzzing approaches..."
run_hypothesis
echo ""
run_random ${iterations:-200}
echo ""
run_atheris ${duration:-60}
;;
*)
echo "β Invalid choice"
exit 1
;;
esac
;;
esac
echo ""
echo "β
Fuzzing completed!"
echo "π Check for any crash-*, leak-*, or timeout-* files in the current directory"
echo "π Look for potential issues reported in the output above"