• 0 Posts
  • 22 Comments
Joined 1 year ago
cake
Cake day: June 13th, 2023

help-circle





  • even in your hypothetical of a file name passed in through the args, either the attacker has enough access to run said tool with whatever args they want, or, they have taken over that process and can inject whatever args they want.

    either attack vector requires a prior breach of the system. you’re owned either way.

    the only way this actually works as an exploit is if there are poorly written services out there that blindly call through to CreateProcess that take in user sourced input without any sanitization, which if you’re doing that then no duh you’re gonna have a bad time.

    cmd.exe is always going to be invoked if you’re executing a batch script, it’s literally the interpreter for .bat files. the issue is, as usual, code that might be blindly taking user input and not even bothering to sanitize it before using it.















  • assuming you have a GNU toolchain you can use the find command like so:

    find . -type f -executable -exec sh -c '
    case $( file "$1" ) in (*Bourne-Again*) exit 0; esac
    exit 1' sh {} \; -print0 | xargs -0 -I{} cp {} target/
    

    This first finds all executable files in the current directory (change the “.” arg in find to search other dirs), uses the file command to test if it’s a bash file, and if it is, pipes the file name to xargs which calls cp on each file.

    note: if “target” is inside the search directory you’ll get output from cp that it skipped copying identical files. this is because find will find them a free you copy them so be careful!

    note 2: this doesn’t preserve the directory structure of the files, so if your scripts are nested and might have duplicate names, you’ll get errors.