簡體   English   中英

有沒有辦法執行 txt 文件中的 vim 命令以及文本?

[英]Is there a way to execute vim commands that are within txt file along with text?

我在我的 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”更大的事情,因為我手動嘗試過並且標志不正確。 提前致謝!

對的,這是可能的。 當使用-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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM