❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

Security Incident : Code Smells – Not Replaced Constants

11 August 2024 at 12:11

The Secure Boot Case Study

Attackers can break through the Secure Boot process on millions of computers using Intel and ARM processors due to a leaked cryptographic key that many manufacturers used during the startup process. This key, called the Platform Key (PK), is meant to verify the authenticity of a device’s firmware and boot software.

Unfortunately, this key was leaked back in 2018. It seems that some manufacturers used this key in their devices instead of replacing it with a secure one, as was intended. As a result, millions of devices from brands like Lenovo, HP, Asus, and SuperMicro are vulnerable to attacks.

If an attacker has access to this leaked key, they can easily bypass Secure Boot, allowing them to install malicious software that can take control of the device. To fix this problem, manufacturers need to replace the compromised key and update the firmware on affected devices. Some have already started doing this, but it might take time for all devices to be updated, especially those in critical systems.

The problem is serious because the leaked key is like a master key that can unlock many devices. This issue highlights poor cryptographic key management practices, which have been a problem for many years.

What Are β€œNot Replaced Constants”?

In software, constants are values that are not meant to change during the execution of a program. They are often used to define configuration settings, cryptographic keys, and other critical values.

When these constants are hard-coded into a system and not updated or replaced when necessary, they become a code smell known as β€œNot Replaced Constants.”

Why Are They a Problem?

When constants are not replaced or updated:

  1. Security Risks: Outdated or exposed constants, such as cryptographic keys, can become security vulnerabilities. If these constants are publicly leaked or discovered by attackers, they can be exploited to gain unauthorized access or control over a system.
  2. Maintainability Issues: Hard-coded constants can make a codebase less maintainable. Changes to these values require code modifications, which can be error-prone and time-consuming.
  3. Flexibility Limitations: Systems with hard-coded constants lack flexibility, making it difficult to adapt to new requirements or configurations without altering the source code.

The Secure Boot Case Study

The recent Secure Boot vulnerability is a perfect example of the dangers posed by β€œNot Replaced Constants.” Here’s a breakdown of what happened:

The Vulnerability

Researchers discovered that a cryptographic key used in the Secure Boot process of millions of devices was leaked publicly. This key, known as the Platform Key (PK), serves as the root of trust during the Secure Boot process, verifying the authenticity of a device’s firmware and boot software.

What Went Wrong

The leaked PK was originally intended as a test key by American Megatrends International (AMI). However, it was not replaced by some manufacturers when producing devices for the market. As a result, the same compromised key was used across millions of devices, leaving them vulnerable to attacks.

The Consequences

Attackers with access to the leaked key can bypass Secure Boot protections, allowing them to install persistent malware and gain control over affected devices. This vulnerability highlights the critical importance of replacing test keys and securely managing cryptographic constants.

Sample Code:

Wrong

def generate_pk() -> str:
    return "DO NOT TRUST"

# Vendor forgets to replace PK
def use_default_pk() -> str:
    pk = generate_pk()
    return pk  # "DO NOT TRUST" PK used in production


Right

def generate_pk() -> str:
    # The documentation tells vendors to replace this value
    return "DO NOT TRUST"

def use_default_pk() -> str:
    pk = generate_pk()

    if pk == "DO NOT TRUST":
        raise ValueError("Error: PK must be replaced before use.")

    return pk  # Valid PK used in production

Ignoring important security steps, like changing default keys, can create big security holes. This ongoing problem shows how important it is to follow security procedures carefully. Instead of just relying on written instructions, make sure to test everything thoroughly to ensure it works as expected.

PYTHON-FUNDAMENTALS: CONSTANTS, VARIABLES AND DATA TYPES

26 July 2024 at 13:22

hi,everyody
I am kavin. I am going to write which I learnt I my class.

Variables

A variable in Python is a symbolic name that references or points to an object. Once a variable is assigned a value, it can be used to refer to that value throughout the program. Variables act as containers for storing data values.

How to name a variables

1.Start with a letter or an underscore.
2.Followed by letters, digits, or underscores.
3.Case-sensitive
4.Don't use Python Keywords

Examples of Valid Variable Names:
my_variable
variable1
_hidden_variable
userName

Assigning Values to Variables

In Python, the assignment operator = is used to assign values to variables. The syntax is straightforward: variable_name = value.
eg:

>>>name="kavin"
>>>print(name)

>>>kavin

Multiple Assignments

Python allows you to assign values to multiple variables in a single line. This can make your code more concise and readable.
eg:

>>>a,b,c=1,2,3
>>>print(a,b,c)

Variable Types

Python is a dynamically typed language, which means you don’t need to declare the type of a variable when assigning a value to it. The type is inferred at runtime based on the assigned value.
eg:

>>>my_variable="10"

>>>my_variable is an integer

You can check the type of a variable using the type() function.
eg:

>>>type("hello")

>>><class'str'>

Constants

In Python, constants are variables whose values are not meant to change. By convention, constants are typically written in all uppercase letters with underscores separating words.
eg:

>>>PI=22/7

Data Types

Data types are the different kinds of values that you can store and work with.

1.Numeric Types
*Integer (int): Whole numbers.

>>>value=23

*Float (float): Decimal numbers.

>>>value=23.5

*Complex (complex): Complex numbers.

>>>value=2+3j

2. Text Type

String (str): Sequence of characters.
eg:

>>>message="hello mac"

3. Boolean Type

Boolean (bool): Represents True or False.
eg:

>>>my_project=True

4. None Type

NoneType: Represents the absence of a value
eg:

>>>result=none

5. Sequence Types

*List (list): Ordered, mutable collection
eg:

>>>fruits=[apple,cherry,mango]

*Tuple (tuple): Ordered, immutable collection.
eg:

>>>coordinates(3,4)

*Range (range): Sequence of numbers.
eg:

>>>number=range(1,10)

6. Mapping Type

Dictionary (dict): Unordered, mutable collection of key-value pairs.
eg:

>>>person={"name":"kavin","url":"https://www.kavin.com"}

7.Set Type

Set (set): Unordered collection of unique elements.
Eg:

>>>unique_number={2,3,4}

Frozenset (frozenset): Immutable set.
eg:

>>>frozen_set=frozena([2,3,4])

Checking Data Type

Syntax: type(variable_name)
eg:

>>>name="kavin"
>>>print(type(name))

>>> <class'int'>

this is the things which i learnt in the class of Variables, Constants and Data Types.
Thank You

Task 2 - Constants and variables

15 July 2024 at 10:31

Create a variable named name and assign your name to it. Then print the value of the variable.

name = "ganesh"
print(name)

Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.

age = 36
age = 37
print(age)

Assign the values 5, 10, and 15 to three variables a, b, and c in a single line. Print their values.

a , b , c = 5 , 10 , 15
print(a , b , c)

Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.

x , y = 1 , 2
print(x , y)
x , y = 2, 1
print(x , y )

Define constants PI with appropriate values and print them.

PI = 3.14
print(PI)

Write a program that calculates the area of a circle using the constant PI and a variable radius. Print the area.

PI = 3.14
r = 5
a = pi * r * r
print(a)
79.5

Define constants for the length and width of a rectangle. Calculate and print the area.
Define a constant for Ο€ (pi) and a variable for the radius. Calculate and print the circumference of the circle.

LENGTH = 60
WIDTH = 20
a = LENGTH * WIDTH
print(a)
1200

PI = 3.14
r = 8
circumference = 2 * pi * r
circumference = 2 * PI * r
print(circumference)
50.24

❌
❌