Skip to content

Escape shell characters in log-file pipe messages - #898

Closed
tynianov1 wants to merge 1 commit into
nowsecure:masterfrom
tynianov1:log-pipe-escape
Closed

tynianov1 wants to merge 1 commit into
nowsecure:masterfrom
tynianov1:log-pipe-escape

Conversation

@tynianov1

@tynianov1 tynianov1 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Hey @radare ,

When file.log starts with |, every trace message goes to that program through r_sys_cmdf inside double quotes (src/io_frida.c:1915-1916). The message is escaped with r_str_escape, it handles quotes and backslashes but not $ and backticks, so the shell still expands them.

Trace messages carry data from the target, for example the strings :dtr reads from registers (trace.ts:343) or z args in :dtf (trace.ts:543). So if you trace with :e file.log=|tee -a out.txt and the app passes a string like $(id) to the traced function, that command runs on your machine.

This PR uses r_str_escape_sh, it is made for this case and also escapes $, backtick and !. The program now gets newlines, tabs, colors and UTF-8 as they are instead of \n, \t and \xNN text with colors removed, and ! now arrives as \!.

Thanks

trufae pushed a commit that referenced this pull request Oct 30, 2026
The log-file filename came from the agent, which runs inside the target,
so a hostile process could run commands, append to files or open
connections on the host. Track file.log on the host side instead and
feed '|cmd' messages to the program stdin rather than through the shell.

Supersedes #898
@trufae

trufae commented Oct 30, 2026

Copy link
Copy Markdown
Member

this solves part of the problem i was digging deeper and pushed a better fix in master. thank you!

@trufae trufae closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants