Sunday, March 15, 2015

Bash obfuscation

I need to place info in scripts that shouldn't be readily obvious.  This isn't encryption, it's just obfuscation.   Some of the inspiration for this came from random readings of bash manuals and discussions and one part directly from http://www.commandlinefu.com/commands/view/6066/convert-ascii-string-to-hex.  Because of a personal preference to awk, I converted the commands.

To Hide Varables

Run the following command with the command or info you want obscured.


1 ) encode the STRINGTOHIDE

echo "STRINGTOHIDE" | base64 -w 0

U1RSSU5HVE9ISURFCg==

2)  encode the varable

echo -n 'HIDDENVARABLE="`echo U1RSSU5HVE9ISURFCg== | base64 -di`"' | xxd -ps |  awk '{gsub(/[[:xdigit:]]{2}/,"\\x&");print}'
\x48\x49\x44\x44\x45\x4e\x56\x41\x52\x41\x42\x4c\x45\x3d\x22\x60\x65\x63\x68\x6f\x20\x55\x31\x52\x53\x53\x55\x35\x48\x56
\x45\x39\x49\x53\x55\x52\x46\x43\x67\x3d\x3d\x20\x7c\x20\x62\x61\x73\x65\x36\x34\x20\x2d\x64\x69\x60\x22

3)  check it

eval $'\x48\x49\x44\x44\x45\x4e\x56\x41\x52\x41\x42\x4c\x45\x3d\x22\x60\x65\x63\x68\x6f\x20\x55\x31\x52\x53\x53\x55\x35\x48\x56\x45\x39\x49\x53\x55\x52\x46\x43\x67\x3d\x3d\x20\x7c\x20\x62\x61\x73\x65\x36\x34\x20\x2d\x64\x69\x60\x22'

echo $'HIDDENVARABLE'
HIDDENVARABLE


To hide a command,

1)
echo -n 'HIDDENCOMMAND' | xxd -ps | awk '{gsub(/[[:xdigit:]]{2}/,"\\x&");print}'

 echo -n 'ls -lah' | xxd -ps | sed 's/[[:xdigit:]]\{2\}/\\x&/g'
\x6c\x73\x20\x2d\x6c\x61\x68

eval $'\x6c\x73\x20\x2d\x6c\x61\x68'






eval $'hex string'

Friday, March 13, 2015

Simple shell based smtp client... really simple..

I first found email as part of cygwin.   This is a quick and simple tool for sending email.  I use it to send status messages and attaching scheduled reports from shell scripts.  it just works.  no fuss, no local mta setup.

I've installed, it into Ubuntu server, and Raspbian and had it work, as well as using it regularly in Cygwin.  The man page is really thorough.  There are optional config files, but I typically specify everything on the command call, just personal preference.

My quick script for installing dean jone's email program, based on his site. (ok, i added a line to get the parts to compile, otherwise it's his commands to pull and build.  Being that this blog serves as my personal annotated bookmarks, I hope he doesn't mind)


In my scripts, I put the following at the top

email_from_address=some@email.address
email_from_name="someones name"
email_server=address or ip
email_port=a port
email_recipients=someoneelse@email.address,different@server.elsewhere

and then where I want to send email,

echo "
 message here 

white space is sent so layout your message as you want it
to look

great!
" | email -n $email_from_name -f $email_from_address -s "subject" -r
$email_server -p $email_port $email_recipients



that's it..

If bcc is needed, do --bcc before the final recipients list and and a list of recipients