Created
November 20, 2009 07:14
-
-
Save phred/239337 to your computer and use it in GitHub Desktop.
Lasso functions to decode and decrypt a FoxyCart datafeed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
Define_Tag('Decode_Raw', -Required='input'); | |
Local('output' = bytes()); | |
Local('ndx' = 1); | |
While(#ndx < #input->Length); | |
if(#input->Get(#ndx) == '%'); | |
local: 'byte' = string(#input->Substring(#ndx+1, 2)); | |
#output->Import8Bits(16 * #byte->digit(1, 16) + 1 * #byte->digit(2, 16)); | |
#ndx += 2; // Consume 2 hex digits | |
else: | |
#output->ImportString(#input->Get(#ndx), 'ascii'); | |
/if; | |
#ndx += 1; | |
/While; | |
Return(#output); | |
/Define_Tag; | |
Define_Tag('rc4_decrypt', -Required='data', -Required='pwd'); | |
local: 'key' = bytes(); | |
local: 'box' = bytes(); | |
local: 'cipher' = bytes(); | |
local: 'pwd' = bytes(#pwd); | |
local: 'pwd_length' = #pwd->Length; | |
local: 'data_length' = #data->Length; | |
local: 'i' = 0; | |
While (#i < 256); /* for ($i = 0; $i < 256; $i++) */ | |
#key->Append(#pwd->GetRange(1 + (#i % #pwd_length), 1)); /* $key[$i] = ord($pwd[$i % $pwd_length]); */ | |
#box->Import8Bits(#i); /* $box[$i] = $i; */ | |
#i += 1; | |
/While; | |
local: 'i' = 0; | |
local: 'j' = 0; | |
local: 'out' = ''; | |
While (#i < 256); /* for ($j = $i = 0; $i < 256; $i++) */ | |
#j = ((#j + #box->Get(1 + #i) + #key->Get(1 + #i)) % 256); /* $j = ($j + $box[$i] + $key[$i]) % 256;*/ | |
local: 'tmp' = #box->GetRange(1 + #i, 1); /* $tmp = $box[$i]; */ | |
#box->SetRange(1 + #i, #box->GetRange(1 + #j, 1)); /* $box[$i] = $box[$j]; */ | |
#box->SetRange(1 + #j, #tmp); /* $box[$j] = $tmp; */ | |
#i += 1; | |
/While; | |
local: 'a' = 0; | |
local: 'j' = 0; | |
local: 'i' = 0; | |
While (#i < #data_length); /* for ($a = $j = $i = 0; $i < $data_length; $i++) */ | |
#a = (#a + 1) % 256; /* $a = ($a + 1) % 256; */ | |
#j = ((#j + #box->Get(1 + #a)) % 256); /* $j = ($j + $box[$a]) % 256; */ | |
local: 'tmp' = #box->GetRange(1 + #a, 1); /* $tmp = $box[$a]; */ | |
#box->SetRange(1 + #a, #box->GetRange(1 + #j, 1)); /* $box[$a] = $box[$j]; */ | |
#box->SetRange(1 + #j, #tmp); /* $box[$j] = $tmp; */ | |
local: 'k' = #box->Get(1 + (((#box->Get(1 + #a) + #box->Get(1 + #j)) % 256))); /* $k = $box[(($box[$a] + $box[$j]) % 256)]; */ | |
local: 'data_byte' = #data->Get(1 + #i); | |
#data_byte->BitXOr(#k); | |
#cipher->Import8Bits(#data_byte); /* $cipher .= chr(ord($data[$i]) ^ $k); */ | |
#i += 1; | |
/While; | |
Return(#cipher->ExportString('UTF-8')); | |
/Define_Tag; | |
include('bitformat.lasso'); | |
var('test_raw') = action_param('foxydata'); | |
var('test') = $test_raw; | |
'the data is: '; | |
$test; | |
'<br /><br /><br />'; | |
'<br /><br /><br />'; | |
'decoded:<br/>'; | |
$test = Decode_Raw($test); | |
$test; | |
'<br /><br /><br />'; | |
var('mykey')='qRaNP5H1RXQlPub6ptI4Nk3JFXTJFdgVUhDzgfuX8adMzfNNymLgyEV8wIH2'; | |
var('foxy_sent')=rc4_decrypt: -data=$test, -pwd=$mykey; | |
'Here\'s what foxy sent:<br />'; | |
$foxy_sent; | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment