渗透篇20-主动信息收集--端口扫描(继主机发现)

ps:本节讨论的是已经存活的IP,进行端口开放否判断!!!(基于kali2018.1)

1、论端口扫描的重要性:


2、UDP端口扫描

    

 判别:前提是主机存活  

        

a、scapy



扫描二维码关注公众号,回复: 141411 查看本文章

b、nmap

nmap -sU 192.168.43.20                    

 


ps:默认扫描1000个端口(结果精确、较耗时,回车查看进度);-sU表示UDP端口扫描


ps:指定端口扫描

ps:其它

nmap -sU 192.168.1.134 -p-    -->1-65535全端口扫描

nmap -iL iplist.txt -sU -p 1-200    -->列表扫描


3、TCP端口扫描

        

a、全连接扫描:建立完整三次握手,如果连接成功,表示端口开放,如果没有接收到目标主机返回的SYN+ACK,判断为关闭.

工具使用--scapy

(1)、tcp_scan1.py






(2)、tcp_scan2.py

    

    

可见系统内核还是在目标主机返回S+A之后自动返回RST包,对方再返回RST包回来,如何避免系统产生万恶的RST包呢?

答案是使用Linux自带的防火墙:

        iptables -A OUTPUT -p tcp --tcp-flags RST RST -d 10.5.1.134 -j DROP

        ps:iptables在系统中的工作先于内核,在内核发出RST包的时候把包从当前出站中丢弃

    



ps:抓包发现成功建立三次握手;可以判断目标端口开放

ps:下贴脚本运行状态


sent:


received:


sent:


received:



工具使用--nmap(较快)

        

        ps:-sT表示TCP全连接扫描

        nmap -sT 192.168.43.32 -p1-100

         

工具使用--dmitry

    dmitry -p 192.168.43.32

        

工具使用--nc

    nc -nv -w 1 -z 192.168.43.32 1-100

        ps:-z表示扫描模式,-w表示超时时间

        

        ps:扫描出端口开放并不代表对应协议,也有可能被迁移

b、隐蔽扫描:只向目标主机发出syn包,目标主机返 回ACK判断为开放,返回RST判断为未开放;不发三次握手最后的ACK包,应用层不记录扫描行为;网络层记录有日志记录。

工具使用--Scapy

a=sr1(IP(dst="10.5.125.127")/TCP(flags=="S",dport=22),timeout=1,verbose=0)

目标端口开放的情况:



ps:scapy发送第一个包,接受第二个包(到此可以判断目标端口开放,不必要在发送ACK包确认),第三个包由操作系统内核产生RST包(因为目标主机莫名其妙发送SYN+ACK包给本机)

目标端口关闭的情况:



调用脚本:



ps:如果目标主机开启了防火墙的话可能扫不到。。。

工具使用--nmap

    nmap -sS 10.5.125.127  -p 1-100

                

        nmap -sS 1.1.1.1 -p-        全端口扫描

        nmap -sS -iL iplist.txt -p 80,21,22,23    指定端口扫描+文件扫描

        ps:先解析dns,再扫描端口

工具使用--hping3

    hping3 10.25.125.127 --scan 1-100 -S        //-S--->SYN扫描

                    

                    ps:直接开始扫描端口

        hping3 10.25.125.127 --scan 80 -S 

        hping3  -c 10 -S --spoof 10.5.125.111 -p ++1 10.5.125.127

        ps:伪造IP地址扫描\每次扫描端口递增1位 \目标主机返回SYN+ACK到伪造IP地址

        

    

c、僵尸扫描:



ps:僵尸机需要足够闲置,如果不闲置,僵尸机就会和其它服务器通信而导致IPID逐渐递增从而无法判别IPID=x+1这个包是不是返回给target的...


条件:攻击者可以伪造目标IP的网络坏境;选择合格的僵尸主机且僵尸机的IPID递增

    

ps:现在的Linux,Windows系统的ipid随机产生,早期win xp等系统 的ipid是按响应包的顺序递增产生.

工具使用--scapy


ps:发给僵尸机


ps:发给目标机


ps:发给僵尸机的第一个包


ps:向目标机发的第一个包


ps:发给僵尸机的第二个包


ps:查看发给僵尸机的第一个包


ps:查看发给僵尸机的第二个包,发现id由726增加位728,刚好增加2,表名目标主机25端口开放



ps:测试目标端口关闭的情况


脚本--zombie.py

#!/usr/bin/python
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *

def ipid(zombie):
	reply1 = sr1(IP(dst=zombie)/TCP(flags="SA"),timeout=2,verbose=0)
	send(IP(dst=zombie)/TCP(flags="SA"),verbose=0)
	reply2 = sr1(IP(dst=zombie)/TCP(flags="SA"),timeout=2,verbose=0)
	
	if reply2[IP].id == (reply1[IP].id + 2):
		print "IPID seqience is incremental and target appears to be idle."
		response = raw_input("DO you want to use this this zombie to perform a scan?(Y or N): ")
		if response == "Y":
			target = raw_input("Enter the IP address of the target system: ")
			zombiescan(target,zombie)
	else:
		print "Either the IPID seqience is not incremental and the target is not idle."

def zombiescan(target,zombie):
	print"\nScanning target "+target+" with zombie " + zombie
	print"\n-----Open Ports on Target------\n"
	for port in range(1,100):
		try:
			start_val = sr1(IP(dst=zombie)/TCP(flags="SA",dport=port),timeout=2,verbose=0)
			send(IP(src=zombie,dst=target)/TCP(flags="S",dport=port),verbose=0)
			end_val = sr1(IP(dst=zombie)/TCP(flags="SA",dport=port),timeout=2,verbose=0)
			if end_val[IP].id == (start_val[IP].id + 2):
				print port
		except:
			pass
print "--------Zombie Scan Suite-----------\n"
print "1 - Identify Zombie Host\n"
print "2 - Perform Zombie Scan\n"
ans=raw_input("Select an Option (1 or 2): ")
if ans =="1":
	zombie = raw_input("Enter IP address for zombie system: ")
	ipid(zombie)
else:
	if ans == "2":
		zombie = raw_input("Enter IP address for zombie sysstem: ")
		target = raw_input("Enter IP address for scan target: ")
		zombiescan(target,zombie)



工具使用--nmap

 发现僵尸机

        nmap -p445 192.168.43.32 --script=ipidseq.nse

            

                ps:不合格僵尸机

            

                ps:合格僵尸

指定僵尸

    nmap 192.168.1.134 -sI 192.168.1.132 -Pn -p 0-100

            -sI:僵尸机idle scan

            -Pn: Treat all hosts as online -- skip host discovery

            


猜你喜欢

转载自blog.csdn.net/qq_38055050/article/details/80171198