主动信息收集[4]{
发现_四层发现:
nmap 1.1.1.1-254 -PU53 -sn ;;-sn: 不做端口扫描,只发现主机), -PU似乎不是很有效
nmap 1.1.1.1/24 -PA80 -sn
nmap -iL iplist.txt -PA80 -sn
hping3 --udp -p [port] 1.1.1.1 -c 1
for i in $(seq 1 254);do hping3 --udp 1.1.1.1 -c 1 >> r.txt ; done
grep Unreachable r.txt | awk '{print $5}' | awk -F "=" '{print $2}'
./udp.sh 1.1.1.0
hping3 1.1.1.1 -c 1 ;;默认为tcp
;;;发送的tcp.flags=0, 若返回ACK,RST, ip在线(此方法似乎也并不很有效)
hping3 1.1.1.1 -S -p 80 -c 1
端口扫描:
发现开放的端口;
UDP端口扫描:
假设ICMP port-unreachable 响应代表端口关闭 ;;此时扫描的都是在线的IP
目标系统不响应ICMP port-unreachable时,可能误判;
完整的UDP应用层请求:
准确性高;
耗时巨大;
Scapy UDP Scan:
端口关闭: ICMP port-unreachable
端口开放: 没有回应
了解每一种基于UDP的应用层包结构很有帮助;
与三层相同的技术;
误判;
Scapy:
;;;可以使用fuzz()函数来构造合法的数据包
sr1(IP(dst='1.1.1.1')/fuzz(UDP()/NTP()))
sr1(IP(dst="1.1.1.1")/UDP(dport=53),timeout=1,verbose=False)
./udp_scan.py 1.1.1.1 1 100
Nmap:
UDP扫描(原理相近):
nmap -sU 1.1.1.1
;;默认的1000个参数
;;ICMP host-unreachable
nmap 1.1.1.1 -sU -p 53
nmap -iL iplist.txt -sU -p 1-200
TCP端口扫描(更加复杂,如基于连接和半连接,还有各种场景):
基于连接的协议
三次握手(syn; syn,ack; ack)
隐蔽扫描(只发syn包, 回应rst: 不建立完整连接, 应用日志不记录扫描行为)
僵尸扫描(极其隐蔽, 条件相当苛刻, 可伪造源地址, 选择僵尸机(闲置系统, 系统使用递增IPID(0, 随机))):
原理: 观察IPID的改变(若x+2,端口开放;否则x+1,端口关闭)
对于目标服务器, 扫描者完全隐身
全连接扫描
所有的TCP扫描方式都是基于三次握手的变化来判断目标端口的状态
python udp 端口扫描脚本:
#!/usr/bin/python3
#-*-coding:utf-8-*-
import time
from scapy.all import *
import queue as Queue
import threading
openp = []
portL = []
ip = "192.168.31.1"
for i in range(124):
portL.append(str(i))
class myThread(threading.Thread):
def __init__(self, name, q):
threading.Thread.__init__(self)
self.name = name
self.q = q
def run(self):
# print('[*] Starting thread-' + self.name)
while True:
try:
pScan(self.name, self.q)
except:
break
# print('[*] Exiting thread-' + self.name)
def pScan(name, q):
port = q.get(timeout=1)
try:
ans = sr1(IP(dst=ip)/UDP(dport=int(port)),timeout=5,verbose=False)
if ans == None:
# print("[+] " + ip + " " + port + " is alive!")
openp.append(int(port))
except Exception as err:
pass
def main():
threads = []
# workQueue = Queue.Queue(len[portL])
workQueue = Queue.Queue(0)
threadList = []
for j in range(20):
tName = str(j)
thread = myThread(tName, workQueue)
thread.start()
threads.append(thread)
for u in portL:
workQueue.put(u)
for t in threads:
t.join()
openp.sort()
print(openp)
print("[*] OK")
if __name__ == '__main__':
main()