---
# System prepended metadata

title: picoCTF General Skills
tags: [picoCTF]

---

# picoCTF General Skills

# Easy
## Binary Search 
![image](https://hackmd.io/_uploads/ry7kwLm7Je.png)
![image](https://hackmd.io/_uploads/HyK9wUQmJg.png)

## **endianness**
![image](https://hackmd.io/_uploads/SyNcvGEXJx.png)



![image](https://hackmd.io/_uploads/HkMY2z4m1e.png)
簡單來講輸入little endian和big endian

Big-Endian 和 Little-Endian 是兩種數據儲存和傳輸時的位元組序列表示方式，主要描述多位元組資料在記憶體或通訊過程中的排列順序。
#### little-Endian
定義：低位元組（LSB）排在低位地址，高位元組（MSB）排在高位地址
```
數值:0x12345678
地址:  0x00   0x01   0x02   0x03
數據:  0x78   0x56   0x34   0x12
```
#### Big-Endian
定義：高位元組（Most Significant Byte, MSB）排在低位地址，低位元組（Least Significant Byte, LSB）排在高位地址。
```
數值:0x12345678
地址:  0x00   0x01   0x02   0x03
數據:  0x12   0x34   0x56   0x78
```

char轉成little-Endian和Big-Endian
```python
input_string = input("Enter string:")

hex_values = [format(ord(char), '02x') for char in input_string]


big_endian = ''.join(hex_values)
print(f"Big-Endian Hex: {big_endian}")


little_endian = ''.join(reversed(hex_values))
print(f"Little-Endian Hex: {little_endian}")
```

![image](https://hackmd.io/_uploads/HJwn-XEQ1g.png)
![image](https://hackmd.io/_uploads/SyEabmVXkg.png)
## Time Machine
![image](https://hackmd.io/_uploads/HkvuYWImkg.png)
查看提交歷史
```
git log
```
![image](https://hackmd.io/_uploads/B1ioYZ8QJx.png)


## Commitment Issues
![image](https://hackmd.io/_uploads/r14FksNmJe.png)

Hints:
1. Version control can help you recover files if you change or lose them!
2. Read the chapter on Git from the picoPrimer https://primer.picoctf.org/#_git_version_control
3. You can 'checkout' commits to see the files inside them

一開始根本不知道要幹嘛
傻傻的cat message.txt
![image](https://hackmd.io/_uploads/BynIgoVXJx.png)

後來看到提示有git,version control和recover files
才想到可能是git的問題
仔細看了一下git文件

查看提交歷史
```
git log
```
看到第二個提交的訊息:create flag
![image](https://hackmd.io/_uploads/HJnLmi4m1x.png)
```

從上圖中可以看出，執行了 git log 命令，這顯示了 Git 專案的提交歷史。以下是圖片的分析與解釋：

提交歷史內容
第一個提交 (e1237df82d2e69f62dd53279abc1c8aeb66f6d64)：

提交信息：remove sensitive info
作者：picoCTF <ops@picoctf.com>
日期：Sat Mar 9 21:10:14 2024 +0000
HEAD（目前指向的分支/提交）對應 master，也就是當前最新的提交。
此提交移除了檔案中的某些敏感信息。
第二個提交 (3d5ec8a26ee7b092a1760fea18f384c35e435139)：

提交信息：create flag
作者：picoCTF <ops@picoctf.com>
日期：Sat Mar 9 21:10:14 2024 +0000
此提交顯示曾經創建了一個「flag」。
```


切換到指定的分支or提交，下方為提交
```
git checkout <commit-hash> //範例
git checkout  3d5ec8a
```
![image](https://hackmd.io/_uploads/Bkb-EjVQyx.png)

列出所有的本地和遠端分支(branches)，確認當前分支:
```
git branch -a
```
帶有星號（*）標記，表示目前所在的分支或狀態
![image](https://hackmd.io/_uploads/SyfMSsEQJl.png)


## Collaborative Development
![image](https://hackmd.io/_uploads/rJmnXJHmJe.png)
Hints:
1. git branch -a will let you see available branches
2. How can file 'diffs' be brought to the main branch? Don't forget to git config!
3. Merge conflicts can be tricky! Try a text editor like nano, emacs, or vim.

先看一下是否有branch
```
git branch -a
```
![image](https://hackmd.io/_uploads/SypeB1Hm1x.png)

切換到其他branch
```
git checkout feature/part-1
```
看到pico了
![image](https://hackmd.io/_uploads/Hkd-LJHXke.png)
![image](https://hackmd.io/_uploads/B1HX8yH71l.png)
![image](https://hackmd.io/_uploads/BkqNLkr71l.png)

## Blame Game
![image](https://hackmd.io/_uploads/Bk2MScBmkl.png)

查看提交歷史
```
git log
```
![image](https://hackmd.io/_uploads/rJouH9H7yg.png)

太多了不想看，試試加上grep
```
git log | grep pico
```
![image](https://hackmd.io/_uploads/ryNsH9H7kx.png)
![image](https://hackmd.io/_uploads/Hk_JL9r71l.png)

這樣就出現了😵‍💫😵‍💫


## binhexa
![image](https://hackmd.io/_uploads/SJzjcyUQ1l.png)
一些很基本的 binary '*', '<<' ,'|' ,'&' ,'>>' ,'+'
![image](https://hackmd.io/_uploads/HJR65J8XJe.png)
![image](https://hackmd.io/_uploads/SkDRck87ye.png)


## repetitions
![image](https://hackmd.io/_uploads/r1gz1lUmkx.png)

![image](https://hackmd.io/_uploads/rkJHkeIQJg.png)

一直decode就會噴出flag
![image](https://hackmd.io/_uploads/rJXcyxU7yl.png)

# Medium
## dont-you-love-banners
![image](https://hackmd.io/_uploads/ByRm2GLmkl.png)
Hints:
1. Do you know about symlinks?
2. Maybe some small password cracking or guessing
```
nc tethys.picoctf.net 51683
nc可以用來建立、讀取TCP or UDP連線
```
看起來很像是password
![image](https://hackmd.io/_uploads/Bk_4AzI7kg.png)
輸入完密碼後，回答幾個問題就進去了
![image](https://hackmd.io/_uploads/rJNuCf8mye.png)

![image](https://hackmd.io/_uploads/B1NP1787Jg.png)

```
cd /root
```
![image](https://hackmd.io/_uploads/r1twlXUmyg.png)

感覺有鬼
![image](https://hackmd.io/_uploads/SksKxXLm1x.png)

cat flag.txt沒有那個權限
![image](https://hackmd.io/_uploads/Bkst4m87yl.png)


這時候沒想法，看了一下Hint
提示有說symlinks，我根本不知道這是什麼
#### symlink
在檔案系統中，symlink（全稱：symbolic link，符號連結）是一種特殊的檔案，指向另一個檔案或目錄的路徑。它相當於是一個快捷方式或別名，讓你可以通過 symlink 存取被指向的實際檔案或目錄，而不需要直接操作該目標。

```
ln -s [目標檔案或目錄] [symlink 名稱]
```
這會在當前目錄建立一個[symlink 名稱]的符號連結，指向[目標檔案或目錄]


把/root/flag.txt連結到/home/player/banner
![image](https://hackmd.io/_uploads/SkPmQ7Lm1e.png)
![image](https://hackmd.io/_uploads/SyxJVXLm1l.png)


![image](https://hackmd.io/_uploads/BkceNQ87kx.png)


## ASCII Numbers
![image](https://hackmd.io/_uploads/B1FfwWP7kl.png)

把hex轉成ascii就行了
```python
text = "0x70 0x69 0x63 0x6f 0x43 0x54 0x46 0x7b 0x34 0x35 0x63 0x31 0x31 0x5f 0x6e 0x30 0x5f 0x71 0x75 0x33 0x35 0x37 0x31 0x30 0x6e 0x35 0x5f 0x31 0x6c 0x6c 0x5f 0x74 0x33 0x31 0x31 0x5f 0x79 0x33 0x5f 0x6e 0x30 0x5f 0x6c 0x31 0x33 0x35 0x5f 0x34 0x34 0x35 0x64 0x34 0x31 0x38 0x30 0x7d"

hex_values = text.replace("0x","").split()

ascii_string = ''.join(chr(int(h,16)) for h in hex_values)

print(ascii_string)
```
![image](https://hackmd.io/_uploads/H1DswbDQke.png)



## Permissions
![image](https://hackmd.io/_uploads/BkA5WZqmke.png)
Hint:What permissions do you have?

這題就是提權找到root裡的flag
```
sudo -l
```
列出當前用戶(or 指定用戶)在系統上被授予的sudo權限
1. 當前用戶是否有使用 sudo 的權限
2. 可以使用哪些命令，以及在什麼條件下可以執行（如是否需要密碼）
3. 根據配置的 sudoers 文件，用戶是否擁有特殊的操作權限

![image](https://hackmd.io/_uploads/r1IE4Z9mJx.png)
`(ALL) /usr/bin/vi` 的含義
`ALL`：指此權限適用於所有用戶身份，意味着用戶可以以任何其他用戶的身份（包括 root）執行 `/usr/bin/vi`
`/usr/bin/vi`：表示允許執行的命令是 vi，位於 /usr/bin 目錄下。
![image](https://hackmd.io/_uploads/ryLDUW57kl.png)
![image](https://hackmd.io/_uploads/Sye4L-qQkx.png)
![image](https://hackmd.io/_uploads/SJfrUWq7kg.png)

![image](https://hackmd.io/_uploads/H11t8WqQ1e.png)


## PW Crack 5
![image](https://hackmd.io/_uploads/rkCRYAq7Je.png)
Hints:
1. Opening a file in Python is crucial to using the provided dictionary.
2. You may need to trim the whitespace from the dictionary word before hashing. Look up the Python string function, strip
3. The str_xor function does not need to be reverse engineered for this challenge.

有四個檔案
![image](https://hackmd.io/_uploads/rJrm9A971g.png)

他給了一個dictionary.txt就是要我們用txt去暴力破解flag

這是關鍵的code
```python
def level_5_pw_check():
    # user_pw = input("Please enter correct password for flag: ")
    # user_pw_hash = hash_pw(user_pw)
    with open('dictionary.txt','r') as file:
        for line in file:
            line = line.strip()
            user_pw_hash = hash_pw(line)
            if( user_pw_hash == correct_pw_hash ):
                print("Welcome back... your flag, user:")
                decryption = str_xor(flag_enc.decode(), line)
                print(decryption)
                return 
            print("That password is incorrect")
```

![image](https://hackmd.io/_uploads/HkQljA9myg.png)

## Basesd
![image](https://hackmd.io/_uploads/S1uHZKjQ1e.png)
一開始根本不知道第二關跟第三關代表什麼，還以為是dec呢

```
第一關binary to ascii
第一關dec to ascii
第一關hex to ascii
```

```python
def binary_to_ascii(binary_string):
   
    bytes_list = binary_string.split()
    
    ascii_chars = [chr(int(byte, 2)) for byte in bytes_list]
    return ''.join(ascii_chars)

def octal_to_ascii(octal_string):
    
    octal_numbers = octal_string.split()
    
    ascii_chars = [chr(int(num,base=8)) for num in octal_numbers]
    return ''.join(ascii_chars)

def hex_to_ascii(hex_string):
    hex_chunks = [hex_string[i:i+2] for i in range(0, len(hex_string), 2)]
    
    ascii_chars = [chr(int(chunk, 16)) for chunk in hex_chunks]
    return ''.join(ascii_chars) 

binary_data = input("Enter binary numbers (e.g., 01100011 01101111): ")
ascii_result_binary = binary_to_ascii(binary_data)
print("Binary to ASCII:", ascii_result_binary)


octal_numbers = input("Enter decimal numbers (e.g., 99 111 109): ")
ascii_result_octal  = octal_to_ascii(octal_numbers)
print("octal  to ASCII:", ascii_result_octal )

hex_numbers = input("Enter hex numbers: ")
ascii_result_hex  = hex_to_ascii(hex_numbers)
print("hex  to ASCII:", ascii_result_hex )
```

![image](https://hackmd.io/_uploads/rk61fFimyl.png)


## useless
![image](https://hackmd.io/_uploads/HJgMwM3QJe.png)

連線進去會看到一個useless的script
![image](https://hackmd.io/_uploads/SJdmwMnXJe.png)

叫我先read the code
看不出個所以然，簡單的加減乘除
![image](https://hackmd.io/_uploads/S1KvvG3mJe.png)
![image](https://hackmd.io/_uploads/SkLr_fn7kx.png)


看了很久才發現到這個有鬼
![image](https://hackmd.io/_uploads/S1QDdG3X1g.png)

題目跟script都是useless
```
man useless
```

![image](https://hackmd.io/_uploads/Byzidf2mye.png)

## chrono
![image](https://hackmd.io/_uploads/BkUl3MnmJe.png)
How to automate tasks to run at intervals on linux servers?
Ans:Cron is the most common method to schedule recurring tasks.

![image](https://hackmd.io/_uploads/BkePjCM2mkg.png)
![image](https://hackmd.io/_uploads/rkg0CMnXJg.png)
