【问题标题】:Is there a way to execute vim commands that are within txt file along with text?有没有办法执行 txt 文件中的 vim 命令以及文本?
【发布时间】:2021-03-08 15:33:31
【问题描述】:

我正处于 CTF 的最后阶段,我有这个:

vim flag
iCourse{v3ry_g00d_fl4g}[ESC]13hs1[ESC]am_[ESC]9l2xli_[ESC]2li3[ESC]vypaks[ESC]:s/ry/15
:wq 

我对 Vim 不是很熟悉,所以我不知道如何运行这个脚本。我猜它必须做的事情比用“15”替换“ry”更大,因为我手动尝试过并且标志不正确。提前致谢!

【问题讨论】:

  • 你必须完全像那样输入所有内容,除了[ESC] 表示按退出键。 FWIW,这会产生 Course{v3m_15_g00d_4_g33ks}
  • @L3viathan 不正确 :( 我很好奇你是怎么知道的?
  • @L3viathan Course{v1m_15_g00d_4_g33ks} 是正确的,但我只是假设它更有意义 :) 不要打扰,但你介意告诉我我必须做什么才能得到它吗?我正在尝试输入“iCourse{v3ry_g00d_fl4g}13hs1am_9l2xli_2li3vypaks”,然后执行 :s/ry/15 但它与我上面描述的效果相同。 ;(
  • 启动vim后,我输入iCourse{v3ry_g00d_fl4g},然后按escape切换回普通模式,然后输入13hs1,再按escape,以此类推。哦,我知道为什么对我来说是 v3m:因为我已经将 s 重新映射为 vim-surround :)
  • @L3viathan,非常感谢! :)

标签: vim ctf


【解决方案1】:

是的,这是可能的。当使用-s 命令行标志启动时,vim 将从输入文件中获取命令:

来自手册页:

-s {scriptin}
      The  script  file {scriptin} is read. The characters in the
      file are interpreted as if you had typed them. The same can
      be done with the command ":source! {scriptin}". If the end
      of the file is reached before the editor exits, further
      characters are read from the keyboard.

所以你需要做的就是使用像sed 这样的工具将[ESC] 的每次出现转换为转义字符,将结果存储在临时文件中,然后将其提供给vim

s='iCourse{v3ry_g00d_fl4g}[ESC]13hs1[ESC]am_[ESC]9l2xli_[ESC]2li3[ESC]vypaks[ESC]:s/ry/15'
cmdfile=`mktemp`
echo -e `sed 's/\[ESC\]/\\\x1B/g' <<<"$s"` >$cmdfile
vim -s $cmdfile

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 2021-10-20
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多