picoCTF 2018 – Hideout (General Skills) 上

CTF網址:
https://picoctf.com/

一開始進去之後解完基本三題
就可以回到上一頁看到所有題目的分類
在圖片中央的城市裡面
充滿的是所有CTF基本常識的題目
然後左上角的Cryptography是需要熟知各種加密演算法才能解開的題目
左下角的webExploitation是網頁漏洞的滲透,最好是能熟知各種網頁語言
正下方的Reverse Engineering是逆向工程,要開始之前先去看看組合語言
右下方的Forensics主要是需要鑑識的技術
右上角的BinaryExploitation則是偏向找出程式邏輯漏洞

Linux一些小指令

創資料夾 mkdir
創檔案 touch
寫入內容(覆蓋) echo ‘內容’ > 檔名
寫入內容(不覆蓋) echo ‘內容’ >> 檔名

各進制轉換

https://www.convertworld.com/zh-hant/numerals/hexadecimal.html
二進位(Binary;bin)八進位(Octal;oct)十進位(Decimal;dec)十六進位(Hexadecimal;hex)

Grep and Regular Expressions!

Grep and Regular Expressions
https://ryanstutorials.net/linuxtutorial/grep.php

題目: grep 1

Hint:
https://ryanstutorials.net/linuxtutorial/grep.php

打開VMare的Ubuntu

利用cat查看一下內容,的確很混亂

利用提示的指令去尋找

一開始試了

egrep 'flag' file

發現找不到東西, 換個思路想,
最後需要submit的內容是picoCTF{}格式

egrep 'pico' file

找到答案

題目: net cat

下載並安裝netcat
https://blog.gtwang.org/linux/linux-utility-netcat-examples/

nc -v 2018shell.picoctf.com 49387

題目: Aca-Shell-A

Learn basic commands for Linux
https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners

write-up
https://github.com/PlatyPew/picoctf-2018-writeup/tree/master/General%20Skills/Aca-Shell-A

進入server後依照他的指示輸入指令

題目: strings

Hint:
https://linux.die.net/man/1/strings
http://man.linuxde.net/strings

利用指令(工具)

strings strings

可以看到正常的內文,可是內文非常的多阿!

要怎麼知道答案在哪裡?

利用前面學過的grep

將strings跟grep一起用

strings strings | egrep 'pico'

題目: pipe

Hint:
http://www.linfo.org/pipes.html

http://linux.vbird.org/linux_basic/0320bash.php#pipe_1

利用nc連到指定的port

nc -v 2018shell.picoctf.com 37542

結果會跳出一堆文字,說這邊沒有flag你要找其他行

所以利用pipe加上grep指令

nc -v 2018shell.picoctf.com 37542 | grep 'pico'

題目: grep 2

Hint:(跟grep 1的一樣)
https://ryanstutorials.net/linuxtutorial/grep.php

http://linux.vbird.org/linux_basic/0330regularex.php

首先shell server是2018shell.picoctf.com
可是沒有給你port

找了一陣子發現…
他的shell server應該是右上角那個

首先會要登入,輸入註冊的帳號密碼即可

進入shell後先到指定的file路徑

到路徑後
發現指令 egrep ‘pico’ files
顯示錯誤沒有files
利用指令ls查看一下這個資料夾有甚麼
發現有好多個file

這邊搭配正規表示式跟egrep兩者使用

^ – matches the beginning of the line.

因為每個檔案開頭都是file 所以用^file

發現沒用, 改成用file*

執行後發現有問題, 他說是資料夾(directory)而不是檔案

驚為天人!!! 0.0

隨便進入一個directory一看,發現裡面還是很多檔案

不過全部檔案都是file開頭

所以google一下有甚麼辦法可以
直接查看目錄底下全部檔案的內容(包含子資料夾)
https://www.opencli.com/linux/grep-directory-all-files
發現很快就找到答案

grep -r 'picoCTF' *

題目: environ

Hint:
https://www.tutorialspoint.com/unix/unix-environment.htm

http://linux.vbird.org/linux_basic/0320bash.php#variable

在Linux中輸入env指令 (env 是 environment簡寫)
會顯示系統中全部的環境變數
如果只要列出特定的變數
可以使用下列

echo $DISPLAY

到網站上的shell
輸入指令

env | grep 'picoCTF'

也就是列出所有變數->篩選有符合picoCFT字串的內容

SECRET_FLAG=picoCTF{eNv1r0nM3nT_v4r14Bl3_fL4g_3758492}

題目: ssh-keyz

Hint:
https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html
https://www.youtube.com/watch?v=3CN65ccfllU&list=PLJ_vkrXdcgH-lYlRV8O-kef2zWvoy79yP&index=4

這題只是要產生ssh key而已

而我之前用github的時候已經有產生過了

所以先試看看用這個ssh key能不能成功

查看的教學如下
https://blog.csdn.net/shog808/article/details/76563136

按照hint的youtube教學,貼上自己的ssh key

雖然教學中用的是Cygwin, 可是電腦已經有安裝過Bash
Bash既然可以產生ssh, 應該功能差不多
所以在picCTF shell server貼上ssh key的內容後

利用bash連線到picoCTF
SSH指令教學
https://www.codingstartup.com/ssh-common-commands/

通過 SSH 連接到 Linux Server

ssh 用戶名@IP地址
ssh wavek@2018shell.picoctf.com

picoCTF{who_n33ds_p4ssw0rds_38dj21}

:::success
Ctrl+D 可以退出cat指令
:::
:::warning
hostname的部分還有待釐清

題目: what base is this?

用python寫個小程式
將2進位轉成10進位 再轉成ASCII解碼

得到computer

不過後來發現這樣我敢不上30秒完成XD

他每次連線給的內容都會不一樣

直接開外掛網站
https://www.rapidtables.com/convert/number/binary-to-ascii.html

發現用網站速度還是不夠快XD

只好用pyhton寫一個遠端連線的程式

:::success
記得先安裝pwn
pip install pwn
:::

2020/01/06回頭看這題
發現不對阿 根本不用寫程式去連線
用網站解明明就夠快 不知道當初我是怎麼了..
https://www.rapidtables.com/convert/number/binary-to-ascii.html
https://www.rapidtables.com/convert/number/hex-to-ascii.html
https://onlineasciitools.com/convert-octal-to-ascii

就是找網站把binary,hex,octal轉成ascii而已
總之回答完問題 拿到flag

picoCTF{delusions_about_finding_values_602fd280}

題目: you can’t see me

題目已經說明答案會在目錄

/problems/you-can-t-see-me_3_1a39ec6c80b3f3a18610074f68acfe69

連上shell之後, 先cd到上述路徑

在home目錄下輸入指令 ls 顯示檔案, 發現沒東西

在輸入ls -al 顯示各檔案說明

發現有兩個檔案名稱都是’.’

可是期中一個是檔案型態不同

http://www2.lssh.tp.edu.tw/~hlf/class-1/linux/file_permission.htm

:::info

ls -al說明:

[root@tsai root]# ls -al 
total 64 
drwxr-x---    4 root     root         4096 Feb 14 22:02 . 
drwxr-xr-x   23 root     root         4096 Feb 16 13:35 .. 
-rw-r--r--    1 root     root         1210 Feb 10 06:03 anaconda-ks.cfg 
-rw-------    1 root     root        12447 Feb 14 23:22 .bash_history 
-rw-r--r--    1 root     root           24 Jun 11  2000 .bash_logout 
-rw-r--r--    1 root     root          234 Jul  6  2001 .bash_profile 
-rw-r--r--    1 root     root          217 Feb  9 22:06 .bashrc 
-rw-r--r--    1 root     root          210 Jun 11  2000 .cshrc 
drwx------    2 root     root         4096 Feb 14 21:54 .gnupg 
-rw-------    1 root     root            8 Feb 14 22:05 .mysql_history 
drwx------    2 root     root         4096 Feb 10 00:44 .ssh 
-rw-r--r--    1 root     root          196 Jul 11  2000 .tcshrc 
-rw-r--r--    1 root     root         1126 Aug 24  1995 .Xresources
 第一欄     二      三       四       五     六       七  
[檔案屬性][檔案數][擁有者][所有者群組][大小][建檔日期][檔名]
  • 第一個屬性代表這個檔案是『目錄、檔案或連結檔』:
    當為[ d ]則是目錄,例如上表的第 11 行;
    為[ – ]則是檔案,例如上表的第 5 行;
    若是[ l ]則表示為連結檔(link file);
    若是[ b ]則表示為裝置檔裡面的可供儲存的周邊設備;
    若是[ c ]則表示為裝置檔裡面的序列埠設備,例如鍵盤、滑鼠。
     
  • 接下來的屬性中,三個為一組,且均為『rwx』的三個參數的組合。其中,[ r ]代表可讀、[ w ]代表可寫、[ x ]代表可執行:
    第一組為『擁有人的權限』,以第五行為例,該檔案的擁有人可以讀寫,但不可執行;
    第二組為『同群組的權限』;
    第三組為『其他非本群組的權限』。
     
    範例:若有一個檔案的屬性為『-rwxr-xr–』,簡單的可由下面說明之:
     
    [-][rwx][r-x][r–]
    1 234 567 890
    1 為:代表這個檔名為目錄或檔案(上面為檔案)
    234為:擁有人的權限(上面為可讀、可寫、可執行)
    567為:同群組使用者權限(上面為可讀可執行)
    890為:其他使用者權限(上面為僅可讀)
    :::

輸入查看指令

cat .

顯示錯誤 Is a directory

直接使用

cat .*

利用正規表示式方法查看全部內容

成功找到flag

題目: absolutely relative


ubuntu 建立 C 環境 跟編譯執行
http://pkmaya.pixnet.net/blog/post/149102072-linux%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E7%AC%AC01%E7%AF%87%EF%BC%9A%E5%BB%BA%E7%AB%8Bc%E5%92%8Cc%2B%2B%E7%9A%84%E7%92%B0%E5%A2%83%EF%BC%8C%E5%9C%A8linu

https://www.laird.tw/2015/04/linux-c-ubuntu-c.html

假設檔案名稱叫HelloWorld
Linux的編譯與執行過程如下

輸入下面的句子編譯「HelloWorld.c」
並指定所生成的可執行程式的文件名為「HelloWorld」。

gcc -g -Wall HelloWorld.c -o HelloWorld

當中的「-g」是加入除錯資訊;「-Wall」是顯示所有的警告訊息 ;
「-o」用來指定所生成的可執行程式的文件名。

要運行編譯後的HelloWorld,輸入下面的句子。

./HelloWorld

輸入內容說你沒有權限看flag

打開文件查看一內文
(用習慣的IDE 用sublime或是vim打開都可以)

#include <stdio.h>
#include <string.h>
#define yes_len 3
const char *yes = "yes";
int main()
{
    char flag[99];
    char permission[10];
    int i;
    FILE * file;

    file = fopen("/problems/absolutely-relative_4_bef88c36784b44d2585bb4d2dbe074bd/flag.txt" , "r");
    if (file) {
        while (fscanf(file, "%s", flag)!=EOF)
        fclose(file);
    }   
    file = fopen( "./permission.txt" , "r");
    if (file) {
        for (i = 0; i < 5; i++){
            fscanf(file, "%s", permission);
        }
        permission[5] = '\0';
        fclose(file);
    }
    if (!strncmp(permission, yes, yes_len)) {
        printf("You have the write permissions.\n%s\n", flag);
    } else {
        printf("You do not have sufficient permissions to view the flag.\n");
    }
    return 0;
}

看起來重點在這一段

    if (!strncmp(permission, yes, yes_len)) {
        printf("You have the write permissions.\n%s\n", flag);
    } else {
        printf("You do not have sufficient permissions to view the flag.\n");
    }

google一下strncmp的用法
https://pydoing.blogspot.com/2010/07/c-strncmp.html
:::info
string.h 的函數 strncmp() ,需要兩個字串及一個整數 n 當作參數,
共有三個參數。此函數比較兩個字串的前 n 個字元是否相等,
相等就回傳 0,第一個字串大於第二個字串回傳正值,反之回傳負值。
:::

所以看一下參數permissions跟yes

看起來意思是

如果permission檔案裡面的字串是yes

就會將flag.txt的檔案內容顯示給你

這邊也注意到內容讀取檔案有相對路徑跟絕對路徑

所以改成用pico server的shell執行

不在自己的電腦用

cd 到路徑/problems/absolutely-relative_4_bef88c36784b44d2585bb4d2dbe074bd

執行會得到一樣的結果沒問題

查看一下資料夾下的內容

沒有permissions這個檔案

打算自己新增一個檔案, 發現權限不夠

注意到程式碼中有個重點

file = fopen( "./permission.txt" , "r");

permission.txt會在你目前的位置執行,
而不是說那個檔案的執行位置

所以我們在shell上先回到自己的home

然後創立檔案permission.txt 並加入內容yes

這時候我們利用路徑來執行absolutely-relative

也就是我仍然在home目錄下

執行absolutely-relative檔案

./problems/absolutely-relative_4_bef88c36784b44d2585bb4d2dbe074bd/absolutely-relative

成功得到flag


:::

發佈留言