[PHP] Targetpay script beveiliging

Gestart doorAzdin5 reacties274 weergaven

6 berichten · pagina 1 van 1

Azdin

Lid · Topicstarter

Berichten
21.633
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hiya,

Ik gebruik zelf dit script van Targetpay:

[COLOR= #0000BB]<?php[/COLOR] 
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]
 [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"localhost"[/COLOR] [COLOR= #007700],[/COLOR] [COLOR= #DD0000]"naam"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"ww"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
 [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"db"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]

[COLOR= #FF8000]// Buitenlandse servers moeten met dezelfde time zone rekenen [/COLOR]
[URL="http://www.php.net/ini_set"]ini_set[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"date.timezone"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"Europe/Amsterdam"[/COLOR][COLOR= #007700]); 

function[/COLOR] access[COLOR= #007700]()   
    {[/COLOR]   
      [COLOR= #FF8000]//Parameters welke vanuit TargetPay worden meegestuurd [/COLOR]
      [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"accesscode"[/COLOR][COLOR= #007700]]) || ![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"time"[/COLOR][COLOR= #007700]]) || ![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"ip"[/COLOR][COLOR= #007700]])) {[/COLOR]
            [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Ongeldige url"[/COLOR][COLOR= #007700]);  
      }[/COLOR]
    
        [COLOR= #0000BB]$accesscode[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"accesscode"[/COLOR][COLOR= #007700]];[/COLOR]
        [COLOR= #0000BB]$time[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"time"[/COLOR][COLOR= #007700]];[/COLOR]
        [COLOR= #0000BB]$ip[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"ip"[/COLOR][COLOR= #007700]];[/COLOR]
      [COLOR= #FF8000]// Tijd moet groter zijn dan de targetpay Epoch tijd  [/COLOR]
      [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]() <[/COLOR] [COLOR= #0000BB]$time[/COLOR] [COLOR= #007700])  
          {[/COLOR]  
          [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Lokale tijd is "[/COLOR][COLOR= #007700]. ([/COLOR][URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()-[/COLOR][COLOR= #0000BB]$time[/COLOR][COLOR= #007700]) .[/COLOR][COLOR= #DD0000]"sec. vroeger dan op Targetpay.com"[/COLOR][COLOR= #007700]);  
          }[/COLOR]  

      [COLOR= #FF8000]// Remote address moet gelijk zijn als in het betaalscherm  
      // Note: Sommige Proxy servers veranderen het IP adres.  
      // Mocht u hier problemen mee ondervinden, schakel dan het die() statement uit.  [/COLOR]
      [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR] [COLOR= #0000BB]$ip[/COLOR] [COLOR= #007700]<>[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"HTTP_CF_CONNECTING_IP"[/COLOR][COLOR= #007700]] )  
          {  
         
          }[/COLOR]  
         
      [COLOR= #FF8000]// Betalings URL is c*10 minuten geldig [/COLOR]
      [URL="http://www.php.net/for"]for[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]<=[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]++)   
        {[/COLOR]   
        [COLOR= #0000BB]$t[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strftime"]strftime[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"%Y%m%d%H%M"[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()-([/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]600[/COLOR][COLOR= #007700])),[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]11[/COLOR][COLOR= #007700]);[/COLOR]   
        [COLOR= #0000BB]$hash[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/md5"]md5[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ip[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #DD0000]"33a633c779"[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$t[/COLOR][COLOR= #007700]);[/COLOR]   
        
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR] [COLOR= #0000BB]$hash[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]$accesscode[/COLOR] [COLOR= #007700])[/COLOR] [URL="http://www.php.net/return"]return[/URL] true[COLOR= #007700];  
        }[/COLOR]  
      
    [URL="http://www.php.net/return"]return[/URL] false[COLOR= #007700];  
    }[/COLOR]  

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR]access[COLOR= #007700]())      
    {[/COLOR]   
      [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"U heeft niet betaald of de betaling is verlopen. "[/COLOR][COLOR= #007700]);   
    }[/COLOR]   

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Je hebt betaald!"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE leden SET muntjes = muntjes+ 50 WHERE id = "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
?>


Na de betaling kom je uit op de url website.nl/betaald.php met alleen bovenstaande script. Echter, als je deze pagina blijft refreshen (f5en) blijft ie dus je muntjes verdubbelen. Hoe kan ik dit precies voorkomen? Via Targetpay verloopt de betaling namelijk pas na 10 min en verlagen kan niet voor zover ik weet.
Mysqli is inderdaad beter, I know, maar daar gaat het nu even niet over, negeer dat pl0x.

Alvast bedankt!
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Geven ze daar bij TargetPay geen unieke code terug? Aan de hand daarvan kan je kijken of een betaling al is uitgevoerd.

Verder raad ik met klem aan om foutafhandeling op je queries te plaatsen.
Stel je voor dat je UPDATE-query niet werkt, dan krijgen de gebruikers gewoon een melding dat er betaald is terwijl er niks bijgeschreven is. Ook een transactie-log zou niet overbodig zijn.
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Je moet checken of de unieke code al is gebruikt (de accesscode vermoed ik), of zelf de user een unieke code meegeven bij het betalen en die code op paid zetten wanneer je de muntjes uitkeert.
0
Berichten
951
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
Je moet checken of de unieke code al is gebruikt (de accesscode vermoed ik), of zelf de user een unieke code meegeven bij het betalen en die code op paid zetten wanneer je de muntjes uitkeert.
Dit zou ik doen. Gewoon de unieke code op gebruikt zetten zodat als ze refreshen dat ze een melding krijgen dat het al afgehandeld is ofzo.
0
Azdin

Lid · Topicstarter

Berichten
21.633
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je krijgt inderdaad een accesscode mee in de URL:
betaald.php?accesscode=415f772fda0fda135e071d3fc9d5b7ba&time=1488548914&ip=iphier

Als voorbeeld. Hoe zou ik het in mijn script moeten zetten?
0
Berichten
951
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR] 
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]
 [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"localhost"[/COLOR] [COLOR= #007700],[/COLOR] [COLOR= #DD0000]"naam"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"ww"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
 [URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"db"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]

[COLOR= #FF8000]// Buitenlandse servers moeten met dezelfde time zone rekenen [/COLOR]
[URL="http://www.php.net/ini_set"]ini_set[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"date.timezone"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"Europe/Amsterdam"[/COLOR][COLOR= #007700]); 

function[/COLOR] access[COLOR= #007700]()   
    {[/COLOR]   
      [COLOR= #FF8000]//Parameters welke vanuit TargetPay worden meegestuurd [/COLOR]
      [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"accesscode"[/COLOR][COLOR= #007700]]) || ![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"time"[/COLOR][COLOR= #007700]]) || ![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"ip"[/COLOR][COLOR= #007700]])) {[/COLOR]
            [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Ongeldige url"[/COLOR][COLOR= #007700]);  
      }[/COLOR]
    
        [COLOR= #0000BB]$accesscode[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"accesscode"[/COLOR][COLOR= #007700]];[/COLOR]
        [COLOR= #0000BB]$time[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"time"[/COLOR][COLOR= #007700]];[/COLOR]
        [COLOR= #0000BB]$ip[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"ip"[/COLOR][COLOR= #007700]];[/COLOR]
      [COLOR= #FF8000]// Tijd moet groter zijn dan de targetpay Epoch tijd  [/COLOR]
      [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]() <[/COLOR] [COLOR= #0000BB]$time[/COLOR] [COLOR= #007700])  
          {[/COLOR]  
          [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Lokale tijd is "[/COLOR][COLOR= #007700]. ([/COLOR][URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()-[/COLOR][COLOR= #0000BB]$time[/COLOR][COLOR= #007700]) .[/COLOR][COLOR= #DD0000]"sec. vroeger dan op Targetpay.com"[/COLOR][COLOR= #007700]);  
          }[/COLOR]  

      [COLOR= #FF8000]// Remote address moet gelijk zijn als in het betaalscherm  
      // Note: Sommige Proxy servers veranderen het IP adres.  
      // Mocht u hier problemen mee ondervinden, schakel dan het die() statement uit.  [/COLOR]
      [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR] [COLOR= #0000BB]$ip[/COLOR] [COLOR= #007700]<>[/COLOR] [COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"HTTP_CF_CONNECTING_IP"[/COLOR][COLOR= #007700]] )  
          {  
         
          }[/COLOR]  
         
      [COLOR= #FF8000]// Betalings URL is c*10 minuten geldig [/COLOR]
      [URL="http://www.php.net/for"]for[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]<=[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]++)   
        {[/COLOR]   
        [COLOR= #0000BB]$t[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/substr"]substr[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strftime"]strftime[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"%Y%m%d%H%M"[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/time"]time[/URL][COLOR= #007700]()-([/COLOR][COLOR= #0000BB]$c[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]600[/COLOR][COLOR= #007700])),[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]11[/COLOR][COLOR= #007700]);[/COLOR]   
        [COLOR= #0000BB]$hash[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/md5"]md5[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ip[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #DD0000]"33a633c779"[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$t[/COLOR][COLOR= #007700]);[/COLOR]   
        
    
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR] [COLOR= #0000BB]$hash[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #0000BB]$accesscode[/COLOR] [COLOR= #007700])[/COLOR] [URL="http://www.php.net/return"]return[/URL] true[COLOR= #007700];  
        }[/COLOR]  
      
    [URL="http://www.php.net/return"]return[/URL] false[COLOR= #007700];  
    }[/COLOR]  

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR]access[COLOR= #007700]())      
    {[/COLOR]   
      [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"U heeft niet betaald of de betaling is verlopen. "[/COLOR][COLOR= #007700]);   
    }[/COLOR]   

[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM payment WHERE pay_key = "[/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR]``[COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"accesscode"[/COLOR][COLOR= #007700]]) .[/COLOR][COLOR= #DD0000]" AND status != paid LIMIT 1"[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"De betaling is al voldaan"[/COLOR][COLOR= #007700]);
}[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Je hebt betaald!"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO payments (pay_key, status) VALUES ("[/COLOR][COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR]``[COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"accesscode"[/COLOR][COLOR= #007700]]) .[/COLOR][COLOR= #DD0000]", paid)"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE leden SET muntjes = muntjes+ 50 WHERE id = "[/COLOR][COLOR= #007700].[/COLOR][URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]user[/COLOR][COLOR= #007700]][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]]).[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
?>


Iets in deze richting?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren