ãã£ð²ã¿ãŒããã«ðœã§ããã³ããðŸã«ãé¡æåãã©ã³ãã 衚瀺ãããããã ã£ãŠïŒð±ðð¶
ãã®èšäºã¯ã·ã§ã«ã¹ã¯ãªãã Advent Calendar 2021ã®5æ¥ç®ã®èšäºã§ãïŒ
12æ5æ¥æç¹ã§5æ¥ç®ä»¥éãå
šãåãŸã£ãŠããªãã£ãã®ã§ãããã©ããªèšäºã§ãã·ã§ã«ã«é¢ä¿ããŠããããã®ããªã£ãŠããšã§ãã£ã¡ãããŸããïŒð
ãŸãã·ã§ã«ã®é
åã®ããæ¹ãšãæžããŠãããããã£ã¹ãšãâŠâŠïŒ
ãããããããããã ,,,,,,,,,,
ããããããã,..':ÂŽ:ÂŽ: ãã /.:ïœäž¶ã
ããããã.__/ : : : : : : .㜠ãi: : : : . ::ãœ_
ããã /ÂŽ::::!: : : ., â'ÂŽï¿£lã ïœlï¿£ïœ ïœ°ãïœãœãããããããå§ããã¯ã³ïŒ
ãã / :::::::::!: : : l:::::â:::ïŸã.....::â::i: |::::::i
ã ./::::::::::::::i: : : l::::::.ïŒãã.ïœïœ€:.:|: !:::::::i
ã/.::::::::::::::::l: : : !:ïŒ ã ãïŒ::::::::::::ïŒãi .:|:::::::|
ã| :::::::::::::::::|: :.:. l.ããããã ̄ ̄ããïœ:.:!:::::::|
ã ãœ::::::::::::::|: : . :|ã ã ããããlãããl :l::::::::!
ãã,人:::::::::|: : :ãlããããã ,.'ÂŽ`ããl./:::::/
ã/:::::::ïœ'...'' :ãlãããã/ããã iã /ïŸ'''â'
/:::::::::::::ããããïœãœïœ€____..ïŸ ï¿£ï¿£ .ãâ²ãœã
ããããããããããããããããããããã ãœ
ããã¿ãŒããã«ã«é¡æåã©ã³ãã ã§è¡šç€ºãããŠãããã
bashã§ãzshã§ãã¿ãŒããã«ã®ããã©ã«ãã®ããã³ããã¯ãã¹ããããç¡å³ä¹Ÿç¥ãšããŠãããªãïŒïŒ
è²ã
æ€çŽ¢ãããšã¿ãŒããã«ããªã·ã£ã³ãã£ãŒã«ããæ¹æ³ã¯æ°å€èŠã€ãããã©ããâŠâŠ
ã§ãâŠâŠããã§ãããã®ããããã£ãããšã¯ã©ãã«ãèŒã£ãŠãªãã£ã(èŠã€ããããªãã£ãã ãïŒ)
ããã¯ã©ãããŠãé¡æåãã©ã³ãã ã§è¡šç€ºãããŠããã ïŒïŒïŒïŒ
ã³ãã³ããå®è¡ããŠããã³ããã衚瀺ããããã³ã«
canalunð $
canalunðŸ $
canalunð³ $
canalunð® $
ãããªé¢šã«å€ãã£ãã楜ããããªãïŒïŒïŒïŒïŒïŒïŒïŒïŒïŒïŒïŒïŒïŒïŒ
(楜ãããªã人ã¯ãããªèšäºèªãã§ãªãã§ä»ã«è¡ã£ãŠãã ãã)
å®éã«ãã£ãŠã¿ãå³ããã¡ãâ
æªããªãâŠâŠæªããªãã ãïŒïŒ
é¡æåãã楜ãããªããªããŠããã€ã³ãã£è ããä»åã®æ¹æ³ãå¿çšããŠèµ·åæã®AAã©ã³ãã 衚瀺ãšã奜ãã«èšå®ã§ãããïŒmetasploitã¿ãããªãã€ãã¡ãã£ãšã¯çãäžãã£ãŠããã ããïŒ
ã©ããã£ãŠããã ãïŒïŒïŒ
ãã¡ããã¡ãåçŽã«èããŠã¿ããšãããªããšãâ
- é¡æåããããè©°ã蟌ãã é åãçšæãã
- é åããã©ã³ãã ã«äžã€èŠçŽ ãåãåºã
- 2ã®åŠçãããã³ããã®æŽæ°ã®ãã³ã«å®æœãããããã«ããŠãã
- åãåºããèŠçŽ ãããã³ããã«ã¶ã£ãã
æ°ã¥ãã¡ãŸã£ãã ãããã©ãäžã®äœæŠãæçŽã«ããããªã¬ã¯
çµè«ããèšããšãããã./.zshrcã«ã¶ã¡ããã°ããŸããã
# 1. é¡æåããããè©°ã蟌ãã é
åãçšæãã
FACE_LIST=("ð" "ð" "ð" "ð" "ð" "ðª" "ð¶" "ðŸ" "ð ")
# 2. é
åããã©ã³ãã ã«äžã€èŠçŽ ãåãåºã
alias randomize_face='FACE=${FACE_LIST[$((1 + $RANDOM % ${#FACE_LIST[@]}))]}'
# 3. 2ã®åŠçãããã³ããã®æŽæ°ã®ãã³ã«å®æœãããããã«ããŠãã
precmd () { randomize_face }
# 4. åãåºããèŠçŽ ãããã³ããã«ã¶ã£ãã
setopt PROMPT_SUBST
PS1='%F{green}%nã¯%F{cyan}%~ãªã$FACE%f
\$ '
ãããããããããã¯äžå¿èª¿ã¹ãããšãšã亀ãã€ã€è§£èª¬ããã
1. é¡æåããããè©°ã蟌ãã é åãçšæãã
ã·ã§ã«ã¹ã¯ãªããã«ãããé å
ã·ã§ã«ã¹ã¯ãªããã§ã¯é åããããªé¢šã«å®çŸ©ããã
("ã" "ã" "ã")
ã³ã³ãã¯ãããªãããæ°ãã€ããªïŒ
ã§ããŸããããã·ã§ã«å€æ°ã«ã¶ã¡ãããšããŸã§ã¯ã³ã»ããã§ãããªã
FACE_LIST=("ð" "ð" "ð" "ð" "ð" "ðª" "ð¶" "ðŸ" "ð ")
ã¡ãªã¿ã«ã€ã³ãŒã«ã®äž¡ç«¯ã«ã¹ããŒã¹ãšãå ¥ãããšãã·ã§ã«ã«ãäœãã£ãŠãã®ãåãã£ãŠé¡ãããã
2. é åããã©ã³ãã ã«äžã€èŠçŽ ãåãåºã
ã·ã§ã«ã¹ã¯ãªããã§é åã®èŠçŽ ãåãåºã
ãŸãã»ããšçµè«ããæžããªããŠäžèº«ã¹ã«ã¹ã«ã«èŠãããã ãã©ãããã ã
# ${ããã«é
åã®åå[ããã«èŠçŽ ã®ã€ã³ããã¯ã¹]}
$ FACE_LIST=("ð" "ð" "ð" "ð" "ð" "ðª" "ð¶" "ðŸ" "ð ")
$ echo ${FACE_LIST[1]}
ð
泚ææ·±ãèªè
ã®æ¹ã
ã¯æ°ã¥ãã ãããã©ãã€ã³ããã¯ã¹ã¯1ããå§ãŸããŸã
ã·ã§ã«ã¹ã¯ãªããããã¯ç§ãã¡äººéãé çªãæ°ãããšãã®ããã«ã1çªç®ã2çªç®ãã£ãŠæ°ããŠãããŠãããã ãæ³£(æžããã£ã瀟äŒã§åªããã«è§Šãããšãã«æµããããã®å³ããåã¯ç¥ã£ãŠãããïŒïŒ)
ã·ã§ã«ã¹ã¯ãªããã§ä¹±æ°çæ
åé¡ã¯ã·ã§ã«ã¹ã¯ãªããã§ã©ããã£ãŠä¹±æ°ã€ããããã£ãŠããšã ãã
ãããªãšãã¯ãã®åªæãå±ãããšããã§ãã
# 1~10ã®ä¹±æ°ãäœã
i=$((1 + $RANDOM % 10))
$RANDOMã¯ã·ã§ã«ã«å
ã
ããããã§ããé¢æ°ã§ã0ãã32767(ã¿ããªããªãã¿2byteã®äžéã§ããª)ã®ç¯å²ã§ç䌌乱æ°ãäœã£ãŠãããã®ã
ã·ã§ã«ã ãšã€ã³ããã¯ã¹ã1ããå§ãŸãã£ãŠãããã£ãã®äºæ
ãçžãŸã£ãŠããã®åªæã¯éèŠ
ã·ã§ã«ã®ã©ã³ãã åŠçããã£ãšæ·±å ãããïŒã£ãŠäººã¯äžã®èšäºãè¯ãããã ã£ãããèŠãŠã¿ãŠã
($RANDOMã®è©³çŽ°ç¥ãããïŒïŒãšãããã¯ã¬ããããã¯TLDPçºããŠãã ãã)
ã¡ãªã¿ã«ãã«ããŒã¯ã®ããšã«ã«ãã³ã2ã€ã€ããã®ã¯ç®è¡èšç®ã®å®è¡ãæå³ããŠããšã³
硬掟ãªäººã¯TLDPèªãã§ãããããããã§ããã©ãäžã®èšäºã«ããããæžããŠãã£ãŠå©ãããŸããðŸ
ã·ã§ã«ã¹ã¯ãªããã§é åã®èŠçŽ æ°ãååŸãã
ããä¹±æ°çæã®åªæã¯ããã£ããã©ãã©ããã£ãŠé
åã®ãµã€ãºãååŸããããã£ãŠæã£ãããªã
ããã§ãé£ã£ãšãïŒ
# ${#ããã«é
åã®åå[@]}
$ FACE_LIST=("ð" "ð" "ð" "ð" "ð" "ðª" "ð¶" "ðŸ" "ð ")
$ echo {#FACE_LIST[@]}
9
ãšããããã§ãããŸã§ã®è¶ 絶æå·§ãçµã¿åããããšäžèšã®ã³ãã³ããã§ãããããŸã
alias randomize_face='FACE=${FACE_LIST[$((1 + $RANDOM % ${#FACE_LIST[@]}))]}'
randomizer_faceã³ãã³ããå®è¡ãããã³ã«ãFACEãªãã·ã§ã«å€æ°ã«ã©ã³ãã ã§é¡æåãã¶ã¡ããŸããŸãïŒïŒïŒ
3. 2ã®åŠçãããã³ããã®æŽæ°ã®ãã³ã«å®æœãããããã«ããŠãã
ããŠããŠãã¿ãŒããã«ã§ããã³ãããèªã¿èŸŒãŸãããã³ã«ã³ãã³ããå®è¡ããããå Žåã¯.zshrcãªã.bashrcãªãã«äžèšã®èšèŒãããŠå·®ãäžãããšãããã
precmd () { ããã«æžããããšãããã³ããã®æŽæ°ã®ãã³ã«å®è¡ãããŸã }
4. åãåºããèŠçŽ ãããã³ããã«ã¶ã£ãã
ã¶ã£ãã¿æ¹
ãããããã€ãã«ã¶ã£ãã¿ã§ã
ãŸãçµè«ããèšããšããã
setopt PROMPT_SUBST
PS1='%F{green}%nã¯%F{cyan}%~ãªã$FACE%f
\$ '
setopt PROMPT_SUBSTã£ãŠã®ã¯ãããã³ããã®å®çŸ©ã®äžã«ãã¡ãã¡å±éããŠãããªããšãããªããã®(ã·ã§ã«å€æ°ãšãã³ãã³ã)ãå ¥ã£ãŠãããšããã¡ãããšé¢åèŠãŠãããããã«ããããã®ãã®ã§ãâ
# 衚瀺ãããããã³ããã®æ¯èŒ
$ canalunã¯~ãªã$FACE # setopt PROMPT_SUBSTãªãã®ãšã: ã·ã§ã«å€æ°FACEãå±éãããªã
$ canalunã¯~ãªãð # setopt PROMPT_SUBSTããã®ãšã: ã·ã§ã«å€æ°FACEãå±éãããïŒ
ã¡ãªã¿ã«PS1ã¯ãããã³ããã®å®çŸ©ãå ¥ããŠãããããã®prompt variableãšåŒã°ããå€æ°ïŒ
PS1 is a primary prompt variable which holds \u@\h \W\$ special bash characters. This is the default structure of the bash prompt and is displayed every time a user logs in using a terminal. These default values are set in the /etc/bashrc file.
PS1
ãã£ãprompt variableã¯PS4ãŸã§ãããš
ã¶ã£ãã¿æã®æãã¬æ³šæç¹
ããšããã¡ããã¡ãå°å³ãªãã ãã©æ³šæç¹ã
å±éãå¿
èŠãªèŠçŽ (ã·ã§ã«å€æ°ãšãã³ãã³ã)ãããã³ããå®çŸ©ã«å
¥ãããšãã¯ãããã«ã¯ã©ãŒããŒã·ã§ã³ãããªããŠã·ã³ã°ã«ã¯ã©ãŒããŒã·ã§ã³ã«ããŠããããããã£ããå±ãªã
ã·ã§ã«ã§æååå®çŸ©ãããšãã£ãŠãããã«ã¯ã©ãŒããŒã·ã§ã³äœ¿ããšå±éããŠãããŠãã·ã³ã°ã«ã¯ã©ãŒããŒã·ã§ã³ã ãšæååãã®ãŸãŸ(å€æ°ãšãã®å±éãªã)ã ããçŽæçã«ã¯éãªãã ããããŸããã®ãžãæ°ã«ãªããªãäžã®ã¹ã¬èŠãŠã¿ãŠãã ãã
ãããŸãã ãïŒïŒïŒ
ããŠããã§çµãããªããã§ããã©ãããããã¿ãŒããã«ã«ã¯æå€ãšå¿çšå¹ãããããïŒïŒ
é¡æåãããªããŠãªã·ã£ã¬ãªAAã®é
åãäœã£ãŠãããŠããããã©ã³ãã ã§åŒã³åºãã³ãã³ãã€ããã°ãmetasploitã¿ããã«ããæãã®ãã€ãã§ããã
ãªãããã¡ãã»ã³ã¹ã®ããå¿çšãå¹ããããã人ãããããã²ã³ã¡ã³ãã§æããŠãã ããïŒïŒã»ããããŸãããã
Discussion