Deploy a .zip from a .sh

Sonic84
Contributor III

Hello, it's possible to hide a .zip archive within a .sh text file. This is a old trick, but still comes in handy every now again. I had to use it today to meet a goal, so I though I'd post this for others while its fresh in my mind.

Start off with a regular bash script and some code to deploy the embedded file.

#!/bin/sh

echo "deploying image.zip"

# this code tails the encoded .zip when the script is run. for example I have created a .zip with Install.png, which I extract to tmp. 
SKIPTO=`awk '/^__ARCHIVE__/ { print NR + 1; exit 0; }' $0`
tail +$SKIPTO "$0" > /tmp/Install.zip
unzip -j -o /tmp/Install.zip -d /tmp

mv /tmp/Install.png /User/Shared/
echo "all done"
exit 0

__ARCHIVE__

The extra return after "ARCHIVE" is important.

Next, create a zip file in Finder. In the example above, I right clicked on Install.png on my Desktop and selected "compress". But it can be anything: DMG, IMG, ics, unix binary, etc....

Now we need to get the .zip into the script.

Use this command in terminal to append the zip to the script:
cat /path/to/Install.zip >> /path/to/script.sh

And we're done. The script has been charged with the .zip and is ready to go. Opening the script in a text editor will produce errors, because it mixed ascii and encoded text. BASH doesn't seem to care when the script is executed.

Hope this helps!

3 REPLIES 3

donmontalvo
Esteemed Contributor III

Autonomy does this with their Connected Backup installer. Ha, I thought they were high, I guess they meant to do it. :)

--
https://donmontalvo.com

JPDyson
Valued Contributor

Doesn't ePO do some such thing with its installer? Not sure when I'd use it personally, but it's a neat tool to have in the bag.

nkalister
Valued Contributor

@JP- yep, if you export the Mcafee agent installer from your epo, you get a 15 MB shell script with the agent DMG embedded as a zip file in the script.