מחזור חיי פיתוח תוכנה מאובטחת (SSDLC) עם תרגול קוד מעשי

משך הסדנה: שעתיים

קהל יעד: מפתחי תוכנה, מהנדסי אבטחה, בודקי איכות (QA), ואנשי IT

מטרות למידה:

  • להבין את החשיבות של שילוב אבטחה בכל שלב במחזור חיי פיתוח התוכנה (SDLC).
  • ללמוד כיצד לזהות ולהפחית סיכוני אבטחה במהלך פיתוח תוכנה.
  • לתרגל טכניקות קידוד מאובטחות למניעת פגיעויות נפוצות.
  • לצבור ניסיון עם כלים לבדיקות אבטחה ומודלים של איומים.

סדר יום של הסדנה:

1. הקדמה ל-SSDLC (30 דקות)

  • מהו SDLC? סקירה מהירה של שלבי SDLC המסורתיים: דרישות, עיצוב, פיתוח, בדיקות, פריסה ותחזוקה.
  • למה פיתוח תוכנה מאובטח? ההשפעה של פגיעויות באבטחה (מקרי מבחן: פרצות נתונים, מתקפות).
  • הקדמה ל-SSDLC: שילוב פעילויות אבטחה בכל שלב של SDLC.
  • עקרונות אבטחה: CIA Triad (סודיות, שלמות, זמינות), עקרון המינימום פריבילגיה, הגנה בעומק.

פעילות: דיון קבוצתי על פריצות אבטחה אחרונות ואיך חוסר באבטחה ב-SDLC תרם לאירועים אלו.

2. פירוט שלב-אחר-שלב של SSDLC עם דוגמאות קוד (שעה)

  1. איסוף דרישות
    • דרישות אבטחה: איך להגדיר דרישות אבטחה לצד דרישות פונקציונליות.
    • כלים: תרחישי שימוש, תרחישי שימוש לרעה ורשימות דרישות אבטחה.
  2. דוגמה:

            - Multi-factor Authentication (MFA) required for users.
            - Passwords must be stored using bcrypt hashing with a minimum cost factor of 12.
            - Users should be locked out after 5 failed login attempts.
        
  3. עיצוב מאובטח
    • מודל איומים: זיהוי איומים ובקרות אבטחה בשלב העיצוב.
    • עקרונות: עיצוב מאובטח, הגנה בעומק, אימות קלט.
    • כלים: Microsoft Threat Modeling Tool או OWASP Threat Dragon.
  4. דוגמה: אפליקציית ווב שמאפשרת למשתמשים להעלות קבצים. איום פוטנציאלי: העלאת קבצים לא מוגבלת.

            // Example design decision
            Allow only `.jpg`, `.png`, `.pdf` file extensions and verify file headers to avoid content spoofing.
        
  5. פיתוח מאובטח (עם דוגמאות קוד)
    • תרגול קידוד מאובטח: פעל לפי הנחיות כמו OWASP Top 10.
  6. דוגמה 1: מניעת מתקפות SQL Injection.

            # Insecure Code: Vulnerable to SQL Injection
            cursor.execute("SELECT * FROM users WHERE username = '" + username + "' AND password = '" + password + "'")
            
            # Secure Code: Use parameterized queries
            cursor.execute("SELECT * FROM users WHERE username = %s AND password = %s", (username, password))
        

    דוגמה 2: מניעת Cross-Site Scripting (XSS) על ידי המרת פלט.

            
            <div>Hello, <?php echo $_GET['name']; ?></div>
            
            
            <div>Hello, <?php echo htmlspecialchars($_GET['name'], ENT_QUOTES, 'UTF-8'); ?></div>
        
  1. בדיקות מאובטחות
    • טכניקות בדיקות אבטחה: SAST (סטטי), DAST (דינמי), IAST (אינטראקטיבי).
  2. דוגמה: הרצת SonarQube לניתוח סטטי של הקוד.

            # Run SonarQube scan on the codebase
            sonar-scanner \
            -Dsonar.projectKey=myproject \
            -Dsonar.sources=. \
            -Dsonar.host.url=http://localhost:9000 \
            -Dsonar.login=your_token
        

    בדיקות חדירה: שימוש ב-OWASP ZAP לבדיקת אפליקציה לדוגמה עבור פגיעויות כמו XSS ו-CSRF.

  3. פריסה ומעקב
    • פריסה מאובטחת: וודא מינימום פריבילגיה בפריסות, הקשחת סביבות, וניהול מפתחות API מאובטחים.
    • מעקב: הגדר רישום ומעקב אחר פעילויות חשודות באמצעות כלים כמו Graylog או Splunk.
  4. דוגמה: הפעלת רישום עבור ניסיונות כניסה שנכשלו.

            # Python logging example for security events
            import logging
            
            logging.basicConfig(filename='security.log', level=logging.WARNING)
            logging.warning('Failed login attempt for user: %s', username)
        
  5. תחזוקה
    • אבטחה מתמשכת: תיקון מתמיד, עדכון ספריות וניהול פגיעויות.
  6. דוגמה: שימוש בכלי כמו Dependabot לזיהוי ותיקון אוטומטי של ספריות פגיעות.

3. תרגול מעשי: תרגיל מודל איומים (45 דקות)

סקירה: איך לבצע מודל איומים על ארכיטקטורת מערכת.

תסריט לדוגמה: משתתפים מקבלים דיאגרמה של פלטפורמת מסחר אלקטרוני ונדרשים לזהות איומים פוטנציאליים (כגון חשיפת נתונים, אימות חלש).

כלים: Microsoft Threat Modeling Tool או OWASP Threat Dragon.

תוצאה: דיאגרמות מודל איומים עם זיהוי איומים והצעות למיתון.

פעילות: עבודה קבוצתית ליצירת מודלי איומים והצגת ממצאים.

4. סדנת תרגול קידוד מאובטח (עם עוד דוגמאות קוד) (45 דקות)

פגיעויות נפוצות: באפר אוברפלואו, מתקפות הזרקה, Cross-Site Scripting ועוד.

OWASP Top 10: סקירה והסבר של כל אחת מהפגיעויות הנפוצות ב-OWASP Top 10.

דוגמה 1: מניעת Buffer Overflow (שפת C).

    // Insecure code: Vulnerable to buffer overflow
    char buffer[10];
    strcpy(buffer, userInput); // No bounds checking
    
    // Secure code: Use safer string functions
    strncpy(buffer, userInput, sizeof(buffer) - 1);
    buffer[sizeof(buffer) - 1] = '\0'; // Null-terminate to avoid overflow

דוגמה 2: מניעת Cross-Site Request Forgery (CSRF).

    
    <form method="POST" action="/submit">
      <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
      <input type="text" name="data">
      <button type="submit">Submit</button>
    </form>

ביקורת קוד: הרצת ניתוח קוד סטטי על קוד לדוגמה, עם התמקדות בזיהוי פגיעויות.

פעילות: המשתתפים מקבלים קטעי קוד לא מאובטח (SQL Injection, XSS) ונדרשים לזהות ולתקן את הבעיות.

5. בדיקות אבטחה (עם תרגול מעשי) (45 דקות)

סקירה של בדיקות אבטחה: SAST, DAST, IAST, ואיך לאוטומט אותן בצינורות CI/CD.

הדגמת כלי: שימוש ב-OWASP ZAP לבדיקות דינמיות של אפליקציית ווב.

דוגמה: בדיקת אפליקציית ווב לדוגמה עבור פגיעויות SQL Injection בעזרת OWASP ZAP.

    # Command to start OWASP ZAP
    zap.sh -daemon -config api.key=your_api_key -port 8080

פעילות: המשתתפים משתמשים ב-OWASP ZAP או Burp Suite לבדיקת אפליקציה לדוגמה ולמציאת פגיעויות כמו XSS, CSRF, ו-SQL Injection.

6. שילוב DevSecOps (30 דקות)

מהו DevSecOps? שילוב אבטחה בצינורות DevOps.

אוטומציה: אוטומציה של בדיקות אבטחה (SAST, DAST) וסריקות פגיעויות בצינורות CI/CD.

מעקב אבטחה מתמשך: שימוש בכלים כמו ELK Stack או Datadog לניטור בזמן אמת.

פעילות: המשתתפים מתכננים צינור DevSecOps ומזהים איפה לשלב כלים לבדיקות אבטחה.

7. סיכום ושאלות (15 דקות)

סיכום מושגים עיקריים: שלבי SSDLC, תרגולי קידוד מאובטח, טכניקות בדיקות אבטחה.

שאלות ותשובות פתוחות לכל שאלה שהמשתתפים עשויים להיות.

מחשבות מסכמות על חשיבות האבטחה בפיתוח תוכנה מודרני.

חומרים וכלים נדרשים:

  • סביבת הדגמה עם אפליקציות ווב לא מאובטחות (כמו OWASP Juice Shop).
  • כלים: OWASP ZAP, Burp Suite, SonarQube, Dependabot לניהול פגיעויות.

עיקרי הדברים:

  • אבטחה חייבת להיות משולבת בכל שלב של SDLC, מדרישות ועד תחזוקה.
  • תרגולי קידוד מאובטח מצמצמים משמעותית את הסיכון לפגיעויות.
  • כלים לאוטומציה של בדיקות וניטור משחקים תפקיד מכריע בשמירה על מחזור חיי יישום מאובטח.

Secure Software Development Lifecycle (SSDLC) with Hands-On Coding

Duration: 2 Hours

Audience: Software developers, security engineers, QA testers, and IT professionals

Learning Objectives:

By the end of the workshop, participants will:

  • Understand the importance of incorporating security in every phase of the Software Development Lifecycle (SDLC).
  • Learn how to identify and mitigate security risks during software development.
  • Practice secure coding techniques to prevent common vulnerabilities.
  • Gain experience with security testing tools and threat modeling.

Workshop Agenda:

1. Introduction to SSDLC (30 minutes)

  • What is SDLC? A brief review of the traditional SDLC phases: Requirements, Design, Development, Testing, Deployment, and Maintenance.
  • Why Secure Software Development? The impact of security vulnerabilities (case studies: data breaches, attacks).
  • Introduction to SSDLC: Incorporating security activities into each phase of SDLC.
  • Security Principles: CIA Triad (Confidentiality, Integrity, Availability), Principle of Least Privilege, Defense in Depth.

Activity: Group discussion on recent security breaches and how a lack of security in the SDLC contributed to these incidents.

2. Phase-by-Phase Breakdown of SSDLC with Code Examples (1 hour)

1. Requirements Gathering
  • Security Requirements: How to define security requirements alongside functional requirements.
  • Tools: Use cases, misuse cases, and security requirements checklists.
  • Example: Define security requirements for user authentication in an application.

– Multi-factor Authentication (MFA) required for users.

– Passwords must be stored using bcrypt hashing with a minimum cost factor of 12.

– Users should be locked out after 5 failed login attempts.

2. Secure Design
  • Threat Modeling: Identify threats and security controls during the design phase.
  • Principles: Secure by design, defense in depth, and input validation.
  • Tools: Microsoft Threat Modeling Tool or OWASP Threat Dragon.

Example: A web application that allows users to upload files. Potential threat: Unrestricted File Upload.

  • Mitigation: Only allow specific file types and scan files for malware.

 

// Example design decision

Allow only `.jpg`, `.png`, `.pdf` file extensions and verify file headers to avoid content spoofing.

3. Secure Development (with Code Examples)
  • Secure Coding Practices: Follow guidelines like OWASP Top 10.
  • Example 1: Prevent SQL Injection attacks.

# Insecure Code: Vulnerable to SQL Injection

cursor.execute(“SELECT * FROM users WHERE username = ‘” + username + “‘ AND password = ‘” + password + “‘”)

# Secure Code: Use parameterized queries

cursor.execute(“SELECT * FROM users WHERE username = %s AND password = %s”, (username, password))

  • Example 2: Prevent Cross-Site Scripting (XSS) by escaping output.

<!– Insecure Code: Vulnerable to XSS –>

<div>Hello, <?php echo $_GET[‘name’]; ?></div>

<!– Secure Code: Escape output to prevent XSS –>

<div>Hello, <?php echo htmlspecialchars($_GET[‘name’], ENT_QUOTES, ‘UTF-8’); ?></div>

Code Review: Emphasize peer code reviews focused on security and using tools like SonarQube for static code analysis.

4. Secure Testing
  • Security Testing Techniques: SAST (Static), DAST (Dynamic), IAST (Interactive).
  • Example: Running a SAST tool like SonarQube to detect insecure code patterns.

# Run SonarQube scan on the codebase

sonar-scanner \

-Dsonar.projectKey=myproject \

-Dsonar.sources=. \

-Dsonar.host.url=http://localhost:9000 \

-Dsonar.login=your_token

  • Penetration Testing: Using OWASP ZAP to test a demo application for common vulnerabilities like XSS and CSRF.
5. Deployment & Monitoring
  • Secure Deployment: Ensure least privilege for deployments, environment hardening, and secure API keys management.
  • Monitoring: Set up logging and monitoring with tools like Graylog or Splunk.

Example: Enable logging for suspicious activity, such as failed login attempts.

# Python logging example for security events

import logging

logging.basicConfig(filename=’security.log’, level=logging.WARNING)

logging.warning(‘Failed login attempt for user: %s’, username)

6. Maintenance
  • Ongoing Security: Continuous patching, updating libraries, and vulnerability management.

Example: Use a tool like Dependabot to automatically detect and patch vulnerable dependencies.

3. Hands-On: Threat Modeling Exercise (45 minutes)

  • Overview: How to perform threat modeling on a system’s architecture.
  • Example Scenario: Participants receive a system diagram of an e-commerce platform and are tasked with identifying potential threats (e.g., data exposure, weak authentication).
  • Tools: Microsoft Threat Modeling Tool or OWASP Threat Dragon.
  • Output: Threat modeling diagrams with identified threats and mitigations.

Activity: Group work to create threat models and present findings.

4. Secure Coding Practices Workshop (with More Code Examples) (45 minutes)

  • Common Vulnerabilities: Buffer overflows, injection attacks, cross-site scripting, and others.
  • OWASP Top 10: Review and explain each of the OWASP Top 10 vulnerabilities.

Example 1: Preventing Buffer Overflow (C language).

// Insecure code: Vulnerable to buffer overflow

char buffer[10];

strcpy(buffer, userInput); // No bounds checking

// Secure code: Use safer string functions

strncpy(buffer, userInput, sizeof(buffer) – 1);

buffer[sizeof(buffer) – 1] = ‘\0’; // Null-terminate to avoid overflow

Example 2: Preventing Cross-Site Request Forgery (CSRF).

<!– Secure HTML form with CSRF token –>

<form method=”POST” action=”/submit”>

  <input type=”hidden” name=”csrf_token” value=”{{ csrf_token }}”>

  <input type=”text” name=”data”>

  <button type=”submit”>Submit</button>

</form>

Code Review: Run static code analysis on sample code, focusing on identifying vulnerabilities.

Activity: Participants are given insecure code snippets (SQL injection, XSS) and tasked with identifying and correcting the issues.

5. Security Testing (with Hands-On) (45 minutes)

  • Overview of Security Testing: SAST, DAST, IAST, and how to automate them in CI/CD pipelines.
  • Tool Demo: Use OWASP ZAP for dynamic testing of a web application.

Example: Test a demo web application for SQL injection vulnerabilities using OWASP ZAP.

# Command to start OWASP ZAP

zap.sh -daemon -config api.key=your_api_key -port 8080

Activity: Participants use OWASP ZAP or Burp Suite to test a demo application and find vulnerabilities like XSS, CSRF, and SQL injection.

6. Integrating DevSecOps (30 minutes)

  • What is DevSecOps? Merging security into DevOps pipelines.
  • Automation: Automating security tests (SAST, DAST) and vulnerability scans in CI/CD pipelines.
  • Continuous Security Monitoring: Use tools like ELK Stack or Datadog for real-time monitoring.

Activity: Participants design a DevSecOps pipeline, identifying where to integrate security testing tools.

7. Wrap-Up and Q&A (15 minutes)

  • Recap of key concepts: SSDLC phases, secure coding practices, testing techniques.
  • Open Q&A for any questions participants might have.
  • Closing thoughts on the importance of security in modern software development.

Materials & Tools Needed:

  • Demo environment with insecure web applications (e.g., OWASP Juice Shop).
  • Tools: OWASP ZAP, Burp Suite, SonarQube, Dependabot for vulnerability management.

Key Takeaways:

  • Security must be integrated into every phase of the SDLC, from requirements to maintenance.
  • Secure coding practices significantly reduce the risk of vulnerabilities.
  • Automated testing and monitoring tools play a crucial role in maintaining a secure application lifecycle.

 

powered by Advanced iFrame