Welcome, guest | Sign In | My Account | Store | Cart

IMO, the immense power of the shell...

Please let me know if there is any other human readable language that can do this...

The DEMO code below was an idea I formed to see how to make a bash script very difficult to hack.

Everything in it is made easy to read so as to see this idea working.

It uses bash variables ONLY and although I have used bash loops to create the variables in this DEMO you could create your own set of variables and 'source' them to the the obfuscated code before running the main body of the code.

It also goes without saying that you could obfuscate the changing of any or all the variable allocations at any time AFTER the code runs to make it even more obfuscated and as may times as you wish...

I would be seriously difficult to actually write a lsrge bash app' using this method but boy oh boy would it be fun?!?

Testbed:- Macbook Pro, OSX 10.7.x and above, using default bash terminal...

LBNL, yeah I am aware of 'eval' but as it is obfuscated and can have as many obfuscated variables as I wish allocated to it then why worry... ;o)

Enjoy finding simple solutions to often very difficult problems...

Bazza...

Bash, 41 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#/bin/bash
# (strings.sh)
# obfuscate.sh
# OSX 10.7.5, default bash terminal.
for n in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
	eval A$n="$n"
done
for n in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
do
	eval A$n="$n"
done
num=0
for n in a b c d e f g h i j
do
	eval B$n="$num"
	num=$((num+1))
done
Bk=' ';Bl='!';Bm='"';Bn='#';Bo='$';Bp='%';Bq='&';Br="'"
Bs='(';Bt=')';Bu='*';Bv='+';Bw=',';Bx='-';By='.';Bz='/'
Ca=':';Cb=';';Cc='<';Cd='=';Ce='>';Cf='?';Cg='@';Ch='['
Ci='\';Cj=']';Ck='^';Cl='_';Cm='`';Cn='{';Co='|';Cp='}'
Cq='~'
# A program using $string format only...
#
# clear
$Ac$Al$Ae$Aa$Ar
# eval name=""
$Ae$Av$Aa$Al$Bk$An$Aa$Am$Ae$Cd$Bm$Bm
# eval age=""
$Ae$Av$Aa$Al$Bk$Aa$Ag$Ae$Cd$Bm$Bm
# eval printf "Enter your full name:-\n"
$Ae$Av$Aa$Al$Bk$Ap$Ar$Ai$An$At$Af$Bk$Bm$AE$An$At$Ae$Ar$Bk$Ay$Ao$Au$Ar$Bk$Af$Au$Al$Al$Bk$An$Aa$Am$Ae$Ca$Bx$Ci$An$Bm
# read name
$Ar$Ae$Aa$Ad$Bk$An$Aa$Am$Ae
# eval printf "Enter your age:-\n"
$Ae$Av$Aa$Al$Bk$Ap$Ar$Ai$An$At$Af$Bk$Bm$AE$An$At$Ae$Ar$Bk$Ay$Ao$Au$Ar$Bk$Aa$Ag$Ae$Ca$Bx$Ci$An$Bm
# read age
$Ar$Ae$Aa$Ad$Bk$Aa$Ag$Ae
# eval printf "Hi Barry Walker, you are 63 years old.\n"
$Ae$Av$Aa$Al$Bk$Ap$Ar$Ai$An$At$Af$Bk$Bm$AH$Ai$Bk$name$Bw$Bk$Ay$Ao$Au$Bk$Aa$Ar$Ae$Bk$age$Bk$Ay$Ae$Aa$Ar$As$Bk$Ao$Al$Ad$By$Ci$An$Bm

Making a bash script difficult to read...

Results on the above platform:-

""" Last login: Fri Dec 19 18:34:41 on ttys000 AMIGA:barrywalker~> cd Desktop AMIGA:barrywalker~/Desktop> cd Code AMIGA:barrywalker~/Desktop/Code> cd Shell AMIGA:barrywalker~/Desktop/Code/Shell> chmod 755 obfuscate.sh AMIGA:barrywalker~/Desktop/Code/Shell> ./obfuscate.sh

Note the screen is cleared here...

Enter your full name:- Barry Walker Enter your age:- 64 Hi Barry Walker, you are 64 years old. AMIGA:barrywalker~/Desktop/Code/Shell> _ """

2 comments

Barry Walker (author) 9 years, 3 months ago  # | flag

Apologies for the bad layout directly above I assumed plain text would be just that... :o/

Steve Parker 8 years, 7 months ago  # | flag

So I change line 25 to read "cat - << EOF", and add "EOF" at the end of the file, and execute the script to view the un-obfuscated code.

Created by Barry Walker on Fri, 19 Dec 2014 (MIT)
Bash recipes (41)
Barry Walker's recipes (73)

Required Modules

  • (none specified)

Other Information and Tasks