Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php echo "d\x65f\x69\x6ee(\x27SQ\x4cTOKE\x4e\x27, '|\x27)\x3b\ndef\x69n\x65('C\x53\x56\x..
Decoded Output download
define('SQLTOKEN', '|');
define('CSV_TOK', ';');
// CP850 TO ISO
function _conv(\$value) {
return iconv('CP850', 'ISO-8859-15', \$value);
}
function _to_ansi(\$value) {
//return iconv('UTF-8', 'ANSI', \$value);
return utf8_decode(\$value);
}
function sql_exec(\$db, \$sql) {
\$ret = array();
// -u -> Unicode
// -f 850 -> CP850 (Codepage), check this with 'chcp' in cmd.exe
\$pd = popen('sqlcmd -S '.SERVER.' -d '.\$db.' -U '.USER.' -P '.PASS.' -W -u -f 850 -Q "'.\$sql.'" -s "'.SQLTOKEN.'"', 'r');
while(!feof(\$pd)) {
\$ret[] = fgets(\$pd);
}
pclose(\$pd);
return \$ret;
}
\$conf = parse_ini_file(__DIR__.'\config.ini');
// validate date
\$start = strtotime(\$conf['start']);
if(!\$start) {
echo 'FEHLER: Startzeit kann nicht gelesen werden, bitte verwende folgendes Format: dd.mm.YYY (31.12.2016), Abbruch!'.PHP_EOL;
exit();
}
\$start = date('Y-d-m',\$start);
\$ende = strtotime(\$conf['ende']);
if(!\$ende) {
echo 'FEHLER: Endezeit kann nicht gelesen werden, bitte verwende folgendes Format: dd.mm.YYY (31.12.2016), Abbruch!'.PHP_EOL;
exit();
}
\$ende = date('Y-d-m',\$ende);
\$query = 'SET NOCOUNT ON;'.
'SELECT Artikel.cArtNr as cArtNr, Bestellpos.nAnzahl as nAnzahl, Bestellung.dErstellt as dErstellt, Bestellung.cBestellNr as cBestellNr '.
'FROM [dbo].[tbestellpos] AS Bestellpos '.
'INNER JOIN [dbo].[tBestellung] AS Bestellung ON Bestellpos.tBestellung_kBestellung = Bestellung.kBestellung '.
'INNER JOIN [dbo].[tArtikel] AS Artikel ON Bestellpos.tArtikel_kArtikel = Artikel.kArtikel '.
'WHERE Bestellung.dErstellt >= \''.\$start.' 00:00:00\' '.
'AND Bestellung.dErstellt < \''.\$ende.' 23:59:59\' '.
'ORDER BY Bestellung.dErstellt ASC;';
\$artikel = sql_exec(DB, \$query);
//file_put_contents(__DIR__.'ericht.txt',print_r(str_replace("
","
",\$artikel), true));
array_shift(\$artikel); array_shift(\$artikel);
echo count(\$artikel).' Bestellungen gefunden.'.PHP_EOL;
\$orders = array();
foreach(\$artikel as \$a) {
\$i = @list(\$sku, \$anzahl, \$erstellt, \$bestellnr) = explode(SQLTOKEN, \$a, 4);
if(count(\$i) != 4) {
continue;
}
\$sku = trim(_conv(\$sku));
\$anzahl = intval(\$anzahl);
\$erstellt = strtotime(\$erstellt);
if(strlen(\$sku)) {
if(isset(\$orders[\$sku])) {
\$orders[\$sku] += \$anzahl;
} else {
\$orders[\$sku] = \$anzahl;
}
}
}
echo count(\$orders).' verschiedene Artikel wurden bestellt.'.PHP_EOL;
arsort(\$orders, SORT_NUMERIC);
\$fd_write = fopen(__DIR__.'\Verkaeufe-zwischen-'.\$start.'-und-'.\$ende.'.csv', 'w');
if(\$fd_write) {
fwrite(\$fd_write, 'Artikelnummer;Anzahl der Verkaeufe'.PHP_EOL);
foreach(\$orders as \$sku => \$anzahl) {
fwrite(\$fd_write, \$sku.';'.\$anzahl.PHP_EOL);
}
fclose(\$fd_write);
}
Did this file decode correctly?
Original Code
<?php echo "d\x65f\x69\x6ee(\x27SQ\x4cTOKE\x4e\x27, '|\x27)\x3b\ndef\x69n\x65('C\x53\x56\x5f\x54\x4f\x4b\x27,\x20\x27\x3b\x27);\n\n// C\x508\x350\x20T\x4f I\x53O\n\x66u\x6ec\x74ion\x20_\x63on\x76(\$val\x75e)\x20{\n\tr\x65t\x75\x72\x6e\x20ic\x6fn\x76('\x43P\x38\x35\x30', \x27I\x53\x4f-88\x359-1\x35',\x20\$v\x61lu\x65);\n}\n\n\x66unc\x74\x69\x6f\x6e \x5fto_ans\x69(\$valu\x65)\x20{\n\t//retur\x6e i\x63\x6f\x6ev(\x27UT\x46-8', \x27\x41NS\x49',\x20\$va\x6c\x75\x65);\n\tret\x75\x72\x6e\x20\x75t\x668_\x64e\x63o\x64e(\$\x76a\x6cue);\n}\n\n\x66\x75ncti\x6fn sq\x6c_e\x78ec(\$db,\x20\$\x73\x71l)\x20{\n\t\n\t\$\x72\x65t\x20\x3d\x20a\x72ray()\x3b\n\t\n\t//\x20-\x75\x20-> \x55ni\x63ode\n\t// -\x66 850\x20-\x3e\x20CP8\x35\x30\x20(\x43\x6fdep\x61\x67\x65), ch\x65ck\x20thi\x73\x20\x77ith\x20\x27\x63\x68\x63p\x27\x20\x69n c\x6dd\x2e\x65\x78\x65\n\t\$pd = \x70open('sq\x6cc\x6dd\x20-S\x20'.SER\x56\x45R\x2e' -d\x20'\x2e\$\x64\x62\x2e'\x20-\x55\x20\x27\x2eUS\x45R.'\x20-\x50\x20'\x2ePA\x53\x53\x2e\x27\x20-\x57\x20-\x75\x20-\x66 \x385\x30 -\x51 \x22'.\$sql\x2e'\" -s \"\x27.S\x51L\x54\x4f\x4bEN\x2e'\x22\x27,\x20\x27r\x27);\n\n\t\x77\x68\x69l\x65(!\x66\x65\x6ff(\$pd)) {\n\t\t\$r\x65t[] \x3d\x20fg\x65\x74\x73(\$p\x64);\n\t}\n\t\n\tpcl\x6f\x73e(\$\x70\x64)\x3b\n\t\n\t\x72\x65\x74u\x72n \$r\x65\x74;\n}\n\n\$co\x6ef \x3d\x20par\x73e_ini\x5f\x66\x69le(_\x5f\x44IR__.\x27\\\x5c\x63on\x66\x69g\x2ei\x6ei');\n\n//\x20v\x61li\x64a\x74\x65 \x64\x61te\n\$st\x61\x72t =\x20\x73trto\x74ime(\$c\x6f\x6ef['s\x74\x61rt'])\x3b\n\x69f(\x21\$start) {\n\n\te\x63ho '\x46\x45\x48LE\x52:\x20\x53t\x61r\x74\x7a\x65\x69\x74 k\x61n\x6e\x20\x6ei\x63\x68t \x67el\x65\x73e\x6e werden,\x20\x62\x69\x74\x74\x65 \x76\x65\x72w\x65nde f\x6f\x6cge\x6ed\x65s \x46\x6f\x72\x6d\x61t: \x64d\x2emm.\x59YY\x20(\x331.\x312.201\x36),\x20\x41b\x62ru\x63h!'\x2eP\x48\x50_EO\x4c\x3b\n\texit();\n\n}\n\n\$\x73\x74\x61\x72\x74 = \x64\x61\x74\x65('Y-d-\x6d',\$s\x74\x61\x72t);\n\n\$en\x64e = s\x74r\x74\x6ft\x69me(\$\x63o\x6e\x66[\x27en\x64e\x27]);\nif(!\$e\x6e\x64e)\x20{\n\n\t\x65c\x68o\x20\x27F\x45H\x4cE\x52: E\x6e\x64ez\x65\x69t\x20\x6bann\x20nich\x74 \x67e\x6ces\x65n\x20wer\x64en,\x20b\x69\x74t\x65\x20v\x65\x72w\x65\x6e\x64\x65 \x66ol\x67endes F\x6f\x72\x6dat: d\x64\x2em\x6d\x2eYY\x59 (\x331.12\x2e2\x30\x316),\x20\x41\x62br\x75ch\x21'.PH\x50\x5f\x45\x4f\x4c\x3b\n\t\x65\x78\x69\x74()\x3b\n\n}\n\$\x65nde\x20= d\x61\x74\x65(\x27\x59-\x64-\x6d',\$\x65nd\x65);\n\n\$q\x75\x65\x72\x79 = \x27\x53ET\x20NOC\x4fU\x4e\x54\x20\x4fN;\x27\x2e\n\x27\x53\x45\x4cEC\x54 \x41rtik\x65l\x2ecAr\x74N\x72 a\x73\x20cA\x72t\x4er, Be\x73t\x65\x6cl\x70\x6fs\x2enAnz\x61h\x6c \x61s nA\x6ezah\x6c,\x20B\x65s\x74el\x6c\x75n\x67\x2e\x64Er\x73te\x6c\x6ct \x61s \x64\x45r\x73\x74ellt,\x20\x42\x65\x73\x74\x65llun\x67\x2ecB\x65s\x74\x65l\x6cN\x72\x20a\x73 \x63\x42\x65\x73t\x65\x6cl\x4er \x27\x2e\n'\x46RO\x4d [d\x62\x6f]\x2e[\x74b\x65\x73\x74\x65llpo\x73]\x20\x41\x53\x20\x42\x65\x73te\x6clp\x6fs\x20'\x2e\n\x27\x49NNER\x20J\x4fIN\x20[d\x62o].[\x74\x42\x65s\x74\x65l\x6cun\x67]\x20\x41S Bes\x74\x65l\x6cung\x20ON \x42es\x74el\x6cp\x6fs.\x74\x42\x65ste\x6clun\x67\x5fk\x42e\x73te\x6clu\x6e\x67 =\x20\x42\x65\x73tell\x75n\x67.\x6bB\x65s\x74ellung\x20'.\n\x27\x49NNE\x52\x20J\x4fIN\x20[db\x6f].[\x74\x41\x72\x74ike\x6c] \x41\x53\x20A\x72t\x69\x6b\x65\x6c O\x4e \x42es\x74e\x6c\x6cpos.\x74A\x72\x74\x69\x6b\x65l_\x6bArti\x6b\x65l\x20= Arti\x6b\x65l\x2e\x6bA\x72t\x69k\x65l\x20\x27\x2e\n'\x57H\x45\x52E\x20Bes\x74\x65\x6c\x6cu\x6eg\x2e\x64E\x72\x73t\x65l\x6ct\x20>\x3d\x20\\'\x27.\$st\x61\x72t\x2e\x27\x200\x30:0\x30:\x300\\'\x20'\x2e\n'\x41ND\x20\x42\x65\x73\x74el\x6c\x75\x6eg\x2edErs\x74e\x6c\x6c\x74 < \\\x27\x27.\$en\x64e.'\x20\x32\x33:\x359:\x35\x39\\'\x20\x27.\n'O\x52DER BY\x20\x42e\x73\x74ell\x75\x6e\x67\x2edE\x72s\x74\x65\x6c\x6c\x74\x20\x41SC;'\x3b\n\n\$arti\x6bel =\x20\x73\x71l\x5f\x65x\x65\x63(\x44B, \$\x71\x75er\x79);\n\n//f\x69\x6ce_\x70\x75\x74_co\x6et\x65n\x74\x73(__\x44\x49\x52\x5f\x5f.\x27\x5c\x5c\x62\x65\x72ic\x68t.t\x78t',pr\x69\x6et\x5fr(s\x74r_\x72ep\x6c\x61ce(\"\x5cn\",\"\\\x72\\n\x22,\$ar\x74\x69kel),\x20\x74\x72\x75\x65))\x3b\n\n\x61r\x72a\x79\x5fs\x68if\x74(\$a\x72\x74ike\x6c); \x61r\x72\x61\x79\x5fs\x68if\x74(\$a\x72\x74i\x6b\x65l);\n\n\x65\x63ho \x63ount(\$\x61rtik\x65l)\x2e'\x20\x42\x65\x73te\x6clu\x6ege\x6e\x20\x67efu\x6eden.'\x2ePH\x50\x5fE\x4f\x4c\x3b\n\n\$\x6frder\x73 \x3d\x20arra\x79()\x3b\n\x66or\x65a\x63h(\$\x61\x72t\x69ke\x6c a\x73\x20\$\x61) {\n\n\t\$i\x20=\x20\x40list(\$sku, \$an\x7aa\x68\x6c, \$\x65r\x73\x74e\x6c\x6c\x74,\x20\$be\x73\x74\x65\x6c\x6c\x6e\x72) = ex\x70l\x6fde(\x53Q\x4cTOKEN,\x20\$\x61,\x20\x34);\n\t\x69\x66(\x63o\x75nt(\$\x69)\x20!=\x204)\x20{\n\t\t\x63\x6f\x6e\x74inu\x65;\n\t}\n\n\t\$sku \x3d \x74ri\x6d(_\x63o\x6ev(\$\x73ku));\n\t\$anzahl = \x69\x6e\x74\x76a\x6c(\$\x61\x6e\x7aah\x6c)\x3b\n\t\$e\x72\x73\x74el\x6c\x74 = s\x74\x72\x74o\x74im\x65(\$e\x72\x73\x74\x65\x6c\x6c\x74);\n\n\t\x69f(st\x72\x6c\x65n(\$sk\x75)) {\n\t\t\n\t\tif(\x69s\x73et(\$\x6frd\x65r\x73[\$s\x6bu]))\x20{\n\t\t\t\$o\x72d\x65\x72\x73[\$\x73\x6b\x75]\x20+= \$\x61n\x7aah\x6c\x3b\n\t\t} \x65l\x73\x65 {\n\t\t\t\$\x6f\x72d\x65r\x73[\$\x73\x6bu]\x20= \$\x61\x6ez\x61h\x6c;\n\t\t}\n\t}\n}\n\necho \x63o\x75nt(\$or\x64e\x72s).\x27\x20ve\x72s\x63\x68ie\x64\x65\x6ee\x20\x41rt\x69\x6be\x6c w\x75\x72\x64\x65\x6e\x20b\x65st\x65\x6c\x6ct\x2e\x27\x2e\x50H\x50\x5fEO\x4c\x3b\n\n\x61rso\x72\x74(\$\x6fr\x64\x65\x72\x73,\x20\x53\x4fRT_NU\x4dERI\x43);\n\n\$f\x64\x5f\x77\x72ite \x3d \x66\x6fpen(\x5f_D\x49\x52\x5f_.\x27\x5c\\V\x65rk\x61eu\x66e-zw\x69sc\x68\x65n-'.\$star\x74\x2e\x27-un\x64-\x27\x2e\$e\x6e\x64\x65\x2e\x27\x2e\x63\x73v', \x27\x77\x27)\x3b\nif(\$\x66d\x5f\x77\x72\x69te) {\n\t\n\tfwrite(\$\x66d\x5fw\x72\x69\x74\x65, \x27\x41\x72\x74\x69\x6b\x65l\x6e\x75\x6d\x6der;A\x6eza\x68l de\x72 V\x65\x72\x6ba\x65uf\x65\x27.P\x48\x50\x5fEO\x4c)\x3b\n\t\x66\x6fr\x65a\x63\x68(\$\x6f\x72der\x73 \x61s \$s\x6b\x75 \x3d>\x20\$anza\x68l) {\n\t\t\x66\x77rite(\$\x66\x64_w\x72i\x74e, \$s\x6b\x75.\x27;'.\$\x61nzahl\x2e\x50\x48\x50_EOL);\n\t}\n\tfc\x6cos\x65(\$\x66\x64_w\x72\x69t\x65)\x3b\n}\n";
?>
Function Calls
| None |
Stats
| MD5 | 35354fa677d9e05587ecb39727d5215a |
| Eval Count | 0 |
| Decode Time | 77 ms |