I am following this book called violent python and in CH5 it goes over making a script to find the mac address of an iphone wifi side. And check if bluetooth is on by incrementing the last bytes by one. Basically find an iphone that has bluetooth in hidden mode.
I am confused why the script errors out like that. What can I do to prevent this error in the future?
Here is the script below:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from scapy.all import *
from bluetooth import *
def retBtAddr(addr):
btAddr=str(hex(int(addr.replace(':', ''), 16) + 1))[2:]
btAddr=btAddr[0:2]+":"+btAddr[2:4]+":"+btAddr[4:6]+":"+\
btAddr[6:8]+":"+btAddr[8:10]+":"+btAddr[10:12]
return btAddr
def checkBluetooth(btAddr):
btName = lookup_name(btAddr)
if btName:
print '[+] Detected Bluetooth Device: ' + btName
else:
print '[-] Failed to Detect Bluetooth Device.'
def wifiPrint(pkt):
iPhone_OUI = 'd0:23:db'
if pkt.haslayer(Dot11):
wifiMAC = pkt.getlayer(Dot11).addr2
if iPhone_OUI == wifiMAC[:8]:
print '[*] Detected iPhone MAC: ' + wifiMAC
btAddr = retBtAddr(wifiMAC)
print '[+] Testing Bluetooth MAC: ' + btAddr
checkBluetooth(btAddr)
conf.iface = 'wlan1mon'
sniff(prn=wifiPrint)
Error message i receive:
sudo python 10-iphoneFinder.py
Traceback (most recent call last):
File "10-iphoneFinder.py", line 34, in <module>
sniff(prn=wifiPrint)
File "/home/rb/.local/lib/python2.7/site-packages/scapy/sendrecv.py", line 620, in sniff
r = prn(p)
File "10-iphoneFinder.py", line 26, in wifiPrint
if iPhone_OUI == wifiMAC[:8]:
TypeError: 'NoneType' object has no attribute '__getitem__'
In Scapy, the addr2 field in the Dot11 layer is a conditional field, so it may have a value of None when the sniffed packet has no such field.
Here is how we could write the wifiPrint() function:
IPHONE_OUI = 'd0:23:db:'
def wifiPrint(pkt):
if Dot11 in pkt:
wifiMAC = pkt[Dot11].addr2
if wifiMAC is not None and wifiMAC.startswith(IPHONE_OUI):
print '[*] Detected iPhone MAC: ' + wifiMAC
btAddr = retBtAddr(wifiMAC)
print '[+] Testing Bluetooth MAC: ' + btAddr
checkBluetooth(btAddr)
As a side note, the script is not really well coded, to say the least. Maybe it's not a good idea to learn Scapy (or even Python) from it.
Related
new to Python but it really makes fun to work with :-)
Using the pyserial lib and works fine so far. BUT...
...is there a way to ignore the following problem: During a serial communication I disconnect the COM-cable for a short time. I got the following errormessage then:
**Traceback (most recent call last):
File "C:\Users\greulich\PycharmProjects\arduino_serial\main.py", line 48, in <module>
functions.receiveWithStartMarkers()
File "C:\Users\greulich\PycharmProjects\arduino_serial\functions.py", line 30, in receiveWithStartMarkers
receivedChar = serialPort.read(1) # read 1 byte
File "C:\Users\greulich\PycharmProjects\arduino_serial\venv\lib\site-packages\serial\serialwin32.py", line 275, in read
raise SerialException("ClearCommError failed ({!r})".format(ctypes.WinError()))
serial.serialutil.SerialException: ClearCommError failed (PermissionError(13, 'Das Gerät erkennt den Befehl nicht.', None, 22))**
My code looks like that:
while serialPort.is_open is True and newData is False:
#try:
receivedChar = serialPort.read(1) # read 1 byte
print(str(date.time()) + ' >>> ' + 'I got the following byte: ' + str(receivedChar))
I opened up port initially in that module:
try:
serialPort = serial.Serial('COM12', 115200)
except:
print('COM-Port not available!')
print('Will exit not the Python program!')
exit() #quits the complete Python program
serialPort.timeout = 3
Is there a way to define kind of a timeout until this error will hit me where the user has the chance to reconnect the cable?
In a nutshell: I want to be able to disconnect the com cable for a short time and connect it again without an error showing :-)
Thanks,
Markus
I am taking an online course on ethical hacking and i am trying to make a program in python that injects code into html, at this moment i am at the decoding HTML response stage.
def process_packet(packet):
scapy_packet = scapy.IP(packet.get_payload())
if scapy.Raw in scapy_packet and scapy.TCP in scapy_packet:
if scapy_packet[scapy.TCP].dport == 80:
print("[+] Request")
modified_load = re.sub("Accept-Encoding:.*?//r//n", "", scapy_packet(scapy.Raw).load)
new_packet = set_load(scapy_packet, modified_load)
packet.setpayload(str(new_packet))
elif scapy_packet[scapy.TCP].sport == 80:
print("[+] Response")
print(scapy_packet.show())
packet.accept()
When I use the program in the terminal it waits with no errors until I open a tab in browser and go somewhere.
When I do that it gives me this error:
[+] Request
Exception ignored in: 'netfilterqueue.global_callback'
Traceback (most recent call last):
File "code_injector.py", line 25, in process_packet
modified_load = re.sub("Accept-Encoding:.*?//r//n", "", scapy_packet(scapy.Raw).load)
TypeError: 'IP' object is not callable
I already used iptabels -I INPUT -j NFQUEUE --queue-num0 and iptabels -I OUTPUT -j NFQUEUE --queue-num0
to make it work in my local computer.
This is my first question, sorry for bad explaining.
These are my imports
import scapy.all as scapy
import netfilterqueue
import re
I am using Cambrionix PowerPad15s for my devices but while running their first code which is to find all the device connected to the usb i am having some issue in jsonrpc file(Which is provided by the company itself).
I have to import this-
from cbrxapi import cbrxapi
This code is to get all the connected device in the usb port and save in result variable-
result = cbrxapi.cbrx_discover("local")
Rest of the code is-
if result==False:
print "No Cambrionix unit found."
sys.exit(0)
unitId = result[0]
handle = cbrxapi.cbrx_connection_open(unitId)
nrOfPorts = cbrxapi.cbrx_connection_get(handle, "nrOfPorts")
cbrxapi.cbrx_connection_close(handle)
print "The Cambrionix unit " + unitId + " has " + str(nrOfPorts) + " ports."
The error I am facing in is
Traceback (most recent call last):
File "cbrx_api_quickstart.py", line 9, in
result = cbrxapi.cbrx_discover("local")
File "/usr/local/share/cbrxapi/jsonrpc-0.1/jsonrpc.py", line 936, in call
return self.__req(self.__name, args, kwargs)
File "/usr/local/share/cbrxapi/jsonrpc-0.1/jsonrpc.py", line 908, in __req
raise RPCTransportError(err)
jsonrpc.RPCTransportError: [Errno 111] Connection refused
The product I am using is Cambrionix
Sorry for not explaining properly. I am still in learning phase..
Found the solution-
I have to install one more file to my system to get the code working..
$ sudo apt-get install avahi-daemon
And I need to ensure that one more script is running on my system.
install_service.sh in /usr/local/share/cbrxd/setup
I got the following code:
import bluetooth
def apparaat():
nearby_devices = bluetooth.discover_devices(lookup_names = True, flush_cache = True, duration = 15)
for address in nearby_devices:
print("Gevonden apparaten: " + str(address))
print("Gevonden apparaten: " + str(nearby_devices))
apparaat()
When I run the script the out put is:
Gevonden apparaten: []
When I scan for bluetooth devices on my raspberry PI it returns a couple. What im a missing here?
Can you try to run this code? I found that someone ported this bluetooth package from python 2.7 to 3.x and it might have introduced some bugs when printing unicode strings.
import bluetooth
x = bluetooth.discover_devices()
n = bluetooth.lookup_name(x[0])
print(n)
(source: https://groups.google.com/forum/#!topic/pybluez/Kq-ViMBo6es)
I'm trying to establish serial communications between a Beaglebone Black and Arduino Mega, but I'm having issues getting this to work, particularly on the Beagle's side. I keep getting this error message:
Traceback (most recent call last):
File "/var/lib/cloud9/IBID 2.0 /data stream test (1).py", line 35, in <module>
sensorValue += ser.read('UART1') #add more for more pins
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 449, in read
buf = os.read(self.fd, size-len(read))
TypeError: unsupported operand type(s) for -: 'str' and 'int'
in response to trying to run this code:
import Adafruit_BBIO.UART as UART
import serial
UART.setup('UART1')
name = raw_input('name your file: ')
final_name = os.path.join(/sequence of files and folders/, name + '.txt')
data = open(name + '.txt', 'a+')
ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600, timeout = 1000)
sensorValue = 0
header = 'Sensor 1 output'
data.write(str(header))
data.write(str('\n'))
while True:
ser.open()
sensorValue += ser.read('UART1')
data.write(sensorValue)
I'm using the cloud 9 IDE to program the Beaglebone to receive incoming data from a sensor hooked up to the Arduino (via logic converter.) The error code is mystifying me, to say the least. The links it provides aren't leading me to anything (no files found) in the IDE. I haven't been able to find much [on how to resolve this error.]
On this line
sensorValue += ser.read('UART1')
you are calling serial.Serial.read(size=1) with type str as an argument. The method takes an int.