pet and hack-pet. managing command snippets for security testing
Hi, hackers and bugbounty hunters :D
Today, I'd like to talk about how to easily manage your command snippet, and even more about a project that can share and use snippets together.
오늘은 여러분들의 command snippet을 쉽게 관리하는 방법, 그리고 더 나아가 snippet을 같이 공유하고 사용할 수 있는 프로젝트에 대한 이야기를 하려고 합니다.
What is pet?
Recently, I found a very interesting tool. It is the command-line snippet manager called pet. It has a fast searchable interface such as fzf, and provides the ability to personalize and synchronize snippets through gist.
최근, 상당히 흥미로운 도구를 하나 발견했습니다. 바로 pet이라는 command-line snippet manager입니다. fzf 같은 빠른 검색이 가능한 인터페이스를 가지고있고, gist를 통해 snippet들을 개인화하고 동기화하여 관리할 수 있는 기능을 제공합니다.
pet
pet - Simple command-line snippet manager.
Usage:
pet [command]
Available Commands:
configure Edit config file
edit Edit snippet file
exec Run the selected commands
help Help about any command
list Show all snippets
new Create a new snippet
search Search snippets
sync Sync snippets
version Print the version number
Flags:
--config string config file (default is $HOME/.config/pet/config.toml)
--debug debug mode
-h, --help help for pet
https://github.com/knqyf263/pet
Install with go get
설치는 go get이면 충분합니다.
go get -u github.com/knqyf263/pet
There are several commands, but basically, there are no problems in using them if you know only the four (new``list``exec``search
).
여러 명령이 있지만, 기본적으로 4가지(new``list``exec``search
)만 확실하게 알고가면 사용하는데 전혀 지장이 없습니다.
pet new
Command> Your command
Description> Your Desc
You can use variables (<param>
or <param=default_value>
) in snippets.
new로 새로운 snippet을 등록할 수 있습니다. 이 때 <>
같은 패턴을 통해 사용자로 부터 인자값을 받을 수 있습니다.
pet new
Command> echo <param> | ~/go/bin/gau | grep "=" | qsreplace -a
Description> Find url included parameter, from gau
Show list
list는 저장된 리스트를 봅니다.
pet list
pet list
Description: ps elf!
Command: ps -elf
------------------------------
...snip...
------------------------------
Description: Find url included parameter, from gau
Command: echo <param> | ~/go/bin/gau | grep "=" | qsreplace -a
and exec(if you select, run command) or search(if you select, show command)
exec는 즉시실행, search는 쿼리 보기정도입니다.
pet exec
https://www.hahwul.com/search?updated-max=2019-12-05t02%3A04%3A00+09%3A00
https://www.hahwul.com/2015/12/coding-htmljavascript-code-for-popup.html?showcomment=1532047391164
https://www.hahwul.com/2019/11/burp-suite-using-tor-network.html?m=1
http://www.hahwul.com/2015/06/operator-overloading-for-python-code.html?showComment=1434687933593
http://www.hahwul.com/2015/09/design-sql-injection.html?showComment=1466006407930
http://www.hahwul.com/2016/01/exploit-android-sensord-local-root.html?showComment=1487266696141
http://www.hahwul.com/2016/01/java-java-applet-simle-code-for-java.html?showComment=1482295236658
http://www.hahwul.com/2016/02/metasploit-default-shell-meterpreter.html?showComment=1456212183726
http://www.hahwul.com/2016/07/metasploit-meterpreter-paranoid-mode.html?showComment=1495406771315
http://www.hahwul.com/2016/07/metasploit-meterpreter-railgun-useful.html?showComment=1477038507834
http://www.hahwul.com/2016/07/ruby-writing-web-crawler-with-ruby-and.html?showComment=1467938120314
http://www.hahwul.com/2016/08/hacking-mobile-application.html?showComment=1482063530341
http://www.hahwul.com/2017/01/hacking-microsoft-windows-kernel.html?showComment=1485360093822
http://www.hahwul.com/2017/02/metasploit-hardware-pentest-using.html?showComment=1487524773751
http://www.hahwul.com/2017/02/python-pudbconsole-base-debugger-python.html?showComment=1488463407073
http://www.hahwul.com/2017/03/web-hacking-data-xss-filtering-bypass.html?showComment=1491831511270
....
Shortcut� key binding
To use it after registering snippet, you need to issue a command such as pet exec
to cli. This is a bit annoying, so it is very convenient to do key mappings through zsh/bash rc. In my case, I mapped it with Ctrl+s
.
snippet을 등록한 이후에 이를 사용하려면 cli에 pet exec
등의 명령을 쳐야합니다. 이는 조금 귀찮은 일이기 때문에 zsh/bash rc를 통해 키 매핑을 해두면 굉장히 편합니다. 저의 경우는 Ctrl+s
로 매핑해두었습니다.
zsh.rc
function pet-select() {
BUFFER=$(pet search --query "$LBUFFER")
CURSOR=$#BUFFER
zle redisplay
}
zle -N pet-select
stty -ixon
bindkey '^s' pet-select
bash.rc
function pet-select() {
BUFFER=$(pet search --query "$READLINE_LINE")
READLINE_LINE=$BUFFER
READLINE_POINT=${#BUFFER}
}
bind -x '"\C-x\C-r": pet-select'
If you apply it with the source command afterwards, you can see that pet is executed immediately when the shortcut key is pressed.
이후에 source 명령으로 적용해보면 단축키를 눌렀을 떄 바로 pet이 실행되는 걸 볼 수 있습니다.
source ~/.zshrc
source ~/.bashrc
Um.. share snippet? for we for hackers for bounty hunters?
As I was using pet, I thought it would be good to use it while sharing. So we looked at the function of pet sync
more, but as a result, it is a form that only individuals can share and use (because it is a gist based on their git token..)
pet을 사용하다보니 공유하면서 사용하면 좋을 것 같다는 생각이 들었습니다. 그래서 pet sync
쪽 기능을 좀 더 알아봤지만, 결과적으론 개인만 공유하며 쓸 수 있는 형태입니다(자신의 git token 기준의 gist라서..)
So I was thinking about a project similar to the WebHackersWeapons I created earlier. First, if you do pet edit
, you can modify the snippet information saved as a text file. Through this, you can check the path and format of the saved file. At this time, the location of the original is ~/.config/pet/snippet.toml
and I am using TOML.
그래서 예전에 만든 WebHackersWeapons와 유사한 프로젝트를 고민하게 됬습니다. 우선 pet edit
를 하게 되면 text 파일로 저장된 snippet 정보를 수정할 수 있는데, 이를 통해 저장되는 파일의 경로와 포맷을 확인했습니다.
이 때 원본의 위치는.. ~/.config/pet/snippet.toml
이고 TOML을 사용하고 있네요.
[[snippets]]
description = "Find url included parameter, from gau"
command = "echo <param> | ~/go/bin/gau | grep \"=\" | qsreplace -a"
output = ""
What is TOML
First, let's take a look at the pet behavior a little more. First of all, pet uses TOML when storing all information such as config / snippet.
자 먼저 pet의 동작에 대해 조금 더 살펴봅시다. 우선 pet은 config / snippet 등 모든 정보를 저장할 떄 TOML을 사용합니다.
TOML은 YAML, JSON 등과 같은 데이터 포맷이고 개인적으로 가시성이 좋기 때문에 좋아하는 포맷입니다.
TOML aims to be a minimal configuration file format that's easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table. TOML should be easy to parse into data structures in a wide variety of languages.
https://github.com/toml-lang/toml
golang TOML Parse
Since I am using go, I searched for a go library that can parse TOML. Typically, toml
and go-toml
seem to be used, and I chose a go-toml with active commit.
저는 일단 go를 쓰고 있기 때문에 TOML을 파싱할 수 있는 go library에 대해 찾아봤습니다. 대표적으로 toml
과 go-toml
이 사용되는 것 같고 commit 이 활발한 go-toml을 선택했습니다.
https://github.com/BurntSushi/toml
=> last change : 2 years ago
https://github.com/pelletier/go-toml
=> last change : 9days ago
writing simple code...
이제 테스팅용 코드를 짜보면..
package main
import (
"github.com/pelletier/go-toml"
"fmt"
"os"
)
type PetSnippet struct {
Description string `toml:"description"`
Command string `toml:"command"`
Output string `toml:"output"`
}
func check(e error) {
if e != nil {
panic(e)
}
}
func main(){
data := PetSnippet{Description: "abcd",Command: "abcd",Output: "abcd"}
b, err := toml.Marshal(data)
check(err)
buffer := "[[snippet]]\n"+string(b)+"\n"
fmt.Println(buffer)
f , err := os.Create("asdf.daml")
check(err)
_, err = f.Write([]byte(buffer))
}
go run main.go
[[snippet]]
command = "abcd"
description = "abcd"
output = "abcd"
cat asdf.daml
[[snippet]]
command = "abcd"
description = "abcd"
output = "abcd"
Yeaaaaa
크게 무리없이 잘 되네요!
hack-pet !
So, since last night, I've been writing code. It is a tool to create and manage hackpet.toml
, which contains all snippet information, and ./snippets
directory that stores each individual file.
그래서, 어제 밤부터 후다닥 코드를 작성해봤습니다. 모든 snippet 정보를 담고있는 hackpet.toml
과 각 개별 파일로 보관하는 ./snippets
directory 를 만들고 관리할 수 있는 도구입니다.
https://github.com/hahwul/hack-pet
You can read and apply the desired snippet.toml from ./snippets
or copy hackpet.toml
to pet's snippet.toml file and use it. After copying, hack-pet snippets will appear in the pet command.
./snippets
에서 원하시는 snippet.toml 을 읽어 적용하시거나 hackpet.toml
을 pet의 snippet.toml 파일로 복사하셔서 사용하시면 됩니다.
cat ./hackpet.toml >> ~/.config/pet/snippet.toml
복사한 이후에는 hack-pet의 snippet들이 pet 명령에서 나타나게 됩니다.
Conclusion
We need your help to share and activate good snippets. Be a good Contributer!