Brandon
12-18-2011, 06:26 PM
Hey All.. I have created a plugin that encrypts passwords in simba IF you implement it. It uses an encryption algorithm known as XTEA + Base64 Encoding.
*Sigh* For the commentators below.. If you really think your smart.. Break this.. Come on.. Go ahead and decrypt it:
IMmrAYw6YTmmVf10JN5BsV3/BxEWNGzX
To Find out your encrypted password, you'd use:
writeln(Encrypt('PasswordHere', Key));
The function definition is: Function Encrypt(Password, Key: String): String;
Now for the implementation.. How will Simba decrypt it?
In Simba you'd have to call Decrypt('Encrypted Pass here', 'Key'). It will prompt you for your key IF one is not already stored in the Key.INI file. I had to store it somewhere or else every 6 hours, you'd find yourself entering it again! Of course you can change the location of the stored key.
Example:
What User Sees in the script: Password:= fdsnglskngklanglanith32805235;
What Simba Sees: Password:= Whatever;
http://i.imgur.com/V2DO1.png
http://i.imgur.com/V2DO1.png
Future Development:
The ability to Encrypt Passwords, Usernames and Pins.. IN a selected file..
Instructions For USERS are at the very bottom of this post.. As well as download links.
FOR DEVELOPERS:
Short Example / Test script.
library SSecurity;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, DCPbase64, DCPconst, DCPcrypt2, DCPmd5, StringFuncs,
MufasaTypes, stringutil, Forms, Dialogs, LCLType, Controls, Interfaces, IniFiles, XTea;
{$R *.res}
type
TCharArray = array of Char;
Function StringToCharArray(TheStr: string): TCharArray; register;
var
i, l: Integer;
begin
l := Length(TheStr);
SetLength(Result, l + 1);
for i := l downto 1 do
Result[i - 1] := TheStr[i];
end;
Function CharArrayToString(TheStr: TCharArray): String; register;
var
i, l: Integer;
begin
l := Length(TheStr) - 1;
for i:= 0 To l do
Result := Result + TheStr[i];
end;
Function ToASCII(AChar: char): Integer; register;
begin
result:= ord(AChar);
end;
Function ToChar(AChar: Byte): Char; register;
begin
result:= chr(AChar);
end;
Function DecToBin(Num: Int64): Int64; register;
var
bin, pos: Cardinal;
begin
bin := 0;
pos := 1;
while (Num > 0) do
begin
bin := bin + (Num mod 2) * pos;
Num := Num Div 2;
pos := pos * 10;
end;
Result:= Bin;
end;
Function Encrypt(StrToEncrypt, Key: String): String; register;
begin
Result:= Trim(Base64Encode(XTeaCryptStr(Trim(StrToEncrypt), Key)));
end;
Function Decrypt(StrToDecrypt, Key: String): String; register;
begin
Result:= Trim(XTeaDecryptStr(Base64Decode(Trim(StrToDecrypt )), Key));
end;
Procedure WriteToFile(StrToWrite: String); register;
var
FS: TOpenDialog;
Buffer, FName: String;
F: TFileStream;
begin
FS := TOpenDialog.Create(nil);
FS.Options := [ofFileMustExist];
FS.Filter := ' Simba Scripts (*.simba;*.Simba)|*.simba;*.Simba|All files (*.*)|*.*|';
FS.FilterIndex := 1;
if FS.Execute then
begin
FName:= FS.FileName;
F:= TFileStream.Create(FName, fmOpenReadWrite);
try
F.Position:= 0;
SetLength(Buffer, F.Size);
F.ReadBuffer(Buffer, F.Size);
Finally
F.Free;
end;
F:= TFileStream.Create(FName, fmOpenReadWrite);
try
F.Position:= 0;
Buffer := StringReplace(Buffer, Between('Pass', ';', Buffer), StrToWrite, [rfReplaceAll, rfIgnoreCase]);
F.WriteBuffer(Buffer, Length(Buffer));
writeln(Buffer);
Finally
F.Free;
end;
FS.Free;
end;
end;
{ EXPORTS }
procedure SetPluginMemoryManager(MemMgr : TMemoryManager); stdcall; export;
begin
SetMemoryManager(MemMgr);
end;
{ EXPORT TYPES }
function GetTypeCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
begin
case x of
0: begin
sType := 'TCharArray';
sTypeDef := 'Array of Char;';
end;
else
Result := -1;
end;
end;
{ EXPORT FUNCS }
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 8;
end;
function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
begin
Result := 0;
case x of
0..7 : Result := 1;
end;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @StringToCharArray;
StrPCopy(ProcDef, 'Function StringToCharArray(TheStr: string): TCharArray;');
end;
1:
begin
ProcAddr := @CharArrayToString;
StrPCopy(ProcDef, 'Function CharArrayToString(TheStr: TCharArray): String;');
end;
2:
begin
ProcAddr := @ToASCII;
StrPCopy(ProcDef, 'Function ToASCII(AChar: char): Integer;');
end;
3:
begin
ProcAddr := @ToChar;
StrPCopy(ProcDef, 'Function ToChar(AChar: Byte): Char;');
end;
4:
begin
ProcAddr := @DecToBin;
StrPCopy(ProcDef, 'Function DecToBin(Num: Int64): Int64;');
end;
5:
begin
ProcAddr := @Encrypt;
StrPCopy(ProcDef, 'Function Encrypt(StrToEncrypt, Key: String): String;');
end;
6:
begin
ProcAddr := @Decrypt;
StrPCopy(ProcDef, 'Function Decrypt(StrToDecrypt, Key: String): String;');
end;
7:
begin
ProcAddr := @WriteToFile;
StrPCopy(ProcDef, 'Procedure WriteToFile(StrToWrite: String);');
end;
else
x := -1;
end;
Result := x;
end;
//Exports
exports SetPluginMemoryManager;
//Types
exports GetTypeCount;
exports GetTypeInfo;
//Functions
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;
begin
end.
SOURCE (1.04 MB) For Developers & Curious Minds:
http://www.multiupload.com/FNYX3Y4L25
Plugin Only (1.66 MB):
http://www.multiupload.com/DQHZQH0N4G
Instructions:
Place the Plugin in C:/Simba/Plugins..
*Sigh* For the commentators below.. If you really think your smart.. Break this.. Come on.. Go ahead and decrypt it:
IMmrAYw6YTmmVf10JN5BsV3/BxEWNGzX
To Find out your encrypted password, you'd use:
writeln(Encrypt('PasswordHere', Key));
The function definition is: Function Encrypt(Password, Key: String): String;
Now for the implementation.. How will Simba decrypt it?
In Simba you'd have to call Decrypt('Encrypted Pass here', 'Key'). It will prompt you for your key IF one is not already stored in the Key.INI file. I had to store it somewhere or else every 6 hours, you'd find yourself entering it again! Of course you can change the location of the stored key.
Example:
What User Sees in the script: Password:= fdsnglskngklanglanith32805235;
What Simba Sees: Password:= Whatever;
http://i.imgur.com/V2DO1.png
http://i.imgur.com/V2DO1.png
Future Development:
The ability to Encrypt Passwords, Usernames and Pins.. IN a selected file..
Instructions For USERS are at the very bottom of this post.. As well as download links.
FOR DEVELOPERS:
Short Example / Test script.
library SSecurity;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, DCPbase64, DCPconst, DCPcrypt2, DCPmd5, StringFuncs,
MufasaTypes, stringutil, Forms, Dialogs, LCLType, Controls, Interfaces, IniFiles, XTea;
{$R *.res}
type
TCharArray = array of Char;
Function StringToCharArray(TheStr: string): TCharArray; register;
var
i, l: Integer;
begin
l := Length(TheStr);
SetLength(Result, l + 1);
for i := l downto 1 do
Result[i - 1] := TheStr[i];
end;
Function CharArrayToString(TheStr: TCharArray): String; register;
var
i, l: Integer;
begin
l := Length(TheStr) - 1;
for i:= 0 To l do
Result := Result + TheStr[i];
end;
Function ToASCII(AChar: char): Integer; register;
begin
result:= ord(AChar);
end;
Function ToChar(AChar: Byte): Char; register;
begin
result:= chr(AChar);
end;
Function DecToBin(Num: Int64): Int64; register;
var
bin, pos: Cardinal;
begin
bin := 0;
pos := 1;
while (Num > 0) do
begin
bin := bin + (Num mod 2) * pos;
Num := Num Div 2;
pos := pos * 10;
end;
Result:= Bin;
end;
Function Encrypt(StrToEncrypt, Key: String): String; register;
begin
Result:= Trim(Base64Encode(XTeaCryptStr(Trim(StrToEncrypt), Key)));
end;
Function Decrypt(StrToDecrypt, Key: String): String; register;
begin
Result:= Trim(XTeaDecryptStr(Base64Decode(Trim(StrToDecrypt )), Key));
end;
Procedure WriteToFile(StrToWrite: String); register;
var
FS: TOpenDialog;
Buffer, FName: String;
F: TFileStream;
begin
FS := TOpenDialog.Create(nil);
FS.Options := [ofFileMustExist];
FS.Filter := ' Simba Scripts (*.simba;*.Simba)|*.simba;*.Simba|All files (*.*)|*.*|';
FS.FilterIndex := 1;
if FS.Execute then
begin
FName:= FS.FileName;
F:= TFileStream.Create(FName, fmOpenReadWrite);
try
F.Position:= 0;
SetLength(Buffer, F.Size);
F.ReadBuffer(Buffer, F.Size);
Finally
F.Free;
end;
F:= TFileStream.Create(FName, fmOpenReadWrite);
try
F.Position:= 0;
Buffer := StringReplace(Buffer, Between('Pass', ';', Buffer), StrToWrite, [rfReplaceAll, rfIgnoreCase]);
F.WriteBuffer(Buffer, Length(Buffer));
writeln(Buffer);
Finally
F.Free;
end;
FS.Free;
end;
end;
{ EXPORTS }
procedure SetPluginMemoryManager(MemMgr : TMemoryManager); stdcall; export;
begin
SetMemoryManager(MemMgr);
end;
{ EXPORT TYPES }
function GetTypeCount(): Integer; stdcall; export;
begin
Result := 1;
end;
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
begin
case x of
0: begin
sType := 'TCharArray';
sTypeDef := 'Array of Char;';
end;
else
Result := -1;
end;
end;
{ EXPORT FUNCS }
function GetFunctionCount(): Integer; stdcall; export;
begin
Result := 8;
end;
function GetFunctionCallingConv(x : Integer) : Integer; stdcall; export;
begin
Result := 0;
case x of
0..7 : Result := 1;
end;
end;
function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; export;
begin
case x of
0:
begin
ProcAddr := @StringToCharArray;
StrPCopy(ProcDef, 'Function StringToCharArray(TheStr: string): TCharArray;');
end;
1:
begin
ProcAddr := @CharArrayToString;
StrPCopy(ProcDef, 'Function CharArrayToString(TheStr: TCharArray): String;');
end;
2:
begin
ProcAddr := @ToASCII;
StrPCopy(ProcDef, 'Function ToASCII(AChar: char): Integer;');
end;
3:
begin
ProcAddr := @ToChar;
StrPCopy(ProcDef, 'Function ToChar(AChar: Byte): Char;');
end;
4:
begin
ProcAddr := @DecToBin;
StrPCopy(ProcDef, 'Function DecToBin(Num: Int64): Int64;');
end;
5:
begin
ProcAddr := @Encrypt;
StrPCopy(ProcDef, 'Function Encrypt(StrToEncrypt, Key: String): String;');
end;
6:
begin
ProcAddr := @Decrypt;
StrPCopy(ProcDef, 'Function Decrypt(StrToDecrypt, Key: String): String;');
end;
7:
begin
ProcAddr := @WriteToFile;
StrPCopy(ProcDef, 'Procedure WriteToFile(StrToWrite: String);');
end;
else
x := -1;
end;
Result := x;
end;
//Exports
exports SetPluginMemoryManager;
//Types
exports GetTypeCount;
exports GetTypeInfo;
//Functions
exports GetFunctionCount;
exports GetFunctionInfo;
exports GetFunctionCallingConv;
begin
end.
SOURCE (1.04 MB) For Developers & Curious Minds:
http://www.multiupload.com/FNYX3Y4L25
Plugin Only (1.66 MB):
http://www.multiupload.com/DQHZQH0N4G
Instructions:
Place the Plugin in C:/Simba/Plugins..