Easy共有九題,所有難度總共有75題,慢慢更新中。
Scenario: "Saint John": what is writing to this log file?
Level: Easy
Type: Fix
Access: Public
Description: A developer created a testing program that is continuously writing to a log file /var/log/bad.log and filling up disk. You can check for example with tail -f /var/log/bad.log.
This program is no longer needed. Find it and terminate it.
Test: The log file size doesn't change (within a time interval bigger than the rate of change of the log file).
The "Check My Solution" button runs the script /home/admin/agent/check.sh, which you can see and execute.
Time to Solve: 10 minutes.
tail
用於查看文件的末尾內容。-f
參數是「follow」的縮寫,讓tail
命令保持開啟狀態,並即時顯示文件的最新新增內容。tail -f /var/log/bad/log
lsof
命令用於顯示系統中已打開的文件和這些文件的相關信息。使用 grep
來過濾包含 "/var/log/bad/log" 字串的信息。lsof | grep "/var/log/bad/log"
# 得知PID為584
kill
命令用於向指定的進程發送終止信號,讓該進程正常結束。**584
**為PIDkill 584
tail -f /var/log/bad/log
Scenario: "Saskatoon": counting IPs.
Level: Easy
Type: Do
Description: There's a web server access log file at /home/admin/access.log. The file consists of one line per HTTP request, with the requester's IP address at the beginning of each line.
Find what's the IP address that has the most requests in this file (there's no tie; the IP is unique). Write the solution into a file /home/admin/highestip.txt. For example, if your solution is "1.2.3.4", you can do echo "1.2.3.4" > /home/admin/highestip.txt
Test: The SHA1 checksum of the IP address sha1sum /home/admin/highestip.txt is 6ef426c40652babc0d081d438b9f353709008e93 (just a way to verify the solution without giving it away.)
Time to Solve: 15 minutes.
/home/admin/access.log
中的行數wc -l /home/admin/access.log
/home/admin/access.log
的前五行內容head -5 /home/admin/access.log
cut
命令來從文件 access.log
中提取字段第一欄(f1
),然後使用 -d
設定分隔符為破折號('-'
),最後使用 > iplist.txt
將提取的字段保存到名為 iplist.txt
的文件中cd /home/admin
#切換到工作目錄
cut -f1 access.log -d '-' > iplist.txt
#將IP提取出來存到iplist.tx
head -5 iplist.txt
# 列出前五行檢查結果
cat
命令輸出 iplist.txt
的內容,通過管道 |
傳遞給 sort
命令對ip進行排序,最後使用 > ip_order.txt
將排序後的結果保存到 ip_order.txt
文件中uniq
無法偵測重複行,除非它們彼此相鄰[1]。因此,在使用 uniq
之前必須對文件中的內容進行排序 sort
。cat iplist.txt | sort > ip_order.txt
head -10 ip_order.txt
# 列出前十行檢查結果
uniq
命令用於刪除連續重複的行,-c
會顯示每行重複出現的次數。sort
將 uniq
的輸出進行排序,以便使用tail
顯示排序後的結果的最後10行。uniq -c ip_order.txt | sort | tail -10
echo "66.249.73.135" > /home/admin/highestip.txt
#依照題目指示將答案寫入到/home/admin/highestip.txt
Scenario: "Santiago": Find the secret combination
Level: Easy
Type: Do
Description: Alice the spy has hidden a secret number combination, find it using these instructions:
- Find the number of lines with occurrences of the string Alice (case sensitive) in the *.txt files in the /home/admin directory
- There's a file where Alice appears exactly once. In that file, in the line after that "Alice" occurrence there's a number.
Write both numbers consecutively as one (no new line or spaces) to the solution file. For example if the first number from 1) is 11 and the second 22, you can do echo -n 11 > /home/admin/solution; echo 22 >> /home/admin/solution or echo "1122" > /home/admin/solution.
Test: Running md5sum /home/admin/solution returns d80e026d18a57b56bddf1d99a8a491f9(just a way to verify the solution without giving it away.)
Time to Solve: 15 minutes.
pwd
cd /home/admin/
ls -l
grep
命令在所有 .txt
的文件中搜尋包含字符串 'Alice'
的行, -c
參數計算匹配的行數grep -c 'Alice' *.txt
# 相加為411(第一題答案)
grep
命令來在文件 1342-0.txt
中搜尋包含字符串 'Alice'
的行,並接著顯示每個匹配行的後一行(-A1
)grep -A1 'Alice' 1342-0.txt
# 得到下一行出現的數字156(第二題答案)
echo '411156' > /home/admin/solution