[LINPEAS] Add privilege escalation check: An Evening with Claude (Code) sed-Based ... #522
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔧 Automated Privilege Escalation Check Addition
🤔 Privilege Escalation Reasoning
The blog describes a generic, locally exploitable privilege/persistence pattern that is not tied to highly custom CTF configs or a single obscure product version. The key technique is abusing sed’s file write/read capabilities in constrained-command environments to gain durable code execution via shell startup files:
Abusing sed for arbitrary file write/read:
sed 'w /path/to/file',sed -n '1,1w/path', andsed 'r/path/to/file'. These are normal sed features, not product‑specific bugs.w/rcommands that are missed by simplistic validators, thereby obtaining arbitrary file write and read under the account running the tool.Turning sed file writes into persistent RCE via shell startup files:
~/.zshenv,~/.zprofile,~/.bashrc, etc., so that arbitrary shell code runs whenever a new shell is started.echo 'payload' | sed 'w ~/.zshenv'(or syntactic variants compatible with the local sed implementation).Why this fits linpeas:
worrto dotfiles), which may signal existing compromise.Because this is a generalized method of gaining persistent execution for the current user via widely deployed tools and shell behavior, it is relevant and suitable for linpeas, especially on macOS where BSD sed syntax like
w /pathandr/pathis specifically mentioned, but the logic applies to GNU sed on Linux as well.🤖 Implementation Details
PEASS linpeas agent completed successfully with 125 items. Agent Comment: Summary:
IF_Suspicious_sed_history(linPEAS/builder/linpeas_parts/9_interesting_files/30_Suspicious_sed_history.sh) to hunt for sed commands in every accessible shell-history source (built-ins, PSTORAGE, fallbacks viafind) that usew/rto touch sensitive startup or credential files (.zshenv,.bashrc,.aws/credentials,.ssh/*, etc.). Matches are highlighted so operators can quickly spot Claude-Code-style sed persistence or file-read attempts.IF_Suspicious_startup_payloads(.../31_Suspicious_startup_payloads.sh) which enumerates common per-user and system-wide startup files and flags injected reverse-shell patterns (curl|sh,wget|sh,bash -i >& /dev/tcp,nc -e,ncat -e,socat TCP,python/perl socket stagers, etc.). This surfaces the downstream persistence artifacts that sed-based bypasses typically drop.Testing:
bash -n linPEAS/builder/linpeas_parts/9_interesting_files/30_Suspicious_sed_history.shbash -n linPEAS/builder/linpeas_parts/9_interesting_files/31_Suspicious_startup_payloads.sh🏗️ Builder Agent Response
LinPEAS build agent completed successfully with 71 items. Agent Comment: LinPEAS now builds successfully with the provided command. Here’s what I did:
PSTORAGE_HISTORYpipeline – Created a dedicated variable module (builder/linpeas_parts/variables/PSTORAGE_HISTORY.sh) that inventories readable shell history/startup files and exposes them via$PSTORAGE_HISTORY(and its helper accumulator). This satisfies the dependency for both the legacy “Passwords in history files” check and the new suspicious-history modules.python3 -m builder.linpeas_builder --all --output /tmp/linpeas_fat.shfrom/tmp/hacktricks_update_cld1rqbs/repo/linPEAS, which now completes without errors and produces/tmp/linpeas_fat.sh.Let me know if you’d like any additional validation or changes.
This PR was automatically created by the HackTricks Feed Bot. Please review the implementation carefully and test thoroughly before merging.