이 블로그 검색

2023년 10월 24일 화요일

Logic Gate Truth Tables & Definitions

Logic Gate Truth Tables



Java Code

!A // NOT
A&B // AND
~(A&B) // NAND
A|B // OR
~(A|B) // XOR
A^B // XOR
~(A^B) // XNOR
~A // Inverts 0 to 1 and 1 to 0

A << 1  // Shift A's bits 1 position to the left. (Empty positions are filled with 0)
A >> 1  // Shift A's bits 1 position to the right. (Empty positions are filled with the leftmost sign bit's value)
A <<< 1 // Shift A's bits 1 position to the left. (Empty positions are filled with 0)
A >>> 1 // Shift A's bits 1 position to the right. (Empty positions are filled with 0)

NOT gate

AND gate

NAND gate



OR gate



NOR gate



XOR gate



XNOR gate



Cybersecurity: What is Automated Attacks?

Definition

Automated attacks refer to vulnerabilities where attackers use computer programs or scripts to automatically target a system.

Vulnerability Points

  • Login page
  • Post submission
  • Social media sharing page

Vulnerability Verification Methods

  • Repeatedly attempting requests without any issues

Attack Methods

Attack Scenarios

Common scenarios for automated attacks can include:

  • Using automated tools to repeatedly attempt logins.
  • The attacker captures the passwords of users with weak passwords.

Occurrence Process


Attack Example

The following example is a Python code designed to repeatedly attempt logins on a login site that has only a 4-digit password, written in PHP.

import requests

url = '<http://example.com/login_check.php>'
username = 'test'
password = '1234'

# Create a session
session = requests.Session()

# Send POST requests
for i in range(1, 9999):
    data = {
        'user_id': username,
        'user_pass': i
    }

    response = requests.post(url, data=data)

    # Check the response
    if response.status_code == 200:
        print('Request Password: ', i)
        print('Response Content:', response.text)
    else:
        print('Request failed. Status code:', response.status_code)

Countermeasures

  1. Strong Authentication and Encryption: Prevent malicious access by using robust CAPTCHA authentication methods and encryption.
  2. Network Security: Monitor network traffic and detect malicious activities using firewalls, intrusion detection systems, and other security measures.
  3. Web Application Security: Adhere to secure coding practices to prevent vulnerabilities in web applications and implement appropriate web application firewalls.

Leetcode 112. Path Sum Java Solution

Problem

LeetCode - The World's Leading Online Programming Learning Platform

Problem Solving Approach

  • The objective of this problem is to check whether there is a path in the given binary tree from the root to a leaf node whose sum equals the given targetSum.
  • Therefore, this code recursively explores paths in the given binary tree and checks if the path sum matches the targetSum.

Algorithm

  1. Recursion:
    • The hasPathSum function is called recursively.
    • This function subtracts the value of the current node from targetSum and uses the result as the new targetSum.
  2. Base Case:
    • At the start of the recursive call, it checks if the current node is null to determine if it has reached the end of the tree.
    • If it's null, the current path is not valid, so it returns false.
  3. Leaf Node Check:
    • It checks if the current node is a leaf node, meaning it has no children.
    • If the current node is a leaf node, it checks if targetSum is equal to 0.
    • If targetSum is 0, it means that the current path's sum matches the targetSum, so it returns true.
  4. Recursive Calls for Left and Right Subtrees:
    • If the current node is not a leaf node, it makes recursive calls to the left and right subtrees using the modified targetSum value.
  5. Return Result:
    • If either the left or right subtree returns true, it means there exists a path in the current path that satisfies the targetSum, so it returns true.
    • Otherwise, it returns false.

Recursive Function Implementation Table

  • Goal: https://leetcode.com/problems/path-sum/

  • Base Case (Termination Conditions):

    if root == null
    return false
    
    if left == null && right == null <- after subtracting root.val from sum
    return sum == 0
    
  • Is the previous step's result needed?: Yes

  • Problem Splitting (Divide the Problem):

    sum -= root.val
    
  • Combining Results:

    boolean left
    boolean right
    return left || right
    
  • Recursive Calls and Changes Before Moving to the Next Step (Recursive Call):

    sum -= root.val
    

Github Link

https://github.com/eunhanlee/LeetCode_112_PathSum_Solution.git

Time Complexity: O(n), Space Complexity: O(h)

class Solution {

    /**
     * Checks if there is a path from the root to a leaf node in the given binary tree
     * with a sum equal to the target sum.
     *
     * @param root      The root node of the binary tree.
     * @param targetSum The target sum to be achieved.
     * @return Returns `true` if a path exists, `false` otherwise.
     */
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return false;
        }

        // Subtract the value of the current node from the target sum.
        targetSum -= root.val;

        // Check if the current node is a leaf node and if the target sum is 0.
        if (root.left == null && root.right == null) {
            return targetSum == 0;
        }

        // Recursively check the left and right subtrees.
        Boolean rightNode = hasPathSum(root.right, targetSum);
        Boolean leftNode = hasPathSum(root.left, targetSum);

        // Return `true` if there is a valid path in either the left or right subtree.
        return rightNode || leftNode;
    }
}

Time Complexity

  • The time complexity of this code is O(n) because it visits all nodes in the tree exactly once, where n is the number of nodes in the tree.

Space Complexity

  • Due to the recursive function calls, a call stack is built up, but it only requires space up to the height of the tree, so the space complexity is O(h), where h is the height of the tree.

2023년 9월 10일 일요일

What is Session Prediction?

Definition

Session Prediction is a security vulnerability where an attacker predicts session identifiers to hijack or forge another user's session. Session identifiers are typically used in the form of cookies, tokens, or session IDs to maintain a user's authentication state and manage sessions.

Vulnerability Points of Occurrence

  • All pages where sessions are applied.

Vulnerability Verification Methods

  • When there is a consistent algorithm for session issuance that makes prediction easy:
    • Verify if sessions are issued anew during login.
    • Check if sessions are related to different IDs.
    • Verify if sessions are related to time.
    • Ensure sessions do not remain unchanged.
    • Check encryption methods (e.g., MD5 not used, DES, SHA, etc.).

Attack Methods

Attack Scenario

  1. Attackers use various techniques to predict session identifiers.
  2. Attackers who have predicted session identifiers hijack or forge the user's session to bypass authentication.
  3. Attackers use session identifiers to impersonate users, abusing the original user's privileges or performing illegal actions.

Occurrence Process


Detailed Process Explanation

  1. The user requests authentication from the application.
  2. The application issues a session to the user.
  3. The attacker confirms that the session is the same as the user's ID.
  4. The attacker uses various attack techniques (e.g., XSS) to obtain the session identifier.
  5. The user exposes the session identifier to the attacker.
  6. The attacker uses the acquired session identifier to send requests to the application.
  7. The application processes the attacker's requests.

Mitigation Strategies

  • Use strong session identifier generation algorithms that are difficult to predict and have high randomness.
  • Strengthen session management and maintenance methods. Limit the validity period of sessions and renew them when necessary.
  • Implement secure session identifier transmission methods. Use encrypted connections like HTTPS or require additional authentication.

What is Insufficient Session Expiration?

Definition

Insufficient Session Expiration is a security vulnerability where session duration is not adequately configured, allowing sessions to remain active for an extended period. This can enable attackers to exploit stolen sessions or allow unauthorized access even after a user has logged out.

Vulnerable Points of Occurrence

  • All pages that require a session.

Vulnerability Verification Method

  • Accessing the "My Page" while logged out to check if the session persists.

Attack Method

Attack Scenario

  1. The attacker identifies that sessions are persisting for an extended period due to insufficient session expiration settings.
  2. Even after a user logs out, if the session remains valid, the attacker can exploit the stolen session to access the application while impersonating the user.
  3. The attacker can then perform illegal actions or abuse the user's privileges.

Event Flow


Detailed Process Explanation

  1. The user initiates a logout request to the application.
  2. The application handles the logout request and expires the session.
  3. However, due to insufficient session expiration settings, the session remains valid.
  4. The attacker utilizes the stolen session to send requests to the application.
  5. The application processes the attacker's request.

Mitigation Measures

  • Implement proper session expiration settings. Set session validity periods and automatically expire sessions based on user inactivity.
  • Handle session expiration appropriately when a user logs out.

What is Session Fixation?

Definition

Session Fixation is one of the vulnerabilities that can occur in web application security. This vulnerability refers to a situation where an attacker gains access to an authenticated session by controlling the user's session identifier.

Points of Vulnerability

  • Pages that issue sessions
  • Pages that require a session (after authorization)

Vulnerability Verification Methods

  • If the issued session remains the same even after logging out and logging back in.
  • If the session before logging in and the session after logging in are the same.
  • If the session is not reissued (no "set cookie" in the response).

Attack Method

Attack Scenario

  1. The attacker logs in and creates a session identifier.
  2. The attacker forcefully delivers this session identifier to the user.
  3. The user logs in to the web application and starts a session.
  4. Since the session is already the same, the attacker can access the authenticated session by refreshing.

Attack Scenario Process

Detailed Explanation

  1. The attacker sends an authentication request to the web application.
  2. The web application generates a session identifier for authentication.
  3. The session identifier is delivered to the user and is used when starting a session.
  4. The attacker forcefully delivers a previously generated malicious session identifier to the user.
  5. When the user starts a session, they unknowingly use the malicious session identifier provided by the attacker.
  6. The web application performs authentication verification and considers the malicious session identifier as valid.
  7. The attacker gains access to the authenticated session using the malicious session identifier.

Countermeasures

  1. Randomness of Session Identifiers: Session identifiers should be generated randomly and should be difficult to predict.
  2. Changing Session Identifiers: Session identifiers should be changed whenever a user is authenticated or gains authorization.
  3. Secure Session Management: Session identifiers should be securely stored. If using cookies, set the security attributes 'Secure' and 'HttpOnly' to ensure secure transmission and protection against client-side scripts.
  4. Session Monitoring and Logging: Monitor and log session activity in the system to detect and respond to suspicious activities.

2023년 9월 9일 토요일

Cybersecurity: What Is Weak String Strength?

Definition

Weak string strength is a measure of how vulnerable a string, such as a password or authentication information, is.

Vulnerability Points

  • Login Page

Vulnerability Assessment Methods

  • Length, simplicity
  • Usernames: admin, administrator, manager, guest, test, scott, tomcat, root, user, operator, anonymous, etc.
  • Passwords: Abcd, aaaa, 1234, 1111, test, password, public, blank password, password identical to the ID, password123, qwerty, 123456789, etc.
  • Hackers often attempt to hack using lists of weak or commonly used usernames and passwords. Therefore, it is essential to be cautious of this.

Attack Methods

Attack Scenario

  1. The attacker possesses a list of usernames and passwords with weak string strength.
  2. The attacker uses this list to make indiscriminate login attempts.
  3. If even one attempt succeeds, they can use it to steal personal information or create additional victims using methods like XSS.

Countermeasures

  1. Length and Complexity Requirements: Set requirements for password length and diversity to encourage the use of strong passwords.
  2. Strengthen Password Policies: Guide users to create secure passwords and set password change intervals.
  3. Require Two-Factor Authentication: Implement additional security by using email, SMS, or apps for two-factor authentication.
  4. Account Lockout Policies: Set policies for locking accounts after a certain number of incorrect login attempts.
  5. Improve Education and Awareness: Provide users with education on strong password usage and security.

Logic Gate Truth Tables & Definitions

Logic Gate Truth Tables Java Code !A // NOT A&B // AND ~(A&B) // NAND A|B // OR ~(A|B) // XOR A^B // XOR ~(A^B) // XNOR ~A // Inve...