成為駭客的前一哩路
Chapter 2 - Text Manipulation
In Linux, nearly everything you deal with directly is a file, and most often these will be text files.
安裝 Snort
- Snort - from NIDS (Network Intrusion Detection System)
Snort是一套開放原始碼的網路入侵預防軟體與網路入侵檢測軟體,而本章會以此作為例子
使用 Ubuntu 下載
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 一旦軟體套件清單已經更新,你可以使用以下命令安裝 Snort:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Snort 也會要求要指定本地網路的地址範圍(通常我們會指定自己的本地網路的 IP 地址範圍),以便 Snort 知道哪些流量被視為內部網路。
- 假設我提供了一個 CIDR 表示法的地址範圍:192.168.0.0/14。
- 這個地址範圍表示的是 192.168.0.0 到 192.168.255.255 之間的所有 IP 地址,這是一個典型的私有 IP 地址範圍,通常在家庭或企業網路中使用。
- 不過,若是你的內部網路不在這個範圍內,也可以根據你的實際情況提供正確的地址範圍。
印用自 動手架設入侵偵測系統吧~Snort 介紹、安裝教學 - iT 邦幫忙
也可以先空著之後再設定
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Viewing Files
- 利用 cat 顯示在 /etc/snort 路徑中 Snort 設定檔 (snort.conf)
因為有跨到 root 資料夾,所以需要 sudo權限
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 可以看到所有檔案內容被顯示出來,但並不方便及實際去找我們需要的內容
Finding the Head
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 也可以自訂行數
head -[行數] 檔名
,以下舉例顯示 20 行
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Finding the Tail
- 瀏覽檔案的尾端,語法跟
head
一樣,預設也是 10 行
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Numbering the Lines
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Filting Text with grep
grep
常作為文字操作指令,在這裡的功能就跟 Ctrl + F
一樣,從檔案中篩選出需要的文字
舉例:找檔案中包含 "output" 這個字的行
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
不用自己一行行找
Hacker Challenge: Using grep
, nl
, tail
, and head
- 目標:顯示 "# Step #6: Configure output plugins" 的前五行
可以有很多種解法,希望你可以找出第二種
因為nl
無法標示空格,而tail -n+(num)會包含空格,所以使用nl
時要加-ba
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
可以看到 "# Step #6: Configure output plugins" 在第 544 行,然後不包含該行的前 5 行是第 539 行
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
tail -n+(num)
是指從num行開始顯示
- 由此,我們找出了"# Step #6: Configure output plugins" 的前五行
Using sed to Find and Replace
sed
的功能如同 Windows 的尋找並取代,就從以下例子解釋
- 在 snort.conf 中尋找 mysql
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 將 mysql 更改成 MySQL 並存入 snort2.conf (路徑設在/home/(username))
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- s/ 表示代換(substitution),中間的 / 分別為 代換掉 及 欲代換,由 /g 代表全域執行
- 查看 snort2.conf
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 如果要去掉第 n 個出現的字,可以在最後的 / 後面加 n
Viewing Files with more and less
more
指令可以讓你在瀏覽檔案時使用Enter
鍵


less
指令功能跟more
類似,但它不只可以上下瀏覽,也可以利用/
篩選你想要查的字,然後按q
退出


Summary
We’ve touched on a few of the most useful methods in this chapter, but I suggest you try each one out and develop your own feel and preferences.
Exercise
- 瀏覽至 /usr/share/metasploit-framework/data/wordlists。這是一個多個單字清單的目錄,可用於使用最受歡迎的滲透測試和駭客框架 Metasploit 在各種受密碼保護的裝置中暴力破解密碼
- 使用
cat
指令查看 password.lst 檔案的內容
- 使用
more
指令顯示 password.lst 文件
- 使用
less
指令查看 password.lst 文件
- 使用
nl
指令在 password.lst 中的密碼上新增行號。應該有大約 88,396 個密碼
- 使用
tail
指令查看 password.lst 文件中的最後 20 個密碼
- 使用
cat
指令顯示 password.lst 文件,然後將其通過管道傳遞給 find 命令,以找出所有包含 123 的密碼