Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

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

Saturday, September 28, 2013

A NAS with a Raspberry Pi: Part 1 - the drives

First, this isn't going to be linux standard.  I have constraints, 1)  NTFS formatted external drives, 2) only one partition per physical drive, and 3) a mixed OS network.


my steps:

1) upgrade everything first. optional, but it's my preference

sudo apt-get update && sudo apt-get upgrade && sudo reboot

2) install ntfs drivers.

sudo apt-get install ntfs-3g

3) find my external drive 

sudo fdisk -l

gives info including :

  Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880    62333951    31105536   83  Linux

 

and 

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048  1953523711   976760832    7  HPFS/NTFS/exFAT


The last one is my external drive.  

4) find the serial for the drive

sudo udevadm info -a -q all -p $(udevadm info -q path -n /dev/sda1)
 

yields:

E: ID_SERIAL=ST31000528AS_9VP500HC

which becomes 

ENV{ID_SERIAL}="ST31000528AS_9VP500HC "

which is important, especially as I'm using two identical drive models. the serial the cleanest way to differentiate between them.


ls -l /dev/disk/by-uuid

gives (among others)

lrwxrwxrwx 1 root root 10 Jan  1  1970 7420568A205652EA -> ../../sda1
 



create "/home/81-external-drive1.rules"




copy it to /etc/udev/rules.d/81-external-drive1.rules

5) restart udev


sudo /etc/init.d/udev restart 

6) mnt/drive1 should exist and be browsable

7) reboot 

sudo reboot

8) should still be browsable 

9) repeat for drive2.

Wednesday, June 19, 2013

Clone Cygwin packages.

I've come to depend on having a specific set of cygwin packages installed when working on systems.  The simple way to make sure it has what I expect is to install it.



I set this up to run regularly, which is why the filenames are timestamped.

Credit for inspiration to use /etc/setup/installed.db goes to http://cygwin.com/ml/cygwin/2011-09/msg00079.html

xmission is one of the closest sites, pick the appropriate one for you at http://cygwin.com/mirrors.html

Monday, June 17, 2013

Windows Explorer to current Bash prompt

There are times when it's just faster to do some things from Windows Explorer, than from Bash.  I know, this is sacrilegious to say, but it's usually when doing Windows specific things, so give me a pass here.

I've seen many ways to do this, but I'm partial to this way. 

I used nano to save this file to /bin/x, chmod 700 and done.

It's small and simple.

Unix philosophy anyone?

Friday, March 22, 2013

Colorize ls - cygwin Tweak #1

My cygwin tweek #1 can be added a number of places, but I typically add to /etc/profile because it's set for every user.

Thursday, April 12, 2012

Monday, April 9, 2012

Mult-file rename.

for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done

From: http://snipplr.com/view/2736/