2025년 5월 27일 화요일

Segfault ethical hacking week 7

 

Error Based SQL Injection

1) If the SQL query results are directly displayed on the screen → Union SQLi

2) If an error message is output → Error-Based SQLi
        : Utilizing error messages to extract data:
            (1) Logic Error
            (2) SQL Error

1) Syntax Error vs. Logic Error

  • Compilation Process: When executing code, a compilation process occurs.
  • Syntax Error: If a syntax error occurs, the code will not execute.
  • SQL Syntax Error: Generally not useful for extracting data.
  • Data Extraction: The SELECT statement must be used to retrieve data.

2) Logic Error

  • SQL Error: Errors occurring due to incorrect SQL syntax can be exploited using Error-Based SQLi.
  • Error Message Injection: The goal is to manipulate the error message so that it displays a SELECT query result.

Tips for Inducing Logic Errors

  • Server behavior varies, requiring individual research for effective exploitation.

Extractvalue Function

Extractvalue('XML text', 'XML expression')

Example injection:

___' and extractvalue('1', concat(0x3a, (select '____'))) and '1'='1

  • Replace ____ with the desired SELECT statement to extract its result.
  • Special symbols must be included to trigger an error.

Concat Function

  • Usage: Combines strings together.
  • concat('hello', 'test') -> hellotest concat(0x3a, 'test') -> :test

  • Hexadecimal Representation:
  • 0x3a represents :

Extractvalue Function Characteristics

  • Requires special characters like : to cause an error and display data.

This method takes advantage of error messages to extract sensitive information from the database by carefully crafting SQL queries. If you're looking for further explanations or practical examples, let me know!


Error-Based SQL Injection Steps

  1. Identify SQL Injection Point
    • Check if SQL errors are displayed on the screen.
  2. Error Output Function
    • Use extractvalue to trigger an error and extract data.
  3. Construct Attack Format
  4. ___' and extractvalue('1', concat(0x3a, (select '____'))) and '1'='1

    Insert the desired query in place of ____ to retrieve data.

  5. Retrieve Database Name
    Insert: select database()
  6. Retrieve Table Name
  7. select table_name from information_schema.tables where table_schema = '_________' limit 1,1

  8. Retrieve Column Name
  9. select column_name from information_schema.columns where table_name='____'

  10. Retrieve name Column from game_table

        select name from game limit 0,1


2025년 5월 21일 수요일

Segfault ethical hacking week 6

 

1. Review

SQL Injection 1

Login page
You must create it yourself to understand how it works internally during login.
It’s essential to know what happens after identification/authentication and what results are returned when a SELECT statement is executed.
Only then can you study various approaches.
Make sure to build it, test it, practice with it, and research it thoroughly.


When problems occur
1) Identify the root cause

- Many times, problems can’t be solved because the root cause isn’t identified.
- It’s important to build and run it yourself to see where and why the issue occurs.

2) After that, you will be able to find a solution.



Prepared Statment 

SQL Injection is not possible.

2025년 5월 14일 수요일

Segfault ethical hacking week 5


 

Web System Structure Overview

 Web (Static Resource Server)
  • Delivers static files to the client (e.g., HTML, CSS, JS, images)
  • Web Server Role: Responds to client requests with files(e.g., Apache, Nginx)

WAS (Web Application Server)

  • Handles dynamic processing (e.g., login, user interaction, DB access)
  • Languages used: ASP, JSP, PHP, Python, etc.
  • Executes business logic

DB (Database)

  • Stores data persistently (e.g., user info, posts)

  • Language used to interact with DB: SQL


Relationship Between Client and Server


Client (Web Browser: Edge, Chrome, etc.) ↔ Web Server (Static files) ↔ WAS (Dynamic logic) ↔ DB (Data storage)
  • Front-End (FE): Visible UI — HTML, CSS, JavaScript
  • Back-End (BE): Business logic (e.g., verifying login credentials)


Login and Session Concepts

    Requesting from Web Server

  • Like sending a letter asking for a file

  • Since the server doesn’t know who is requesting, it uses cookies in the header to identify the user


    Cookie (Client-side storage)
  • Stored on the client 
  • Issue: Vulnerable to theft or hijacking (can lead to unauthorized access
    
    Session (Server-side storage)
  • Server creates a session ID to identify each user

  • Session data is stored on the server; only session ID is passed via cookie
  • Safer than using only cookies


    Burp Suite (Web Proxy Tool)

  • Intercepts communication between the client and web server
  • Allows you to view and modify HTTP requests/responses
  • Useful for testing vulnerabilities and simulating attacks

    SQL Injection

  • SQL: Language used to communicate with the database
  • Injection: To insert malicious code
  • SQL Injection: An attack that injects malicious SQL queries into input fields to manipulate or steal data from the DB

2025년 4월 29일 화요일

Segfault ethical hacking week 4

 

1. Burp Suite

Burp Suite is a web proxy tool that intermediates requests and responses between the client and the web server. By using a proxy, it allows the analysis of all transmitted packets, enables packet modification, and supports the delivery of modified packets to the server.


User > Display > Appearance 

It can be switched to dark mode.


Burp Proxy Setting

Register proxy listener



Bind to Port

Set the port that the proxy listener will use.

Bind to address

    Loopback only : Receives only requests coming from the local system.

    All interafces : Receives requests from all network interfaces.

    Specific address : Receives only requests from a designated address.


2. Burp Suite Functions



Intercept :

    Halts incoming packets. Packets intercepted can be modified and sent to the web server.

History : 

    Stores all packets observed through the proxy. Detailed inspection is possible.

Repeater : 

    Sends the same request or slightly modified requests repeatedly for response analysis.

Decoder: 
    Performs operations such as encryption, decryption, or hash transformation on extracted data from packets. 

Comparer: 
    Compares two sets of data to easily identify differences






Request: 

It contains applied resources or client information.
Looking at GET /4_burp/flag.php HTTP/1.1, it is composed of:

  • Method: The action to be performed (e.g., GET).
  • Path: The specific route to the resource (e.g., /4_burp/flag.php).
  • Protocol: The communication protocol being used (e.g., HTTP).
  • Protocol Version: The version of the protocol (e.g., 1.1).


Response: 

It contains applied resources or client information.
Looking at HTTP/1.1 200 OK, it is composed of:

  • Protocol: The communication protocol being used (e.g., HTTP).
  • Protocol Version: The version of the protocol (e.g., 1.1).
  • Status Code: Indicates the result of the request (e.g., 200 OK).

The output value is displayed with a blank line below the header.




Status Code: 

    200 : OK
    300 : Redirect
    400 : Client Error
    500: Server Error


2025년 4월 23일 수요일

Segfault ethical hacking week 3

1. Login Authentication

Login is the process of verifying a user’s identity. It consists of two main components: identification and authentication.

Identification:

Identification refers to locating specific data among a large set of information. Identifying information must be unique and non-duplicable, such as a user ID, phone number, or email address.
In databases, these are typically used as primary keys, which must not be duplicated under any circumstances.
Even if identifying information is public, it usually doesn't pose a direct security risk. However, personally identifiable information (PII) is considered more sensitive and dangerous when exposed.

  • Personally Identifiable Information (PII): Data that can be used to uniquely identify an individual, such as resident registration numbers, driver's license numbers, or passport numbers.

Authentication:

Authentication is the process of verifying that the person is truly who they claim to be. Login is a common form of authentication.
It usually involves credentials, such as a password, but can also include OTP (One-Time Passwords), and must be securely stored in the database (e.g., hashed and salted).

In summary:

Login involves both identification (who you are) and authentication (proving it’s really you).
You must provide both an identifier and authentication credentials together.

select * from member
where id='nomaltic'


2. Login Logic Case

1) Performing Identification and Authentication Simultaneously

This approach performs both identification and authentication in a single step.
It implements login by executing one SQL query that checks both the identifier and the credentials at the same time.

Example: Logging in by querying the database once using both the username (or email/phone number) and password.

Pseudo Code

$sql = "select * from meeber where"
$sql .= "id='$user_id' and pass='$user_pass"

$ret = $sql.execute();

if($ret){
    // login success
}else{
    // login failed
}


Putting both the ID and password into a single SELECT statement.

This method compares the ID with the database, and simultaneously checks the password.
If both conditions are satisfied, the login is successfully executed.

In other words, the login query validates both the user ID and the password in one step.



If the user ID is "normaltic" and the password is "1234", a matching user record will be returned.
If either the ID or the password is incorrect, no results will be returned.

In this approach, if a result is returned from the query, the login is considered successful.
If no result is returned, the login is treated as failed.

$sql = "select * from meeber where id='_______' and pass='________'"


2) Performing Identification and Authentication Separately

This method separates identification (ID) and authentication (password) into two steps.
First, the system retrieves the password from the database using the provided ID and stores it in a variable such as db_pass.
Then, it compares the user’s input password with the password stored in the database.

An if statement is used to determine whether the login is successful or not, based on the result of the comparison.

Pseudo Code

$sql = "select * from meeber where id='_______' " ---
|-- Identification part
$db_pass = sql.ret['pass'] ---

if($db_pass == $user_pass){ ---
    // login success |
}else{ |-- Authentication part
    // login failed ---
}



*** HASHING ***

Hashing is a one-way function, meaning the original value cannot be restored from the hash.
It is different from encryption or encoding, and unlike encryption, it is not reversible (no decryption).

Even if a hash is exposed, it is generally safe — at least for a single use — because the original value cannot be recovered from it.

Since hashing produces a consistent and deterministic result, it can always be used for comparison.
Although we can’t know what password a user entered, we can still verify whether it’s correct, by comparing the hash values.

The hash value itself does not change, as long as the input remains the same.


3) Performing Identification and Authentication Simultaneously (Hashing)


4) Performing Identification and Authentication Separately (Hashing)



3. Login Persistence

1) In the early days of the web, login persistence was handled using cookies.

The Set-Cookie header would store both the user ID and password, and the browser would automatically include these cookie values with every request.

However, the origin of the request is the client — and since attackers are also clients,
they can manipulate cookie values freely.

This means that if sensitive information like user IDs and passwords are stored in cookies, it becomes vulnerable to tampering or misuse by malicious users.


Cookie: loginUser=normaltic; PHPSESSID=

Cookie: loginUser=doldol; PHPSESSID=

A user could modify cookies to log in as a different user.

The main issue was that cookies are stored on the client side, which means the user can freely edit or manipulate them.


2) The Introduction of Sessions

Sessions were introduced as a more secure method.
With sessions, login information is stored on the server side, not on the client.

This approach makes it much harder for users or attackers to manipulate authentication data, since it is not accessible or editable from the client side.


<?php
        session_start();

        $_SESSION['id'] = 'normaltic';

?>


They try to steal the session ID.
If you inspect the cookies, you can often find the session ID stored there.

In fact, some past account hacking incidents on platforms like Naver and YouTube involved session hijacking — where the attacker used a stolen session ID to impersonate a user.


To enhance security, the session ID changes every time you log in.
So even if a session ID is stolen, it becomes useless as soon as the user logs in again or logs out.

However, in poorly implemented systems, the session might not be invalidated properly on logout, which can leave the session vulnerable.




3)  JWT(JSON Web Token)

 What is JWT?

  • A digital token issued after login

  • Enables stateless authentication (no session saved on the server)

 How it works

  1. Server issues a JWT upon successful login

  2. Client stores the token (in localStorage or cookies)

  3. Client sends the token with each request (Authorization header)

  4. Server verifies the token to authenticate


Header:
{
  "alg": "HS256",
  "typ": "JWT"
}

Payload:
{
  "user_id": 101,
  "username": "normaltic",
  "is_admin": true,
  "exp": 1713000000
}

Signature:
HMACSHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), secret)

 Pros

  • No need to store sessions on the server

  • Scales well for distributed systems

 Cons

  • Risky if exposed → Use HTTPS

  • Logout is harder to manage (token expiration needed)


GET /dashboard HTTP/1.1  
Host: example.com  
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR...

2025년 4월 14일 월요일

Segfault ethical hacking week 2

 

1. Index page    

Create an index page to check whether the user is logged in or not.  

<?php
    if($_GET[login_id] == ""){
      header("location:login.php");
      exit;
    }
?>

Header
Put the content that needs to go inside the header into the response header.

header("location:login.php");
Redirect to login.php.

exit;

If you don't use exit, the code can be exposed. Although the screen might appear the same, from a hacker's perspective, the underlying code could be revealed. Sections that should only be visible after logging in might become accessible.

The meaning of exit is that the program stops running at that point.


2. Function

The function named login1 is created in login_func.php and used from there.

<?php                          
require_once('login_func.php');
?>  

In login_func.php, compare the ID and password to authenticate whether the login is successful or not.


3. In case of Errors

When developing for the web, even a small typo in PHP code can cause an error.

Since PHP executes code from top to bottom, inserting checkpoints throughout the code can help with debugging and locating errors later on. 

echo "This > " . $login_res;


2025년 4월 9일 수요일

Segfault ethical hacking week 1

1. What is a web server?

A web server is essentially a software that responds to user requests by delivering files such as HTML, images, CSS, and JavaScript. These files are then visualized through a web browser and appear to us as a web page.
There are various ways to run a web server, but one simple method is to use Python’s built-in HTTP server.

python3 -m http.server 80

2. How to request files from a web server

A web server delivers files requested by the user through a URL. A URL is structured as follows.

http:// 192.168.50.128:80/nomaltic.png

Web Root Path
When running a server with Python, the directory from which the server is executed becomes the web root directory. Only files within subdirectories of this root can be requested. Files located above the root directory cannot be accessed through the web server—this restriction is in place for security reasons.

If the web server's root path were set to the actual root directory ("/") of the server, it could potentially expose all files on the system. Therefore, in a production environment, it's essential to configure the server to allow access only to appropriate directories.

Ports and URL Requests
The default port for the HTTP protocol is 80, and for HTTPS, it is 443.
If the port is not specified in a URL, the browser will use the default port based on the protocol.
https://www.google.com can omit the port.
If you're using a port other than 80 or 443, you must explicitly specify it in the URL.


3. Static Pages vs. Dynamic Pages

Static Page

  • Delivers unchanging resources such as HTML, images, CSS, and JavaScript

  • The web server (e.g., Apache, Nginx, http.server) responds directly

Dynamic Page

  • Renders different content depending on user input (e.g., message boards, search results)

  • Requires a Web Application Server (WAS)

  • Uses dynamic languages and frameworks such as PHP, JSP, Python Flask, Node.js, etc.


4. Web Server Architecture: 3-Tier Structure

A web server system is typically composed of the following three-tier structure:

  1. Web Server

    • Handles static file delivery

    • Examples: Nginx, Apache, Python http.server

  2. WAS (Web Application Server)

    • Handles dynamic request processing

    • Examples: Tomcat, Flask, Express, Spring Boot, etc.

  3. Database (DB)

    • Stores data and processes queries

    • Examples: MySQL, PostgreSQL, MongoDB, etc.


Segfault ethical hacking week 16

Who Are You, and What Can You Do? (Authentication & Authorization Vulnerabilities) It's hard to imagine a web service without a logi...