『CTF Tricks』Ruby-利用File.open()执行shell命令
2021/9/19 7:05:08
本文主要是介绍『CTF Tricks』Ruby-利用File.open()执行shell命令,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
文章目录
- 前言
- 利用
- 原理
- 实战例题
- 完
前言
测试环境为
- ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
- Ubuntu 20.04.2 LTS
利用
file = '|whoami' puts open(file).read() # ubuntu puts open(file).gets # ubuntu
原理
查看核心文件Kernel.rb
,在2800行左右:
# open(path [, mode [, perm]] [, opt]) -> io or nil # open(path [, mode [, perm]] [, opt]) {|io| block } -> obj # # Creates an IO object connected to the given stream, file, or subprocess. # If +path+ starts with a pipe character (<code>"|"</code>), a subprocess is # created, connected to the caller by a pair of pipes. The returned IO # object may be used to write to the standard input and read from the # standard output of this subprocess. # === Examples # # Open a subprocess and read its output: # # cmd = open("|date") # print cmd.gets # cmd.close # # Produces: # # Wed Apr 9 08:56:31 CDT 2003
如果+path+以一个管道字符(
|
)开头,就会创建一个子进程,通过一对管道连接到调用者。 返回的IO对象可用于向该子进程的标准输入写入和从标准输出读取。
因此可以利用open函数的特性通过管道符执行shell
实战例题
- [第三届第五空间网络安全大赛]PNG图片转换器
完
欢迎在评论区留言
这篇关于『CTF Tricks』Ruby-利用File.open()执行shell命令的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15PingCAP 黄东旭参与 CCF 秀湖会议,共探开源教育未来
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升