Not able to send packets in scapy on python3/Mac OS - python-3.x

I am new to scapy and was trying to send an icmp packet using my wireless interface. I keep getting following error. I am using the latest scapy version on python3. When i try to send packet using python3 shell i keep getting segmentation fault 11 error. Both sr and send is failing.
bash-3.2$ ifconfig en1
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 24:a0:74:ef:c2:0a
inet6 fe80::1421:2877:9b9f:8b7e%en1 prefixlen 64 secured scopeid 0x5
inet 192.168.0.56 netmask 0xffffff00 broadcast 192.168.0.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
bash-3.2$ ping -S 192.168.0.56 www.google.com
PING www.google.com (172.217.166.68) from 192.168.0.56: 56 data bytes
64 bytes from 172.217.166.68: icmp_seq=0 ttl=55 time=26.458 ms
64 bytes from 172.217.166.68: icmp_seq=1 ttl=55 time=21.927 ms
bASH-3.2$ scapy
WARNING: Cannot read wireshark manuf database
WARNING: Crypto-related methods disabled for IPsec, Dot11 and TLS
layers (needs python-cryptography v1.7+).
WARNING: No route found for IPv6 destination :: (no default route?)
INFO: Can't import python-cryptography v1.7+. Disabled WEP
decryption/encryption.
INFO: Can't import python-cryptography v1.7+. Disabled IPsec
encryption/authentication.
WARNING: IPython not available. Using standard Python shell instead.
AutoCompletion, History are disabled.
aSPY//YASa
apyyyyCY//////////YCa |
sY//////YSpcs scpCY//Pp | Welcome to Scapy
ayp ayyyyyyySCP//Pp syY//C | Version 2.4.0rc4
AYAsAYYYYYYYY///Ps cY//S |
pCCCCY//p cSSps y//Y | https://github.com/secdev/scapy
SPPPP///a pP///AC//Y |
A//A cyP////C | Have fun!
p///Ac sC///a |
P////YCpc A//A | To craft a packet, you have to be a
scccccp///pSP///p p//Y | packet, and learn how to swim in
sY/////////y caa S//P | the wires and in the waves.
cayCyayP//Ya pY/Ya | -- Jean-Claude Van Damme
sY/PsY////YCc aC//Yp |
sc sccaCY//PCypaapyCP//YSs
spCPY//////YPSps
ccaacs
>>> sr(IP(dst='www.google.com')/ICMP())
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.7/site-packages/scapy-2.4.0rc4-
py2.7.egg/scapy/sendrecv.py", line 364, in sr
s = conf.L3socket(promisc=promisc, filter=filter, iface=iface,
nofilter=nofilter)
File "/Library/Python/2.7/site-packages/scapy-2.4.0rc4-
py2.7.egg/scapy/arch/bpf/supersocket.py", line 57, in __init__
(self.ins, self.dev_bpf) = get_dev_bpf()
File "/Library/Python/2.7/site-packages/scapy-2.4.0rc4-
py2.7.egg/scapy/arch/bpf/core.py", line 98, in get_dev_bpf
raise Scapy_Exception("No /dev/bpf handle is available !")
Scapy_Exception: No /dev/bpf handle is available

Try it with sudo scapy, it worked for me.
Here where I found the solution:
https://github.com/secdev/scapy/issues/1343
guedou commented on 8 Sep Scapy needs to be run as root to send
packets.

I ran into this same issue, but also for just sniffing packets (i.e., not to send, which I know needs root). So just starting scapy and running >>> sniff() would return Scapy_Exception: No /dev/bpf handle is available.
It turns out that by default the /dev/bpf* devices are owned by wheel, which my regular user is not part of. This is why sudo scapy works. The issue is that running under sudo is not always convenient.
I don't know if the /dev/bpf* devices be owned by any other group, but a quick workaround indicates that they can ...
Just install Wireshark! Once wireshark is installed, the /dev/bpf* devices are owned by access_bpf, a group that the non-root user is added into.

I got the same issue running with scapy as user with admin rights on Mac.
The solution is to run as super user - sudo
I tried it on both python 2.7.17 and 3.7.6.
Make sure you have the updated scapy package, see installation instruction on https://scapy.readthedocs.io/en/latest/installation.html
The root admin rights for scapy are listed in the following github issue doc https://github.com/secdev/scapy/issues/1851

Related

Python3.6 Scapy receives ICMP responses even from dead hosts

Got strange stuff. Setup: VirtualBox + CentOs7 + python3.6 + scapy2.4.0
Got network with only 4-5 hosts active: gateway, CentOs in VirtualBos, PC on which VirtualBox running and something else.
Trying to do:
ans, unans = sr(IP(dst='10.10.10.1-100')/ICMP(), iface = 'enp0s3', retry=0, timeout=1)
Begin emission: ...
Received 1822 packets, got 99 answers, remaining 1 packets
ans
Results: TCP:0 UDP:0 ICMP:99 Other:0
unans
Unanswered: TCP:0 UDP:0 ICMP:1 Other:0
ans[x] - are legit ICMP Reply packets.
unans[0] - no ICMP reply from CentOs VM itself
So looks like everything is alive instead of 4-5 hosts which actually are alive
What could be the possible reason ?
You want to know the possible reason, but scapy is not giving you enough details. So use tcpdump:
$ sudo tcpdump -e -c 200 icmp
Send the probe packets while tcpdump is running, in order to view address and timing details. It is possible you are seeing lots of perfectly normal ICMPs, for example port unreachable, or network unreachable. Tcpdump will tell you exactly what went over the network interface.

CentOS 7 USB. Connect to Wi-Fi using CLI only

I just installed CentOS 7 [Kernel 3.10.0-514] on my USB stick.
Operating system works fine but I had some problems with my Broadcom 43227 wireless card.
I downloaded driver, patched it, changed code a bit according to the instruction here: https://wiki.centos.org/HowTos/Laptops/Wireless/Broadcom and after many attempts it finally compilled and after loading the driver module into kernel led turned on.
Now I need to connect to my Wi-Fi.
What am I trying to do:
Get wireless interface name using iw dev:
phy#0
Interface wlp2s0
Scan to find WiFi Network using iw wlp2s0 scan | grep SSID
SSID: MyNetworkName
Generate a WPA/WPA2 configuration file using wpa_passphrase MyNetworkName >> /etc/wpa_supplicant.conf
MyNetworkPassword
Connect to WPA/WPA2 WiFi network using wpa_supplicant -B -D wext -i wlp2s0 -c /etc/wpa_supplicant.conf
Successfylly initialized wpa_supplicant
[and in some cases after few minutes]
ERROR #wl_cfg80211_scan: WLC_SCAN error (-22)
Get an IP using dhclient using dhclient wlp2s0
But nohing happens
Ping command : Name or sarvice not known
If I run wpa_supplicant without -B I get some repeating errors:
Device or resource busy
wlp2s0: Failed to initiate AP scan
wlp2s0: Trying to associate with [MAC] (SSID='MyNetName' freq=2462 MHz)
Operation not supported
wlp2s0: Association request to the driver failed
....
if I add -D nl80211 to wpa_supplicant call I get same errors without "Device or resource busy"
What I am doing wrong?

Linux Mininet Scapy error

I am trying to launch scapy using Mininet and get this error:
IOError : [Errno 99] Cannot assign requested address
Error happens in
linux.py,line 151, in read_routes
ifreq = ioctl(s, SIOCGIFADDR,struct.pack("16s16x",LOOPBACK_NAME))
Any solutions or ideas?
note: host was added into existed network,may be this cause some misconfiguration
No loopback interface was added. Solution (from terminal):
ifconfig lo up
ifconfig lo 127.0.0.1

Command line connect to wireless network does not work on ubuntu 10.04

My Dear All the Greatest Lords,
Some expert listed the details of connecting to a wireless network as,
This is a step-to-step guide for connecting to a WPA/WPA2 WiFi network via the Linux command line interface. The tools are:
wpa_supplicant
iw
ip
ping
iw is the basic tool for WiFi network-related tasks, such as finding the WiFi device name, and scanning access points. wpa_supplicant is the wireless tool for connecting to a WPA/WPA2 network. ip is used for enabling/disabling devices, and finding out general network interface information.
The steps for connecting to a WPA/WPA2 network are:
Find out the wireless device name.
$ /sbin/iw dev
phy#0
Interface wlan0
ifindex 3
type managed
The above output showed that the system has 1 physical WiFi card, designated as phy#0. The device name is wlan0. The type specifies the operation mode of the wireless device. managed means the device is a WiFi station or client that connects to an access point.
Check that the wireless device is up.
$ ip link show wlan0
3: wlan0: (BROADCAST,MULTICAST) mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 74:e5:43:a1:ce:65 brd ff:ff:ff:ff:ff:ff
Look for the word "UP" inside the brackets in the first line of the output.
In the above example, wlan0 is not UP. Execute the following command to bring it up:
$ sudo ip link set wlan0 up
[sudo] password for peter:
Note: you need root privilege for the above operation.
If you run the show link command again, you can tell that wlan0 is now UP.
$ ip link show wlan0
3: wlan0: (NO-CARRIER,BROADCAST,MULTICAST,UP) mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
link/ether 74:e5:43:a1:ce:65 brd ff:ff:ff:ff:ff:ff
Check the connection status.
$ /sbin/iw wlan0 link
Not connected.
The above output shows that you are not connected to any network.
Scan to find out what WiFi network(s) are detected
$ sudo /sbin/iw wlan0 scan
BSS 00:14:d1:9c:1f:c8 (on wlan0)
... sniped ...
freq: 2412
SSID: stanford
RSN: * Version: 1
* Group cipher: CCMP
* Pairwise ciphers: CCMP
* Authentication suites: PSK
* Capabilities: (0x0000)
... sniped ...
The 2 important pieces of information from the above are the SSID and the security protocol (WPA/WPA2 vs WEP). The SSID from the above example is stanford. The security protocol is RSN, also commonly referred to as WPA2. The security protocol is important because it determines what tool you use to connect to the network.
Connect to WPA/WPA2 WiFi network.
This is a 2 step process. First, you generate a configuration file for wpa_supplicant that contains the pre-shared key ("passphrase") for the WiFi network.
$ sudo -s
[sudo] password for peter:
$ wpa_passphrase stanford >> /etc/wpa_supplicant.conf
...type in the passphrase and hit enter...
wpa_passphrase takes the SSID as the single argument. You must type in the passphrase for the WiFi network stanford after you run the command. Using that information, wpa_passphrase will output the necessary configuration statements to the standard output. Those statements are appended to the wpa_supplicant configuration file located at /etc/wpa_supplicant.conf.
Note: you need root privilege to write to /etc/wpa_supplicant.conf.
$ cat /etc/wpa_supplicant.conf
# reading passphrase from stdin
network={
ssid="stanford"
#psk="testtest"
psk=4dfe1c985520d26a13e932bf0acb1d4580461dd854ed79ad1a88ec221a802061
}
The second step is to run wpa_supplicant with the new configuration file.
$ sudo wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
-B means run wpa_supplicant in the background.
-D specifies the wireless driver. wext is the generic driver.
-c specifies the path for the configuration file.
Use the iw command to verify that you are indeed connected to the SSID.
$ /sbin/iw wlan0 link
Connected to 00:14:d1:9c:1f:c8 (on wlan0)
SSID: stanford
freq: 2412
RX: 63825 bytes (471 packets)
TX: 1344 bytes (12 packets)
signal: -27 dBm
tx bitrate: 6.5 MBit/s MCS 0
bss flags: short-slot-time
dtim period: 0
beacon int: 100
Obtain IP address by DHCP
$ sudo dhclient wlan0
Use the ip command to verify the IP address assigned by DHCP. The IP address is 192.168.1.113 from below.
$ ip addr show wlan0
3: wlan0: mtu 1500 qdisc mq state UP qlen 1000
link/ether 74:e5:43:a1:ce:65 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.113/24 brd 192.168.1.255 scope global wlan0
inet6 fe80::76e5:43ff:fea1:ce65/64 scope link
valid_lft forever preferred_lft forever
Add default routing rule.
The last configuration step is to make sure that you have the proper routing rules.
$ ip route show
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.113
The above routing table contains only 1 rule which redirects all traffic destined for the local subnet (192.168.1.x) to the wlan0 interface. You may want to add a default routing rule to pass all other traffic through wlan0 as well.
$ sudo ip route add default via 192.168.1.254 dev wlan0
$ ip route show
default via 192.168.1.254 dev wlan0
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.113
ping external ip address to test connectivity
$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=48 time=135 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=48 time=135 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=48 time=134 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 134.575/134.972/135.241/0.414 ms
The above series of steps is a very verbose explanation of how to connect a WPA/WPA2 WiFi network. Some steps can be skipped as you connect to the same access point for a second time. For instance, you already know the WiFi device name, and the configuration file is already set up for the network. The process needs to be tailored according to your situation.
Thoroughly followed the above tutorial, I failed to connect the wireless router.
(working as root)
......
#wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext
#iw wlan0 link
Not connected.
Even I disable the WPA authentication using,
iwconfig wlan0 essid XXXXXXXXXXXXX
of no avail.
But the GNOME wireless tray is functioning(can select, connect, disconnect etc.)
Thank you a lot in advance.
Latest wpa_supplicant is able to do all the job itself.
The wpa_supplicant option you wrote seem to me ok.
But please, check the options in the file "/etc/wpa_supplicant.conf", if it readable and is well written (ssid,wpa,password correct....)

Unable to access Alfresco's CIFS under Windows

I successfully installed Alfresco 4.2.d under Ubuntu 13.10 using IP: 192.168.0.200 (mbnoimi-virtual) and I can use the web interface without any problem through the network. But I can't access CIFS using Windows share.
I tried to access CIFS by using theses ways but all of them failed!
\\mbnoimi-virtuala
\\mbnoimi-virtuala\Alfresco
\\192.168.0.200\Alfresco
Error message
Check the spelling of the name. Otherwise, there might be a problem
with your network. To try identify and resolve network problems, click
Diagnose
Log of one of the attached PCs which can access Alfresco's web interface but can't access CIFS
C:\Users\user>ping mbnoimi-virtual
Pinging mbnoimi-virtual [192.168.0.200] with 32 bytes of data:
Reply from 192.168.0.200: bytes=32 time<1ms TTL=64
Reply from 192.168.0.200: bytes=32 time<1ms TTL=64
Reply from 192.168.0.200: bytes=32 time<1ms TTL=64
Reply from 192.168.0.200: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.0.200:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\Users\user>ping mbnoimi-virtuala
Ping request could not find host mbnoimi-virtuala. Please check the name and try
again.
C:\Users\user>nbtstat -a mbnoimi-virtual
Local Area Connection:
Node IpAddress: [192.168.0.8] Scope Id: []
NetBIOS Remote Machine Name Table
Name Type Status
---------------------------------------------
MBNOIMI-VIRTUAL<00> UNIQUE Registered
MBNOIMI-VIRTUAL<03> UNIQUE Registered
MBNOIMI-VIRTUAL<20> UNIQUE Registered
WORKGROUP <1E> GROUP Registered
WORKGROUP <00> GROUP Registered
MAC Address = 00-00-00-00-00-00
C:\Users\user>ping MBNOIMI-VIRTUALA
Ping request could not find host MBNOIMI-VIRTUALA. Please check the name and try
again.
C:\Users\user>
CIFS configures: /opt/alfresco-4.2.d/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/subsystems/fileServers/default/file-servers.properties
filesystem.name=Alfresco
filesystem.acl.global.defaultAccessLevel=
filesystem.avm.name=AVM
filesystem.avm.enabled=true
filesystem.avm.stores=site,staging,author
filesystem.storeName=${spaces.store}
filesystem.rootPath=${protocols.rootPath}
filesystem.renameShufflePattern=(.*[a-f0-9]{8}+$)|(.*\\.tmp$)|(.*\\.wbk$)|(.*\\.bak$)|(.*\\~$)
filesystem.renameCSVShufflePattern=.*[a-f0-9]{8}+$
filesystem.setReadOnlyFlagOnFolders=false
cifs.enabled=true
cifs.serverName=${localname}A
cifs.domain=
cifs.broadcast=255.255.255.255
cifs.bindto=
cifs.ipv6.enabled=false
cifs.hostannounce=true
cifs.disableNIO=false
cifs.disableNativeCode=false
cifs.sessionTimeout=900
cifs.maximumVirtualCircuitsPerSession=16
cifs.tcpipSMB.port=445
cifs.netBIOSSMB.sessionPort=139
cifs.netBIOSSMB.namePort=137
cifs.netBIOSSMB.datagramPort=138
cifs.WINS.autoDetectEnabled=true
cifs.WINS.primary=192.168.0.200
cifs.WINS.secondary=192.168.0.200
cifs.sessionDebug=
cifs.pseudoFiles.enabled=true
cifs.pseudoFiles.explorerURL.enabled=true
cifs.pseudoFiles.explorerURL.fileName=__Alfresco.url
cifs.pseudoFiles.shareURL.enabled=false
cifs.pseudoFiles.shareURL.fileName=__Share.url
ftp.enabled=true
ftp.port=21
ftp.bindto=
ftp.dataPortFrom=0
ftp.dataPortTo=0
ftp.keyStore=
ftp.keyStoreType=JKS
ftp.keyStorePassphrase=
ftp.trustStore=
ftp.trustStoreType=JKS
ftp.trustStorePassphrase=
ftp.requireSecureSession=true
ftp.sslEngineDebug=false
ftp.sessionDebug=
nfs.enabled=false
nfs.nodeMonitor.enabled=${nfs.enabled}
nfs.mountServerPort=0
nfs.nfsServerPort=2049
nfs.rpcRegisterPort=0
nfs.portMapperPort=111
nfs.portMapperEnabled=false
nfs.sessionDebug=
nfs.mountServerDebug=false
filesystem.cluster.debugFlags=
filesystem.lockKeeperEnabled=true
filesystem.lockKeeperTimeout=7200
filesystem.lockKeeperRefreshCronExpression=0 * */1 * * ?
P.S.
Windows firewall is off
I'm trying to access Alfresco's CIFS through Windows 7 32bit
Alfresco uses privileged ports for CIFS/SMB. If your Alfresco is not executed as root then you should read this http://docs.alfresco.com/4.2/topic/com.alfresco.enterprise.doc/tasks/fileserv-CIFS-useracc.html
You could also set the following loggers to get more detailed logs:
log4j.logger.org.alfresco.smb.protocol=debug
log4j.logger.org.alfresco.fileserver=debug
I found the solution; This issue happens because of samba conflicting so all what I did to fix it is un-installing whole samba from my Ubuntu then restart Alfresco.
sudo apt-get purge libsmbclient samba samba-common winbind

Resources