【web | CTF】BUUCTF [HCTF 2018]WarmUp

PHP代码审计中的文件名拦截与安全漏洞分析

天命:这题本地php代码是无法复现的

首先打开网站,啥也没有,查看源码

发现文件,打开访问一下看看,发现是代码审计

<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            // 拦截1:判断是否数组里面两个文件名
            if (in_array($page, $whitelist)) {
                return true;
            }

            // 拦截2:输入的东西在最后面添加上?,然后获取字符串长度,通过长度来截取字符串
            // 如果?前面是数组里面的东西,就返回true,
            $_page = mb_substr( $page, 0, mb_strpos($page . '?', '?'));
            if (in_array($_page, $whitelist)) {
                return true;
            }

            // 拦
### HCTF 2018 WarmUp 1 PHP Code Security Audit Vulnerabilities Analysis In conducting a security audit on the PHP code from HCTF 2018 WarmUp 1, several potential vulnerabilities can be identified that may compromise application integrity and confidentiality. #### Potential SQL Injection Flaw If user inputs are not properly sanitized before being used in database queries, an attacker could inject malicious SQL commands. For instance, consider this snippet: ```php $query = "SELECT * FROM users WHERE username='" . $_POST['username'] . "' AND password='" . md5($_POST['password']) . "'"; ``` This approach lacks parameterized queries or prepared statements, exposing the system to injection attacks[^1]. #### Weak Password Hashing Mechanism Using `md5` for hashing passwords represents a significant weakness since MD5 is considered cryptographically broken and unsuitable for further use due to extensive vulnerability research findings. A more robust algorithm like bcrypt should replace outdated methods. #### Lack of Input Validation Failure to validate input parameters allows arbitrary values through unchecked pathways into backend processes. An example might involve file uploads without strict MIME type checks or size limitations, leading to unauthorized resource access scenarios[^2]. #### Insecure Direct Object References (IDOR) When sensitive actions rely directly upon unverified identifiers passed via URLs or forms, there exists risk associated with IDOR issues where attackers manipulate these references gaining illegitimate privileges over resources they shouldn't have control over. To mitigate such risks effectively within PHP applications similar to those presented during CTF challenges, developers must adhere strictly to secure coding practices including but not limited to employing ORM frameworks for query construction, utilizing strong encryption algorithms alongside salting techniques when handling credentials storage securely as well as implementing comprehensive validation routines across all entry points ensuring only expected types/formats reach internal logic layers.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星盾网安

能花钱买到的知识,都不贵

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值