This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Encrypt

Help for those learning Tcl or writing their own scripts.
m
micky
Voice
Posts: 11
Joined: Mon Dec 13, 2004 10:07 am

Encrypt

Post by micky »

Some of you know how encrypt tcl? (http://mini.net/tcl/728)
Maybe some of you would be so kind and tell me how i can encrypt scripts or how to use obfuscation.
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

why would you want to encrypt a script?
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

you can compile your script with TclPro, it will produce a .tbc file which has a little loader header in clear Tcl (which of course depends on external library - libtbcload) and the rest is compiled bytecode stuff, similar to that in Java .class files (needless to say, there are .tbc decompilers, I hear user wrote one ;) so your script will never be safe from cracking)
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

alternatively, if you need script encryption as a preventive measure against peeking at your files on the shell, you can store your scripts encrypted with a key (of course, you'll need to patch your bot to be able to load those scripts)
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

hmm i don't see the point using tcl as an ecrypter knowning that.. if you read the script that is gone encrypt it that it can be used to decrypt it ..

you will need to write a module to encrypt it .. when its compiled you can use a key or something which can't be read from the binary file.. when it is compiled .. well everything is possible if you know how but still its gone be a hard and for sur when you use hex chars .. to hide that code .. or encrypt the variables within the c code..
XplaiN but think of me as stupid
m
micky
Voice
Posts: 11
Joined: Mon Dec 13, 2004 10:07 am

Post by micky »

User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

micky wrote:no, no, i need crypt like that http://www.tclshack.com/modules.php?op= ... tit&lid=22
lame and primitive obfuscation scriptlet, presumably hiding even lamer script (hard-coded parsing of HTML, will stop working when they change the webpage)
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

micky wrote:no, no, i need crypt like that http://www.tclshack.com/modules.php?op= ... tit&lid=22
i think i understand verry well what you wana do you wana encrypt the script so its only readable to the module..

you wana hide the script source ..

then if you wana do that you need a module not a script a module can decrypt or crypt a script you load the crypt into memory then decrypt it.. thats how u can do it .. and eval the code.. in the variable .. but making this work you should use a C module cause if you use a tcl script then there is no use crypting it .. you will be able to read how to decrypt it from the script cause the encrypter or decrypter still will be open source if you use a tcl script to crypt or decrypt it !!!!!

or do you mean a script that decrypts encrypted text that passes by in a channel ??
XplaiN but think of me as stupid
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

try saying that after a few pints Ofloo :lol:
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Maybe a bit too late... :)

Post by user »

this is a slightly modified version of my code from this post...

Code: Select all

# turn a string into random (octal/hexadecimal/unicode) escapes
proc lamesc str {
	set o ""
	foreach c [split $str ""] {
		if {[string is space $c]} {
			append o $c
		} {
			append o [switch [expr {int(rand()*3)}] {
				0 {format \\%o [scan $c %c]}
				1 {format \\x%x [scan $c %c]}
				2 {format \\u%x [scan $c %c]}
			}]
		}
	}
	set o
}

# obfuscate a piece of code
proc obfuscate code {
	foreach c [split $code ""] {set tmp($c) ""}
	set chrs [array names tmp]
	set i [array size tmp]
	set forward [set back [list]]
	foreach c $chrs {
		set r [expr {int(rand()*$i)}]
		incr i -1
		lappend forward $c [lindex $chrs $r]
		set back [concat [list [lindex $chrs $r] $c] $back]
		set chrs [lreplace $chrs $r $r]
	}
	switch [expr {int(rand()*3)}] {
		0 {set cmd "if [expr {1+int(rand()*(1<<24))}]"}
		1 {set cmd eval}
		2 {set cmd "uplevel 0"}
	}
	set code "[lamesc $cmd] \[[lamesc "string map"] [list $back [string map $forward $code]]\]"
}

# obfuscate everything between #OBF and #/OBF in one file and dump the result to another file
proc OBF {infile {outfile {}} {A "#OBF\n"} {B "\n#/OBF\n"}} {
	set i [set c 0]
	set j [string len $A]
	set k [string len $B]
	set data [read [set f [open $infile]]][close $f]
	if {$outfile=={}} {set f [open $infile w]} {set f [open $outfile w]}
	while {
		[set a [string first $A $data $i]]>-1
						&&
		[set b [string first $B $data $a]]>-1
	} {
		puts -nonewline $f [string range $data $i [expr {$a-1}]]
		puts $f [obfuscate [string range $data [incr a $j] [expr {$b-1}]]]
		set i [expr {$b+$k}]
		incr c
	}
	puts -nonewline $f [string range $data $i end]
	close $f
	set c
}

# look for command line parameters and invoke OBF if there are any
if $argc {
	if {[catch [concat OBF $argv] err]} {
		puts $err
	} else {
		puts "$err part[expr {$err==1?"":"s"}] obfuscated."
	}
	exit
}
source the script and invoke the procs you want
...or save it to a file and do 'tclsh file input.tcl output.tcl' in your shell (will run the OBF proc on input.tcl and write the result to output.tcl)

Example:

Code: Select all

proc demobf args {
#OBF
	return "Hello world"
#/OBF
}
...was turned into the beautiful code below by OBF

Code: Select all

proc demobf args {
\x75\u70\154\u65\u76\145\u6c \60 [\163\x74\x72\151\u6e\147 \x6d\141\160 {o o r n e l d {	} n H w w {	} u t e H t {"} d u {"} l r { } { }} {dltH	lr unteeo wole"u}]
}
Using it to obfuscate only the body of a proc, like I did here, is not recommended.
Have you ever read "The Manual"?
m
mm
Halfop
Posts: 78
Joined: Thu Jul 01, 2004 10:24 pm

Post by mm »

Hi,
demond
alternatively, if you need script encryption as a preventive measure against peeking at your files on the shell, you can store your scripts encrypted with a key (of course, you'll need to patch your bot to be able to load those scripts)


demond, where can i find a patch?

thanks
MM
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

mm wrote:Hi,
demond
alternatively, if you need script encryption as a preventive measure against peeking at your files on the shell, you can store your scripts encrypted with a key (of course, you'll need to patch your bot to be able to load those scripts)


demond, where can i find a patch?

thanks
I don't believe you'll find such a patch available publicly; after all, the whole point of that is to conceal how the actual encryption (respectivelly decryption/loading) is done, in order to prevent potential crackers/takeover monkeys from patching your scripts (or at least to make their task harder; if they want your channel really bad and have some skills, they'd crack the bot binary anyway; besides, there are other methods for hacking ops from encrypted bot, such as connection hijacking, using ptrace() to attach to & control bot's process, etc.)

I once wrote similar patch for eggdrop 1.4, but it's not much of a use today anyway
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

User, how would you go about deobfuscating that script you obfuscate with your code so you can actually use it? :p
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

just run it :P
Have you ever read "The Manual"?
l
lsn
Voice
Posts: 25
Joined: Mon Jul 19, 2004 8:11 am

Post by lsn »

I write that code into a file named tcl
I run the code:

Code: Select all

tclsh8.4 tcl x.tcl z.tcl
I get this
0 parts obfuscated.
And the file z.tcl was identical with x.tcl, nothing has changed.. What goes wrong ?
Post Reply