Sorğu Saxtakarlığı CSRF | hash token | generating CSRF token in PHP | cyber attack | part1 #kody_az

PHP

Dərs haqqında

Saytlararası Sorğu Saxtakarlığı (CSRF), hücumçunun istifadəçiləri bilmədən etibarlı bir veb tətbiqə istənilməyən sorğular göndərməsinə imkan verən bir təhlükəsizlik zəifliyidir. Bu, hesab məlumatlarının dəyişdirilməsi, alış-veriş etmək və ya hətta vəsaitlərin köçürülməsi kimi icazəsiz hərəkətlərə səbəb ola bilər.

CSRF hücumları necə işləyir

1. Qurbanın Doğrulanması: İstifadəçi etibarlı bir veb sayta (məsələn, www.example.com) daxil olur və aktiv sessiya saxlayır.
2. Zərərli Sorğu: Hücumçu fərqli bir domen üzərində zərərli bir link və ya forma yaradır.
3. İstifadəçi İnteraksiyası: Qurban bilmədən zərərli link və ya formayla qarşılıqlı əlaqədə olur, bu da etibarlı sayta sorğu göndərir.
4. Avtomatik Etimadnamə Daxil Edilməsi: Brauzer sorğu ilə birlikdə sessiya kukilərini və ya doğrulama tokenlərini etibarlı sayta göndərir.
5. İcazəsiz Hərəkət: Etibarlı sayt sorğunu emal edir, onu qanuni istifadəçidən gəldiyini düşünür.

PHP-də CSRF-dən qorunma

CSRF hücumlarının qarşısını almağın ən yaygın metodu anti-CSRF tokenlərinin tətbiqidir. Bunlar server tərəfindən yaradılan unikal tokenlərdir və formalara daxil edilir. Server sonra form göndərildikdə tokeni doğrulayır.

1. CSRF tokeni yaratmaq: Forma yaradılarkən, unikal bir token yaradın və istifadəçinin sessiyasında saxlayın.
2. Tokeni Forma daxil etmək: Formada tokeni gizli bir input sahəsi olaraq əlavə edin.
3. Form göndərildikdə tokeni doğrulayın: Forma göndərildikdə, tokenin sessiyada saxlanılanla uyğun olub-olmadığını yoxlayın.
4. Tokeni yenidən yaratmaq və ya etibarsızlaşdırmaq: Doğrulamadan sonra, tokeni yenidən yaratmağı və ya istifadə edilməməsi üçün etibarsızlaşdırmağı seçə bilərsiniz.

CSRF qorumasının tətbiqi veb tətbiqlərin təhlükəsizliyi üçün vacibdir. Anti-CSRF tokenlərindən istifadə edərək və ən yaxşı təcrübələrə əməl edərək, PHP tətbiqlərinizdə CSRF hücumlarının riskini əhəmiyyətli dərəcədə azalda bilərsiniz.

======

Cross-Site Request Forgery (CSRF) is a security vulnerability that allows an attacker to trick authenticated users into submitting unintended requests to a web application. This can lead to unauthorized actions like changing account details, making purchases, or even transferring funds.

How CSRF Attacks Work

1. Victim Authentication: The user logs into a trusted website (e.g., www.example.com) and maintains an active session.
2. Malicious Request: The attacker crafts a malicious link or form hosted on a different domain.
3. User Interaction: The victim unknowingly interacts with the malicious link or form, which sends a request to the trusted website.
4. Automatic Credential Inclusion: The browser includes session cookies or authentication tokens with the request to the trusted site.
5. Unauthorized Action: The trusted site processes the request, thinking it’s from the legitimate user.

Preventing CSRF in PHP

The most common method to prevent CSRF attacks is by implementing anti-CSRF tokens. These are unique tokens generated by the server and included in forms. The server then validates the token upon form submission.

Step-by-Step Implementation

1. Generate a CSRF Token: When rendering a form, generate a unique token and store it in the user’s session.
2. Include the Token in the Form: Add the token as a hidden input field within the form.
3. Validate the Token Upon Submission: When the form is submitted, check if the token matches the one stored in the session.
4. Regenerate or Invalidate the Token: After validation, you can choose to regenerate the token to prevent reuse.

Implementing CSRF protection is crucial for web application security. By using anti-CSRF tokens and following best practices, you can significantly reduce the risk of CSRF attacks on your PHP applications.

#kody_az #kodyaz #php #csrf #tokens #phpcode #laravel #phpprogramming #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz

YouTube-da bax · KODY.AZ