Skip to content

Commit ef28ef7

Browse files
committed
fix linpeas not getting EC2 metadata
1 parent 58c107d commit ef28ef7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

linPEAS/builder/linpeas_parts/3_cloud/2_AWS_EC2.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
if [ "$is_aws_ec2" = "Yes" ]; then
1717
print_2title "AWS EC2 Enumeration"
1818

19-
HEADER="X-aws-ec2-metadata-token: "
19+
TOKEN=""
20+
TOKEN_HEADER="X-aws-ec2-metadata-token"
21+
TOKEN_TTL="X-aws-ec2-metadata-token-ttl-seconds: 21600"
2022
URL="http://169.254.169.254/latest/meta-data"
2123

2224
aws_req=""
2325
if [ "$(command -v curl || echo -n '')" ]; then
24-
aws_req="curl -s -f -L -H '$HEADER'"
26+
# Get token for IMDSv2
27+
TOKEN=$(curl -s -f -X PUT "http://169.254.169.254/latest/api/token" -H "$TOKEN_TTL" 2>/dev/null)
28+
aws_req="curl -s -f -L -H '$TOKEN_HEADER: $TOKEN'"
2529
elif [ "$(command -v wget || echo -n '')" ]; then
26-
aws_req="wget -q -O - --header '$HEADER'"
30+
# Get token for IMDSv2
31+
TOKEN=$(wget -q -O - --method=PUT --header="$TOKEN_TTL" "http://169.254.169.254/latest/api/token" 2>/dev/null)
32+
aws_req="wget -q -O - --header '$TOKEN_HEADER: $TOKEN'"
2733
else
2834
echo "Neither curl nor wget were found, I can't enumerate the metadata service :("
2935
fi

linPEAS/builder/linpeas_parts/functions/execBin.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ execBin() {
3131

3232
# ---------------- 120‑second wall‑clock timeout ----------------
3333
if command -v timeout >/dev/null 2>&1; then # GNU/BSD timeout
34-
print_info "Running $TOOL_NAME with 120s timeout"
3534
timeout --preserve-status -s 9 120 "$TMP_BIN" $PARAMS
3635
elif command -v gtimeout >/dev/null 2>&1; then # Homebrew coreutils (macOS)
37-
print_info "Running $TOOL_NAME with 120s gtimeout"
38-
gtimeout --preserve-status 120 "$TMP_BIN" $PARAMS
36+
gtimeout --preserve-status -s 9 120 "$TMP_BIN" $PARAMS
3937
else # POSIX fall‑back
40-
print_info "Running $TOOL_NAME with 120s custom timeout"
4138
(
4239
"$TMP_BIN" $PARAMS & # run in background
4340
cmdpid=$!

0 commit comments

Comments
 (0)