2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

picoCTF 2023 Writeup : General Skills

Posted at

最初に

全部で6問あります!
(解き始める前にキャプチャとるの忘れていた、、、)

image.png

Writeup

repetitions

以下の内容が記載されたテキストファイルがダウンロードできます

VmpGU1EyRXlUWGxTYmxKVVYwZFNWbGxyV21GV1JteDBUbFpPYWxKdFVsaFpWVlUxWVZaS1ZWWnVh
RmRXZWtab1dWWmtSMk5yTlZWWApiVVpUVm10d1VWZFdVa2RpYlZaWFZtNVdVZ3BpU0VKeldWUkNk
MlZXVlhoWGJYQk9VbFJXU0ZkcVRuTldaM0JZVWpGS2VWWkdaSGRXCk1sWnpWV3hhVm1KRk5XOVVW
VkpEVGxaYVdFMVhSbFZrTTBKeldWaHdRMDB4V2tWU2JFNVdDbUpXV2tkVU1WcFhWVzFHZEdWRlZs
aGkKYlRrelZERldUMkpzUWxWTlJYTkxDZz09Cg==

==があり、BASE64っぽいので一度BESE64でデコードしてみると、以下になります。

VjFSQ2EyTXlSblJUV0dSVllrWmFWRmx0TlZOalJtUlhZVVU1YVZKVVZuaFdWekZoWVZkR2NrNVVX
bUZTVmtwUVdWUkdibVZXVm5WUgpiSEJzWVRCd2VWVXhXbXBOUlRWSFdqTnNWZ3BYUjFKeVZGZHdW
MlZzVWxaVmJFNW9UVVJDTlZaWE1XRlVkM0JzWVhwQ00xWkVSbE5WCmJWWkdUMVpXVW1GdGVFVlhi
bTkzVDFWT2JsQlVNRXNLCg==

最初と比べて1行減りました!
この調子でBASE64でデコードしていくとフラグが手に入ります

picoCTF{base64_n3st3d_dic0d!n8_d0wnl04d3d_73494190}

useless

picoplayer@challenge:~$ cat useless 
#!/bin/bash
# Basic mathematical operations via command-line arguments

if [ $# != 3 ]
then
  echo "Read the code first"
else
        if [[ "$1" == "add" ]]
        then 
          sum=$(( $2 + $3 ))
          echo "The Sum is: $sum"  

        elif [[ "$1" == "sub" ]]
        then 
          sub=$(( $2 - $3 ))
          echo "The Substract is: $sub" 

        elif [[ "$1" == "div" ]]
        then 
          div=$(( $2 / $3 ))
          echo "The quotient is: $div" 

        elif [[ "$1" == "mul" ]]
        then
          mul=$(( $2 * $3 ))
          echo "The product is: $mul" 

        else
          echo "Read the manual"
         
        fi
fi

manualを読めと書いてありますが、ここにはありません、、、

ルートディレクトリに移動して、Grepでmanualの文字を含むファイルを探しますが、こちらも見つかりません、、、


picoplayer@challenge:/$ grep -r "manual"  2>/dev/null
etc/groff/man.local:.  \" manual pages you're writing are clear of this problem.
etc/groff/man.local:.  \" signs in manual pages, so map it to plain "-" for HTML/XHTML output
etc/groff/mdoc.local:.  \" manual pages you're writing are clear of this problem.
etc/groff/mdoc.local:.  \" signs in manual pages, so map it to plain "-" for HTML/XHTML output
etc/hosts.allow:#                   See the manual pages hosts_access(5) and hosts_options(5).
etc/hosts.deny:#                  See the manual pages hosts_access(5) and hosts_options(5).
etc/manpath.config:# be used to manipulate the manual pages. Also, mandb will not initialise
etc/wgetrc:## not contain a comprehensive list of commands -- look at the manual
etc/wgetrc:##   https://www.gnu.org/software/wget/manual/wget.html#Startup-File
home/picoplayer/useless:          echo "Read the manual"
proc/kallsyms:0000000000000000 t __pfx_twl6040_power_up_manual
proc/kallsyms:0000000000000000 t twl6040_power_up_manual
proc/kallsyms:0000000000000000 T __pfx_da9052_adc_manual_read
proc/kallsyms:0000000000000000 T da9052_adc_manual_read
proc/kallsyms:0000000000000000 r __ksymtab_da9052_adc_manual_read
proc/dynamic_debug/control:drivers/usb/core/message.c:1595 [usbcore]usb_set_interface =_ "manual set_interface for iface %d, alt %d\n"

他にマニュアルっぽいものあるかなと思って、manコマンドを思い出したので、こちらを試してみると見つかりました

picoplayer@challenge:~$ man useless

useless
     useless, — This is a simple calculator script

SYNOPSIS
     useless, [add sub mul div] number1 number2

DESCRIPTION
     Use the useless, macro to make simple calulations like addition,subtraction, multiplication and division.

Examples
     ./useless add 1 2
       This will add 1 and 2 and return 3

     ./useless mul 2 3
       This will return 6 as a product of 2 and 3

     ./useless div 6 3
       This will return 2 as a quotient of 6 and 3

     ./useless sub 6 5
       This will return 1 as a remainder of substraction of 5 from 6

Authors
     This script was designed and developed by Cylab Africa

     picoCTF{us3l3ss_ch4ll3ng3_3xpl0it3d_3823}

Permissions

問題文から権限に関わる問題のようです

SSHをした後に現在sudo権限で実行できるコマンドを調べると、viが使えるみたいです


picoplayer@challenge:/$ sudo -l
[sudo] password for picoplayer: 
Matching Defaults entries for picoplayer on challenge:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User picoplayer may run the following commands on challenge:
    (ALL) /usr/bin/vi

viが使えるということは、権限周りを記載しているファイルをそのまま書き換えればいいのでは?と思い、以下の記事を参考にしつつ、やっていきました

まずは、etc/sudoersを見てどのグループに権限が割り振られているのかを確認すると、sudoグループはすべてのコマンドが使えるようになっていました

Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

なので、まずはetc/groupを書き換えて、picoplayerをsudoグループに所属させます

picoplayer@challenge:/$ sudo vi etc/group
[sudo] password for picoplayer: 

picoplayer@challenge:/$ cat etc/group | grep pico
sudo:x:27:picoplayer
picoplayer:x:1000:

picoplayer@challenge:/$ groups picoplayer
picoplayer : picoplayer sudo

これで、picoplayerがsudoグループに所属しました!
suして、再度sudo権限で実行できるものを探します

picoplayer@challenge:/$ su picoplayer
Password: 
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

picoplayer@challenge:/$ sudo -l
Matching Defaults entries for picoplayer on challenge:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User picoplayer may run the following commands on challenge:
    (ALL : ALL) ALL
    (ALL) /usr/bin/vi
picoplayer@challenge:/$ 

無事すべてのコマンドを実行できるようになりました!

あとは、rootディレクトリのファイルを出力して、

picoplayer@challenge:/$ sudo find /root  -type f
/root/.bashrc
/root/.profile
/root/.viminfo
/root/.flag.txt

.flag.txtにフラグが記載されていました!

picoplayer@challenge:/$ sudo vi /root/.flag.txt

chrono

問題文にLinuxの自動実行に関することが記載されていたので、/etc/crontabを見てみたら、フラグがありました笑

picoplayer@challenge:/etc$ ls -la | grep cron
drwxr-xr-x 1 root   root       26 Aug  4  2023 cron.d
drwxr-xr-x 1 root   root       26 Aug  4  2023 cron.daily
drwxr-xr-x 2 root   root       26 Aug  4  2023 cron.hourly
drwxr-xr-x 2 root   root       26 Aug  4  2023 cron.monthly
drwxr-xr-x 2 root   root       26 Aug  4  2023 cron.weekly
-rw-r--r-- 1 root   root       43 Aug  4  2023 crontab
picoplayer@challenge:/etc$ cat crontab 
# picoCTF{Sch3DUL7NG_T45K3_L1NUX_7754e199}

Special

問題文から、スペルを自動補完するプログラムを開発したみたいですね

パワーユーザーはシェルでスペルミスをするのに疲れませんか? もうそんなことはありません! Affecting Linuxのスペルチェック・インターフェース、Specialの登場です。 今、すべての単語は適切に綴られ、大文字になります...自動的に、そして舞台裏で! ベータ版のSpecialをいち早く試して、Specialがどのようにあなたの開発プロセスを効率化するか、私たちに教えてください。 あなたの同僚があなたの素晴らしいシェル・インターフェイスを見たら、ぜひ教えてあげてください

SSHでつないで、試してみましたが、なんだかよくわからない変換をされる。。。
lsIsにしているあたりが特にしんどい。、、

Special$ ls
Is 
sh: 1: Is: not found
Special$ pwd
Pod 
sh: 1: Pod: not found

似たようなものを試してみました。
1Iになるあたり、形で選んでいそうです

Special$ 1s
Is 
sh: 1: Is: not found

加えて、1文字目以外も変わってしまうのが、やっかいですね。。

Special$ sl
So 
sh: 1: So: not found

文字列の一部を切り出すと変換後の文字列が変わる

Special$ asdfl
Abdul 
sh: 1: Abdul: not found
Special$ as
As 
sh: 1: As: not found

同じ入力に対しては、同じ出力を返すみたいです。。

Special$ as
As 
sh: 1: As: not found
Special$ as
As 
sh: 1: As: not found

なんだこれは、、、、となってしまったので、Writeupを見てみました。

シェル芸を使って先頭に関係のない文字列をいれるみたいです。。。。

ということで、さっそくやっていきます!

Special$ $(:)ls $(:)-la
$(:)ls $(:)-la 
total 0
drwxr-xr-x 1 ctf-player ctf-player 20 Mar  3 05:48 .
drwxr-xr-x 1 root       root       24 Mar 16  2023 ..
drwx------ 2 ctf-player ctf-player 34 Mar  3 05:48 .cache
drwxr-xr-x 2 ctf-player ctf-player 22 Mar 16  2023 blargh

blarghディレクトリがあったので、そのディレクトリ内でpicoの文字列が記載されているファイルを探したら、ありました!

Special$ $(:)grep $(:)pico $(:)-rl $(:)./
$(:)grep $(:)pico $(:)-rl $(:)./ 
./blargh/flag.txt

あとは、このflag.txtをcatしたらフラグが手に入ります!

Special$ $(:)cat $(:)./blargh/flag.txt
$(:)cat $(:)./blargh/flag.txt 
picoCTF{5p311ch3ck_15_7h3_w0r57_0c61d335}Special$ 

Specialer

1つ前の問題を改良したみたいです。。。

入力したものはそのまま使えるが、よく使うコマンドがない、、、

Specialer$ cat
-bash: cat: command not found
Specialer$ ls
-bash: ls: command not found

何かないかなと思って、helpコマンドで使えるコマンドを確認

Specialer$ help
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
These shell commands are defined internally.  Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.

A star (*) next to a name means that the command is disabled.

 job_spec [&]                                                            history [-c] [-d offset] [n] or history -anrw [filename] or history >
 (( expression ))                                                        if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ e>
 . filename [arguments]                                                  jobs [-lnprs] [jobspec ...] or jobs -x command [args]
 :                                                                       kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill ->
 [ arg... ]                                                              let arg [arg ...]
 [[ expression ]]                                                        local [option] name[=value] ...
 alias [-p] [name[=value] ... ]                                          logout [n]
 bg [job_spec ...]                                                       mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [->
 bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r ke>  popd [-n] [+N | -N]
 break [n]                                                               printf [-v var] format [arguments]
 builtin [shell-builtin [arg ...]]                                       pushd [-n] [+N | -N | dir]
 caller [expr]                                                           pwd [-LP]
 case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac              read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] >
 cd [-L|[-P [-e]] [-@]] [dir]                                            readarray [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] >
 command [-pVv] command [arg ...]                                        readonly [-aAf] [name[=value] ...] or readonly -p
 compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W word>  return [n]
 complete [-abcdefgjksuv] [-pr] [-DEI] [-o option] [-A action] [-G glo>  select NAME [in WORDS ... ;] do COMMANDS; done
 compopt [-o|+o option] [-DEI] [name ...]                                set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
 continue [n]                                                            shift [n]
 coproc [NAME] command [redirections]                                    shopt [-pqsu] [-o] [optname ...]
 declare [-aAfFgilnrtux] [-p] [name[=value] ...]                         source filename [arguments]
 dirs [-clpv] [+N] [-N]                                                  suspend [-f]
 disown [-h] [-ar] [jobspec ... | pid ...]                               test [expr]
 echo [-neE] [arg ...]                                                   time [-p] pipeline
 enable [-a] [-dnps] [-f filename] [name ...]                            times
 eval [arg ...]                                                          trap [-lp] [[arg] signal_spec ...]
 exec [-cl] [-a name] [command [arguments ...]] [redirection ...]        true
 exit [n]                                                                type [-afptP] name [name ...]
 export [-fn] [name[=value] ...] or export -p                            typeset [-aAfFgilnrtux] [-p] name[=value] ...
 false                                                                   ulimit [-SHabcdefiklmnpqrstuvxPT] [limit]
 fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]        umask [-p] [-S] [mode]
 fg [job_spec]                                                           unalias [-a] name [name ...]
 for NAME [in WORDS ... ] ; do COMMANDS; done                            unset [-f] [-v] [-n] [name ...]
 for (( exp1; exp2; exp3 )); do COMMANDS; done                           until COMMANDS; do COMMANDS; done
 function name { COMMANDS ; } or name () { COMMANDS ; }                  variables - Names and meanings of some shell variables
 getopts optstring name [arg]                                            wait [-fn] [id ...]
 hash [-lr] [-p pathname] [-dt] [name ...]                               while COMMANDS; do COMMANDS; done
 help [-dms] [pattern ...]                                               { COMMANDS ; }
S

printfは使えそう!
と思って、ファイルを見つけて中身をみてみたが、違うみたい、、、

Specialer$ printf *
abra
Specialer$ cd abra
Specialer$ printf *
cadabra.txt
Specialer$ echo "$(<cadabra.txt)"
Nothing up my sleeve!

やっていることはあっていそうだが、フラグがない、、、、

以下のQiitaの記事を見てみると、改行を入れているみたい、、

Specialer$ printf "%s\n" *
abra
ala
sim

順番にみていけば、フラグがありました!

Specialer$ cd ala
Specialer$ printf "%s\n" *
kazam.txt
mode.txt
Specialer$ echo "$(<kazam.txt)"
return 0 picoCTF{y0u_d0n7_4ppr3c1473_wh47_w3r3_d01ng_h3r3_811ae7e9}

最後に

今回学んだことは以下です

  • ユーザーをsudo グループに入れることで、権限を付与できる
  • Linuxが事前に用意したコマンドを使う経験
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?