Jump to content

Perl to PHP Conversion Help


Lectrician

Recommended Posts

The below code is taken from my perl forums code.  The code decloaks a formsession string sent as a hidden form element.

 

It works fine to verify the form in Perl, but when I try to convert it to PHP I get errors conflicting outputs which are coming from the two lines below:

 

$key = hex($hexkey);

(PERL)

 

$key = dechex($hexkey);

(PHP)

or

$key = bin2hex($hexkey);

(PHP)

 

The Perl line above gives a different result to the PHP line(s).

 

I have managed to convert down to this line from the top.

 

Any help in figuring out why the perls HEX command varies from the PHP DECHEX command would be great!  Also any pointers in converting from there downwards!  (I know perls LENGTH is PHP STRLEN, and can sort the for loop).

 

Thanks in advance for any help!

 

 

$input = $_POST["formsession"];

if ($input !~ /\A[0-9A-F]+\Z/) {return $input; } # probably a non cloacked ID as it contains non hex code

$input =~ s~0$~~;
$hexkey = substr($input,length($input)-2,2);
$key = hex($hexkey);
for($n=0; $n < length($input)-2; $n += 2) {
$dec = substr($input, $n, 2);
$ascii = hex($dec) ^ $key; # xor it to reverse it
$ascii = chr($ascii);
$user .= $ascii;
return $user;

Link to comment
https://forums.phpfreaks.com/topic/154875-perl-to-php-conversion-help/
Share on other sites

The input is something like this

"6D5F470C7844490C785E4D48495F60494F585E454F454D422C"

 

It is a couple of the boards systemwide variables cloaked into hex code.  (that is hex code isn't it?).

 

The code above should decloak this into binary which would reveal the systemwide variables.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.