Skip to content

Commit b1a2eef

Browse files
authored
Update 4_Capabilities.sh (#629)
1 parent 53973a2 commit b1a2eef

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

linPEAS/builder/linpeas_parts/8_interesting_perms_files/4_Capabilities.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ if ! [ "$SEARCH_IN_FOLDER" ]; then
1818
print_2title "Capabilities" "T1548.001"
1919
print_info "https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/index.html#capabilities"
2020
if [ "$(command -v capsh || echo -n '')" ]; then
21+
is_hex_cap_value() {
22+
case "$1" in
23+
""|*[!0-9a-fA-F]*)
24+
return 1
25+
;;
26+
esac
27+
return 0
28+
}
29+
2130
print_3title "Current shell capabilities" "T1548.001"
2231
cat "/proc/$$/status" | grep Cap | while read -r cap_line; do
2332
cap_name=$(echo "$cap_line" | awk '{print $1}')
@@ -26,7 +35,7 @@ if ! [ "$SEARCH_IN_FOLDER" ]; then
2635
# Add validation check for cap_value
2736
# For more POSIX-compliant formatting, the following could be used instead:
2837
# if echo "$cap_value" | grep -E '^[0-9a-fA-F]+$' > /dev/null 2>&1; then
29-
if [[ "$cap_value" =~ ^[0-9a-fA-F]+$ ]]; then
38+
if is_hex_cap_value "$cap_value"; then
3039
# Memory errors can occur with certain values (e.g., ffffffffffffffff)
3140
# so we redirect stderr to prevent error propagation
3241
echo "$cap_name $(capsh --decode=0x"$cap_value" 2>/dev/null | sed -${E} "s,$capsB,${SED_RED_YELLOW},")"
@@ -35,7 +44,7 @@ if ! [ "$SEARCH_IN_FOLDER" ]; then
3544
fi
3645
else
3746
# Add validation check for cap_value
38-
if [[ "$cap_value" =~ ^[0-9a-fA-F]+$ ]]; then
47+
if is_hex_cap_value "$cap_value"; then
3948
# Memory errors can occur with certain values (e.g., ffffffffffffffff)
4049
# so we redirect stderr to prevent error propagation
4150
echo "$cap_name $(capsh --decode=0x"$cap_value" 2>/dev/null | sed -${E} "s,$capsB,${SED_RED},")"
@@ -51,7 +60,7 @@ if ! [ "$SEARCH_IN_FOLDER" ]; then
5160
cap_value=$(echo "$cap_line" | awk '{print $2}')
5261
if [ "$cap_name" = "CapEff:" ]; then
5362
# Add validation check for cap_value
54-
if [[ "$cap_value" =~ ^[0-9a-fA-F]+$ ]]; then
63+
if is_hex_cap_value "$cap_value"; then
5564
# Memory errors can occur with certain values (e.g., ffffffffffffffff)
5665
# so we redirect stderr to prevent error propagation
5766
echo "$cap_name $(capsh --decode=0x"$cap_value" 2>/dev/null | sed -${E} "s,$capsB,${SED_RED_YELLOW},")"
@@ -60,7 +69,7 @@ if ! [ "$SEARCH_IN_FOLDER" ]; then
6069
fi
6170
else
6271
# Add validation check for cap_value
63-
if [[ "$cap_value" =~ ^[0-9a-fA-F]+$ ]]; then
72+
if is_hex_cap_value "$cap_value"; then
6473
# Memory errors can occur with certain values (e.g., ffffffffffffffff)
6574
# so we redirect stderr to prevent error propagation
6675
echo "$cap_name $(capsh --decode=0x"$cap_value" 2>/dev/null | sed -${E} "s,$capsB,${SED_RED},")"

0 commit comments

Comments
 (0)