发现的是IP,而不是端口
优点:扫描速度快、可靠
缺点:不可路由
Arp协议:
arping 1.1.1.1 -c 1
arping 1.1.1.1 -d
arping -c 1.1.1.1 | grep “bytes from” |cut -d" " -f 5 | cut -d"(" -f 2 | cut -d")" -f 1
脚本
arping1.sh eth0 > addrs
#!/bin/bash
if ["$#" -ne 1];then
echo "Usage - ./arping.sh [interface]"
echo "Example - ./arping.sh eth0"
echo "Example will perface an ARP scan of the local subnet to which eth0 is assigned"
exit
fi
interface=$1
prefix=$(ifconfig $interface | grep 'inet addr' | cut -d":" -f 2 | cut -d" " -f 1 | cut -d"." -f 1-3)
for addr in $(seq 1 254);do
arping -c 1 $prefix.$addr |grep "bytes from" | cut -d" " -f 5 | cut -d"(" -f 2 |cut -d")" -f 1
done
arping2.sh addrs
#!/bin/bash
if ["$#" -ne 1];then
echo "Usage - ./arping.sh [interface]"
echo "Example - ./arping.sh eth0"
echo "Example will perface an ARP scan of the local subnet to which eth0 is assigned"
exit
fi
file=$1
for addr in $(cat $file);do
arping -c 1 $prefix.$addr |grep "bytes from" | cut -d" " -f 5 | cut -d"(" -f 2 |cut -d")" -f 1
done
作为Python库进行调用
也可以作为单独的工具使用
抓包、分析、创建、修改、注入网络流量
安装组件: apt-get install python-gnuplot
使用:
Python脚本
arp1.py
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 2:
print("Usage - ./arp_sidc.py [interface]")
print("Example - ./arp_disc.py eth0")
print("Example will perform an ARP scan of the local subnet to which eh0 is assigned")
sys.exit()
interface = str(sys.argv[1])
ip = subprocess.check_output('ifconfig' + interface + " |grep `inet addr` | cut -d':' -f 2 | cut -d' ' -f 1", shell=True).strip()
prefix = ip.split('.')[0] + '.'+ ip.split('.')[1] + '.'+ ip.split('.')[2] + '.'
for addr in range(0, 254):
answer = stl(ARP(pdst=prefix+str(addr)), timeout=0.1, verbose=0)
if answer == None:
pass
else:
print(prefix+str(addr))
arp2.py
#!/usr/bin/python
import logging
import sys
from scapy.all import *
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 2:
print("Usage - ./arp_sidc.py [interface]")
print("Example - ./arp_disc.py eth0")
print("Example will perform an ARP scan of the local subnet to which eh0 is assigned")
sys.exit()
filename = str(sys.argv[1])
file = open(filename, "r")
for addr in file:
answer = stl(ARP(pdst=addr.strip()), timeout=0.1, verbose=0)
if answer == None:
pass
else:
print(addr.strip())
ping 1.1.1.1 -c 2
ping -R 1.1.1.1 / traceroute 1.1.1.1
ping 1.1.1.1 -c 1 |grep “bytes from” | cut -d" " -f 4 | cut -d":" -f 1
脚本
ping.sh 1.1.1.0
#!/bin/bash
if ["$#" -ne 1];then
echo "Usage - ./ping.sh [interface]"
echo "Example - ./ping.sh eth0"
echo "Example will perface an ARP scan of the local subnet to which eth0 is assigned"
exit
fi
interface=$1
prefix=$(echo $1 | cut -d"." -f 1-3)
for addr in $(seq 1 254);do
ping -c 1 $prefix.$addr |grep "bytes from" | cut -d" " -f 4 | cut -d"." -f 1 &
done
OSI多层堆叠手工声称ICMP包—IP/ICMP
ip = IP()
ip.dst=“1.1.1.1”
ping = ICMP()
a = sr1(ip/ping)
a.display()
Ping 不存在的地址
a = sr1(IP(dst=“1.1.1.1”)/ICMP(),timeout=1)
脚本
ping1.py 1.1.1.0 > addrs
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 2:
print("Usage - ./pinger.py [interface]")
print("Example - ./pinger.py 192.168.1.0")
print("Example will perform an IMCP scan of the 192.168.1.0/24 range")
sys.exit()
address = str(sys.argv[1])
prefix = address.split('.')[0] + '.'+ address.split('.')[1] + '.'+ address.split('.')[2] + '.'
for addr in range(1, 254):
answer = stl(IP(pdst=prefix+str(addr))/IMCP(), timeout=0.1, verbose=0)
if answer == None:
pass
else:
print(prefix+str(addr))
ping2.py addrs
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 2:
print("Usage - ./pinger.py [interface]")
print("Example - ./pinger.py 192.168.1.0")
print("Example will perform an IMCP scan of the 192.168.1.0/24 range")
sys.exit()
filename = str(sys.argv[1])
file = open(filename, "r")
for addr in file:
answer = stl(IP(pdst=addr.strip())/IMCP(), timeout=0.1, verbose=0)
if answer == None:
pass
else:
print(addr.strip())
ACK–TCP Port—RST
Scapy
i = IP()
i.dst="1.1.1.1"
t=TCP()
t.flags="A"
r=(i/t)
a = sr1(r)
a.display()
a=sr1(IP(dst=“1.1.1.1”)/TCP(dport=80,flags=“A”),timeout=1)
ACK_Ping.py
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 2:
print("Usage - ./ACK_Ping.py [interface]")
print("Example - ./ACK_Ping.py 192.168.1.0")
print("Example will perform a TCP ACK ping scan of the 192.168.1.0/24 range")
sys.exit()
address = str(sys.argv[1])
prefix = address.split('.')[0] + '.'+ address.split('.')[1] + '.'+ address.split('.')[2] + '.'
for addr in range(1, 254):
response = stl(IP(pdst=prefix+str(addr))/TCP(dport=2222, flags="A"), timeout=0.1, verbose=0)
try:
if int(response[TCP].flags) == 4:
print(prefix+str(addr))
except Exception as e:
pass
UDP-UDP Port–ICMP
i = IP()
i.dst="1.1.1.1"
u = UDP()
U.DPORT=3333
r=(i/u)
a=sr1(r.timeout=1,verbose=1)
a.display()
# ICMP
UDP_Ping.py
UDP发现不可靠
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 2:
print("Usage - ./UDP_Ping.py [interface]")
print("Example - ./UDP_Ping.py 192.168.1.0")
print("Example will perform a UDP ACK ping scan of the 192.168.1.0/24 range")
sys.exit()
address = str(sys.argv[1])
prefix = address.split('.')[0] + '.'+ address.split('.')[1] + '.'+ address.split('.')[2] + '.'
for addr in range(1, 254):
response = stl(IP(pdst=prefix+str(addr))/UDP(dport=2222), timeout=0.1, verbose=0)
try:
if int(response[IP].proto) == 1:
print(prefix+str(addr))
except Exception as e:
pass
hping3 0-udp 1.1.1.1 -c 1
for addr in ( s e q 1254 ) ; d o h p i n g 3 − − u d p 1.1.1. (seq 1 254); do hping3 --udp 1.1.1. (seq1254);dohping3−−udp1.1.1.addr -c 1 >> r.txt; done
grep Unreachable r.txt | cut -d" " -f 5 |cut -d"=" -f 2
./udp_hping.sh 1.1.1.0
#!/bin/bash
if ["$#" -ne 1];then
print("Usage - ./udp_hping.py [/24 network address]")
print("Example - ./udp_hping.py 192.168.1.0")
print("Example will perform a UDP ping sweep of the 192.168.1.0/24 network and output to an output.txt file")
exit
fi
prefix=$(echo $1 |cut -d "." -f 1-3)
for addr in $(seq 1 254); do
hping3 $prefix.$addr --udp -c 1 >> r.txt;
done
grep Unreachable r.txt |cut -d " " -f 5 | cut -d "=" -f 2 >> output.txt
rm r.txt
hping3 1.1.1.1 -c 1 (TCP)
hping3 1.1.1.1
./tcp_hping.sh
#!/bin/bash
if ["$#" -ne 1];then
print("Usage - ./tcp_hping.py [/24 network address]")
print("Example - ./tcp_hping.py 192.168.1.0")
print("Example will perform a TCP ping sweep of the 192.168.1.0/24 network and output to an output.txt file")
exit
fi
prefix=$(echo $1 |cut -d "." -f 1-3)
for addr in $(seq 1 254); do
hping3 $prefix.$addr -c 1 >> r.txt;
done
grep ^len r.txt |cut -d " " -f 2 | cut -d "=" -f 2 >> output.txt
rm r.txt
Flag 0 --ACK、RST
端口关闭: ICMP port-unreachable
端口开放: 没有回包
了解每一种给予UDP的应用层包结构很有帮助
与三层相同的技术
误判
Scapy
sr1(IP(dst=“1.1.1.1”)/DUP(dport=53),timeout=1,verbose=1)
./udp_scan.py 1.1.1.1 1 100
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
import time
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 4:
print("Usage - ./udp_scan.py [Target-IP] [First Port] [Last Port]")
print("Example - ./udp_scan.py 192.168.1.1 1 100")
print("Example will UDP scan ports 1 through 100 on 192.168.1.1")
sys.exit()
ip = sys.argv[1]
start = int(sys.argv[2])
end = int(sys.argv[3])
for port in range(start, end):
answer = stl(IP(pdst=ip)/UDP(dport=port), timeout=5, verbose=0)
time.sleep(1)
if answer == None:
print(port)
else:
pass
1. -> SYN
2. <- SYN,ACK
3. -> ACK
给予连接的协议
三次握手
隐蔽扫描–syn
僵尸扫描
全连接扫描
所有的TCP扫描方式
都是给予三次握手的变化来判断目标端口状态
sr1(IP(dst=“1.1.1.1”)/TCP(dport=80),timeout=1,verbose1)
./syn_scan.py
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
import time
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 4:
print("Usage - ./syn_can.py [Target-IP] [First Port] [Last Port]")
print("Example - ./syn_can.py 192.168.1.1 1 100")
print("Example will TCP SYN scan ports 1 through 100 on 192.168.1.1")
sys.exit()
ip = sys.argv[1]
start = int(sys.argv[2])
end = int(sys.argv[3])
for port in range(start, end):
answer = stl(IP(dst=ip)/TCP(dport=port), timeout=1, verbose=0)
if answer == None:
pass
else:
if int(a[TCP].flags)==18:
print(port)
else:
pass
Syn扫描不需要raw packets
内核认为syn/ack是非法包,直接发rst中断连接
全连接扫描对scapy比较困难
sr1(IP(dst=“1.1.1.1”)/TCP(dport=22,flags=“S”))
./tcp_scan1.py
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
import time
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
response = sr1(IP(dst="192.168.43.22")/TCP(dport=80,flags="S"))
reply = sr1(IP(dst="192.168.43.22")/TCP(dport=80,flags="A", ack=(response[TCP].seq + 1)))
./tcp_scan2.py
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
import time
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
SYN = IP(dst="192.168.43.22")/TCP(dport=445,flags="S")
print("-- SENT --")
SYN.display()
print("\n\n-- RECEIVED --")
response = sr1(SYN, timeout=1,verbose=0)
response.display()
if int(response[TCP].flags) == 18:
print("\n\n-- SENT --")
A = IP(dst="192.168.43.22")/TCP(dport=445,flags="A", ack=(response[TCP].seq + 1))
A.display()
print("\n\n-- RECEIVED --")
response2 = sr1(A, timeout=1,verbose=0)
response2.display()
else:
print("SYN-ACK not returned")
iptables -A OUTPUT -p tcp --tcp-flags RST -d 192.168.20.2 -j DROP
zombile.py
i=IP()
t=TCP()
rz=(i/t)
rt=(i/t)
rz[IP].dst=IPz
rz[TCP].dport=445
rz[TCP].flags="SA"
rt[IP].src=IPz
rt[IP].dst=IPt
rt[TCP].dport=22
rt[TCP].flags="S"
az1=sr1(rz) / at=sr1(rt,timeout=1 ) / az2=sr1(rz)
az1.display() / az2.dislay()
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
import time
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
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 sequence is incremental and target appears to be idle. ZOMBLE LOCATED")
response = input("Do you want to use this zomble perform a scan? (Y or N)")
if response.upper() == "Y":
target = input("Enter the IP address of the target system: ")
zombiescan(target,zombie)
else:
print("Either the IPID sequence is not incremental or the target is not idle. NOT A GOOO ZOMBLE")
def zombiescan(target,zombie):
print("\nScanning target " + target + " with zomble " + zombie)
print("\n------------- Open Ports on Target -------------")
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="SA"), verbose=0)
end_val = sr1(IP(dst=zombie)/TCP(flags="SA"), timeout=2, verbose=0)
if end_val[IP].id == (start[IP].id + 2):
print(port)
except:
pass
print("------------ Zombie Scan Suite ------------")
print("1. Identify Zombie Host")
print("2. Perform Zombie Scan")
ans = input("Select an Option (1 or 2):")
if ans == "1":
zombie = input("Enter IP address to test IPID sequence:")
ipid(zombie)
else:
if ans == "2":
zombie = input("Enter IP address for zombie system:")
target = input("Enter IP address for scan target:")
zombiescan(target, zombie)
socket 模块用于连接网络服务
import socket
bangrab = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
bangrab.connect(("1.1.1.1", 21))
bangrab.recv(4096)
# '220' (vsFTP 2.3.4)\r\n
bangrab.close()
exit()
#!/usr/bin/python
import sys
import socket
import select
if len(sys.argv[1]) != 4:
print("Usage - ./banner_grab.py [Target-IP] [First Port] [Last Port]")
print("Example - ./banner_grab.py 192.168.1.1 1 100")
print("Example will grab banner for TCP ports 1 through 100 on 192.168.1.1")
sys.exit()
ip = sys.argv[1]
start = int(sys.argv[2])
end = int(sys.argv[3])
for port in range(start, end):
try:
bangrab = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
bangrab.connect((ip, port))
ready = select.select([bangrab],[],[],1)
if ready[0]:
print("TCP Port " + str(port) + "-" + bangrab.recv(4096))
bangrab.close()
except Exception as e:
pass
Banner 不允许抓取,recv函数无返回将挂起!!
./ban_grab.py 1.1.1.1 1 100
python
from scapy.all import *
win = "1.1.1.1"
linux="1.1.1.2"
aw=sr1(IP(dst=win)/ICMP())
al=sr1(IP(dst=linux)/ICMP())
if al[IP].ttl<=64:
print("host is Linux")
else:
print("host is Windows")
./ttl_os.py
#!/usr/bin/python
import logging
import sys
import subprocess
from scapy.all import *
import time
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 2:
print("Usage - ./ttl_os.py [Target-IP]")
print("Example - ./ttl_os.py 192.168.1.1")
print("Example will perform ttl analysis to attempt to determine whether the system is Windows or linux")
sys.exit()
ip = sys.argv[1]
ans=sr1(IP(dst=ip)/ICMP(),timeout=1,verbose=0)
if ans == None:
print("No response was returned")
elif int(ans[IP].ttl) <= 64:
print("Host is Linux/Unux")
else:
print("Host is Windows")
显示不太友好
snmowalk 1.1.1.1 -c public -v 2c
用户
显示友好
snmpcheck -t 1.1.1.1
snmpcheck -t 1.1.1.1 -v private -v 2
snmpcheck -t 1.1.1.1 -w
nmap smtp.163.com -p 25 --script=smtp-enum-uers.nse --script-args=smtp-enum-users.methocls={VRTY}
nmap smtp.163.com -p 25 --script=smtp-open-relay.nse
smtp-user-enum -M VRTY -U user.txt -t 1.1.1.1
./smtp.py # 存在bug
#!/usr/bin/python
import sys
import socket
if len(sys.argv)!=2:
print("Usage: smtp.py ")
sys.exit(0)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connect = s.connect(("1.1.1.1", 25))
banner = s.recv(1024)
pritn(banner + "aaaaaaaaaaaa")
s.send("RCPT" + sys.argv[1] + "\r\n")
result =s.recv(1024)
print(result)
s.close()
Send | Response | Type | |
---|---|---|---|
1 | SYN | No | Filtered |
ACK | RST | ||
2 | SYN | SYN+ACK / SYN+RST | Filtered |
ACK | No | ||
3 | SYN | SYN+ACK / SYN+RST | Unfiltered / Open |
ACK | RST | ||
4 | SYN | No | Closed |
ACK | No |
./fw_detect.py 1.1.1.1 43
#!/usr/bin/python
import sys
import logging
from scapy.all import *
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
if len(sys.argv[1]) != 3:
print("Usage - ./fw_detect.py [Target-IP] [Target Port]")
print("Example - ./fw_detect.py 192.168.1.1 443")
print("Example will determine if filtering existe on port 443 of host 192.168.1.1")
sys.exit()
ip = sys.argv[1]
port = int(sys.argv[2])
ACK_response=sr1(IP(dst=ip)/TCP(dport=port,flags="A"),timeout=1,verbose=0)
SYN_response=sr1(IP(dst=ip)/TCP(dport=port,flags="S"),timeout=1,verbose=0)
if (ACK_response == None) and (SYN_response==None):
print("Port is either unstatefully filtered or host is down")
elif ((ACK_response == None) or (SYN_response==None)) and not ((ACK_response == None) and (SYN_response==None)):
print("Stateful filtering in place")
elif int(SYN_response[TCP].flags) == 18:
print("Port is unstatefully and open")
elif int(SYN_response[TCP].flags) == 20:
print("Port is unstatefully and closed")
else:
print("Unable to determine if the port is filtered")
namp -iR 100 -p 22 # 随机扫描100IP
namp 1.1.1.0/24 --exclude 1.1.1.1-100 # 跳过扫描
namp 1.1.1.0/24 --excludefile iplist.txt # 跳过扫描
namp -sL 1.1.1.0/24 # 列出扫描IP
zenmap