TibaMe: 道德駭客實務入門及CEH認證班
Teacher: 林煌錡 (Alex Lin)

The class on 3/26 introduced NetBIOS, SNMP, LDAP, NTP, NFS, SMTP, DNS enumeration, vulnerability assessment and system hacking.

Enumerate ports & services

Common communication ports

Wiki List of TCP and UDP port numbers

NetBIOS enumeration

  • NetBIOS Wiki
  • Commands
    nmap uses –script to add plugin script
    1
    sudo nmap -sU --script nbstat.nse -p 137 192.168.1.0/24
    1
    nbtscan -v 192.168.1.0/24
    Command result

    Attack usually focuses on the target device with 1c & 1b service.

SNMP enumeration

LDAP enumeration

  • LDAP Wiki
  • Tools: Goddi
  • Commands
    Need user name & password
    1
    ldapdomaindump -u username -p password

NTP enumeration

  • NTP Wiki
  • Commands
    Use rpcinfo to list all the services. Most devices do not response this command.
    1
    rpcinfo -p 192.168.1.1
    1
    ntpd -d 172.17.0.3
    1
    sudo nmap -Pn --script default -sV -vvv -sU - p123 172.17.0.3

NFS enumeration

  • NFS Wiki
  • Commands
    1
    sudo nmap -Pn --script default -sV -vvv -p111 172.17.0.4
    1
    sudo nmap -vv -Pn --script default -sV 172.17.0.4
    1
    showmount -e 192.168.1.1
    1
    sudo mount -t nfs -o nolock -o tcp xxx:/dir /mnt/dir

SMTP enumeration

  • SMTP Wiki
  • Commands
    Search methods: VRFY, EXPN, RCPT.
    1
    smtp-user-enum -M VRFY -U /usr/share/wordlists/fern-wifi/common.txt -t 192.168.1.1

DNS enumeration

  • DNS Wiki
  • Commands
    1
    dnsrecon -t axfr -d victim.com -n victim.com

Vulnerability analysis

CTF

拔旗遊戲。網絡安全的攻防競賽,看起來實在太好玩。

Vulnerability category

所有漏洞分門別類,標上號碼,本是方便釐清問題,結果更方便駭客找到對應漏洞的破解腳本。

Tools

網頁和伺服器漏洞掃瞄工具,屬於付費工具。

Practice

駭客技術不是光上幾堂課,知道些工具,暸解些原理就可以了。技術是練出來的,但是駭客技術不能隨便亂玩,下面的網站提供了練習駭客技術的靶機。

推薦Nikhil的blog,有很多Hackthebox的題目解法。
https://0xw0lf.github.io/category/#/HackTheBox

System hacking

Gain access

首先要駭入一個系統,就要想辦法拿到登入帳號密碼,並且可以遠端登錄。
我覺的暴力破解是一個很花時間的方法,駭客常用手法應該是釣魚/詐騙,直接用騙的,用偷的比較快。

  • Find system bugs: exploit-db

  • Understand Microsoft Authentication

  • Password cracking
    pwdump7
    RainbowCrach
    Cain and Abel
    John The Ripper
    Hashcat

  • Stack Overflow detect
    Windows -> Ollydbg
    Linux -> GDB

Privilege escalation

一旦駭入了系統就要想辦法把自己權限提升到最高,這樣才可以為所欲為。

  • DLL Hijacking
  • Exploit DB (Search privilege keyword)
  • Pipe
  • SUID & SGID
  • PEAS
    Windows -> winPEAS
    Linux -> linPEAS

Maintaining Access

終於打下來的機器要想辦法維持聯繫。

  • Remote Control Tools
    Windows: WMI, WinRM
    Linux: SSH
    我在Kali上裝 Remmina,感覺不錯用。

  • KeyLogger
    這是駭客常用工具,他可以在背景記錄你所有的鍵盤使用,強大一點的還可以抓取螢幕截圖,這些訊息呢都會通過email送給駭入電腦的人,以便他隨時監控。 也就是說你就算改了電腦的密碼,他也可以從key logger工具傳回的訊息中找到新的密碼繼續使用。
    多年前我在做Oti SmartKMLink開發的時候就有寫過Windows和MAC這部分的程式, 背景監聽電腦的鍵盤和滑鼠Event實作不難,但是唯一的問題是這種程式在安裝的時候需要很高的權限。 類似的軟體比如說遠端電腦控制軟體, 全部都有在監聽鍵盤和滑鼠事件,這類軟體我真不想用,總覺得給了這類軟體太多的權限也不知他們在背後做什麽,但是有時候還是不得不用,我有用Google remote desktop, no machine… 相信自己只是一個nobody就算了。但如果你是somebody或者是很重要的電腦,真心建議不要裝這類軟體。
    Google “Key Logger github”你就可以找到很多工具,像是下面這篇提到的Zlogger,號稱一般權限就可以安裝,我比較好奇他是怎麼做到的。
    https://medium.com/purple-team/make-a-keylogger-using-the-zlogger-tool-9945bc87922

Track Covering

清理作案現場盡量不讓人發現被駭。基本上就是去清log。

  • Windows: SECEVENT.EVT, SYSEVENT.EVT, APPECENT.EVT
  • Linux Logs
log file content command
/var/log/btmp Failed login records lasttb
/var/log/lastlog All login users’ last login time lastlog
/var/log/wtmp All login user’s login & logout records last
/var/log/utmp Current login user info. w, who, users
/var/log/secure Security related info.
/var/log/messsage General system logs and errors

Ubuntu logs doc

這裡老師有說,如果log檔案突然被大量修改,或變小很多,就有可能是駭客清除的結果。我想應該有監視log檔案的工具吧。

Clean logs commands

1
2
3
4
5
6
echo "" > /var/log/btmp
echo "" > /var/log/wtmp
echo "" > /var/log/lastlog
echo "" > /var/log/utmp
cat /dev/null > /var/log/secure
cat /dev/null > /var/log/message

課堂練習

列舉伺服器上可能的檔案

  • dirsearch
    Install dirsearch
    1
    2
    sudo apt-get update
    sudo apt install dirsearch
    Install dictionary
    1
    sudo apt install wordlists
    搜尋靶機找到檔案

    這個工具我覺的可以用來測自己的Server看是不是有不小心多放了什麼不該放的檔案。

駭入靶機練習

  • Scan target device ports
    用nmap掃瞄靶機找到 2222 ssh port

  • Use hydra to crack the password
    暴力破解找密碼。
    -l user name. 此案例中已知user name是user。如果user未知的話,也可以加user查詢字典。
    -P 從字典找密碼。
    -t 加delay避免被查覺。


    因為密碼老師已經放在字典中,所以很快找到。
    Google “password dictionary github” 可以找到很多密碼字典。
    比如:https://github.com/duyet/bruteforce-database
    密碼字典當然要夠大才有機會找到密碼,可想而知用暴力破解跑完整本字典真的是天長地久,我想一般駭客大概把常用的試過就算了,所以設定時應該盡量避免常用的user name & password。

  • Enter the target device and get more info.
    找到 user name & password 你就拿到了入場券。
    ㄧ入場當然是查看環境先。
    Commands for checking the environment.

    1
    2
    3
    4
    5
    whoami
    id
    ls -al
    cat .bash_history
    cat /etc/passwd

  • Find the target device vulnerability
    可以掃瞄漏洞的工具非常多,課上好像是用下面這個。
    https://github.com/The-Z-Labs/linux-exploit-suggester
    在靶機上安裝然後掃瞄,老師刻意安排的靶機當然有很多漏洞。

  • Get root privilege
    選定利用sudo漏洞CVE-2021-3156。選取哪個漏洞來用,這個就是經驗了。
    漏洞 CVE-2021-3156 detail
    Check sudo verion

    Google “sudo 1.8.31” or “CVE-2021-3156 github” 就找到下面這個工具。
    https://github.com/teamtopkarl/CVE-2021-3156
    安裝工具執行後,權限直接提升為root。

Others

Metasploit

在Kali上找到的工具,感覺非常強大。
https://www.metasploit.com
https://zh.wikipedia.org/zh-tw/Metasploit

這個工具我覺的可以用來遠端掃瞄Server是否有漏洞。