analitics

Pages

Showing posts with label npcap. Show all posts
Showing posts with label npcap. Show all posts

Thursday, December 7, 2023

Python 3.13.0a1 : Testing with scapy - part 001.

Scapy is a powerful interactive packet manipulation library written in Python. Scapy is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, match requests and replies, and much more. see the official website.
You need to install NPCap.
Beacon frames are transmitted periodically, they serve to announce the presence of a wireless LAN and to synchronise the members of the service set.
In IBSS network beacon generation is distributed among the stations.
Beacon frames are transmitted by the access point (AP) in an infrastructure basic service set (BSS).
Beacon frames include information about the access point and supported data rates and what encryption is being used.
These are received by your device’s wireless network interface and interpreted by your operating system to build the list of available networks.
The beacon variable indicates the capabilities of our access point.
Let's see the source code:
C:\PythonProjects\scapy_001>pip install scapy
Collecting scapy
  Downloading scapy-2.5.0.tar.gz (1.3 MB)
     ---------------------------------------- 1.3/1.3 MB 3.5 MB/s eta 0:00:00
  Installing build dependencies ... done
...
Successfully built scapy
Installing collected packages: scapy
Successfully installed scapy-2.5.0
The source code is simple:
from scapy.all import Dot11,Dot11Beacon,Dot11Elt,RadioTap,sendp,hexdump

netSSID = 'testSSID'       #Network name here
iface = 'Realtek PCIe GbE Family Controller'         #Interface name here

dot11 = Dot11(type=0, subtype=8, addr1='ff:ff:ff:ff:ff:ff',
addr2='22:22:22:22:22:22', addr3='33:33:33:33:33:33')
beacon = Dot11Beacon(cap='ESS+privacy')
essid = Dot11Elt(ID='SSID',info=netSSID, len=len(netSSID))
rsn = Dot11Elt(ID='RSNinfo', info=(
'\x01\x00'                 #RSN Version 1
'\x00\x0f\xac\x02'         #Group Cipher Suite : 00-0f-ac TKIP
'\x02\x00'                 #2 Pairwise Cipher Suites (next two lines)
'\x00\x0f\xac\x04'         #AES Cipher
'\x00\x0f\xac\x02'         #TKIP Cipher
'\x01\x00'                 #1 Authentication Key Managment Suite (line below)
'\x00\x0f\xac\x02'         #Pre-Shared Key
'\x00\x00'))               #RSN Capabilities (no extra capabilities)

frame = RadioTap()/dot11/beacon/essid/rsn

frame.show()
print("\nHexdump of frame:")
hexdump(frame)
input("\nPress enter to start\n")

sendp(frame, iface=iface, inter=0.100, loop=1)
Let's run this source code:
python scapy_network_001.py
###[ RadioTap ]###
  version   = 0
  pad       = 0
  len       = None
  present   = None
  notdecoded= ''
###[ 802.11 ]###
     subtype   = Beacon
     type      = Management
     proto     = 0
     FCfield   =
     ID        = 0
     addr1     = ff:ff:ff:ff:ff:ff (RA=DA)
     addr2     = 22:22:22:22:22:22 (TA=SA)
     addr3     = 33:33:33:33:33:33 (BSSID/STA)
     SC        = 0
###[ 802.11 Beacon ]###
        timestamp = 0
        beacon_interval= 100
        cap       = ESS+privpython scapy_network_001.py
###[ RadioTap ]### tion Element ]###
  version   = 0      = SSID
  pad       = 0      = 8
  len       = None   = 'testSSID'
  present   = Noneation Element ]###
  notdecoded= ''     = RSN
###[ 802.11 ]###     = None
     subtype   = Beacon'\x01\x00\x00\x0f¬\x02\x02\x00\x00\x0f¬\x04\x00\x0f¬\x02\x01\x00\x00\x
     type      = Management
     proto     = 0
     FCfield   =
     ID        = 0
     addr1     = ff:ff:ff:ff:ff:ff (RA=DA)FF FF FF FF  ................
     addr2     = 22:22:22:22:22:22 (TA=SA)33 33 00 00  ..""""""333333..
     addr3     = 33:33:33:33:33:33 (BSSID/STA)8 74 65  ........d.....te
     SC        = 049 44 30 1C 01 00 00 0F C2 AC 02 02  stSSID0.........
###[ 802.11 Beacon ]### 00 0F C2 AC 02 01 00 00 0F C2  ................
        timestamp = 0                                  ....
        beacon_interval= 100
        cap       = ESS+privacy
###[ 802.11 Information Element ]###
           ID        = SSID..................................................................
           len       = 8.....................................................................
           info      = 'testSSID'
###[ 802.11 Information Element ]###
           ID        = RSN
           len       = None>
           info      = '\x01\x00\x00\x0f¬\x02\x02\x00\x00\x0f¬\x04\x00\x0f¬\x02\x01\x00\x00\x0f¬\x02\x00\x00'


Hexdump of frame:
0000  00 00 08 00 00 00 00 00 80 00 00 00 FF FF FF FF  ................
0010  FF FF 22 22 22 22 22 22 33 33 33 33 33 33 00 00  ..""""""333333..
0020  00 00 00 00 00 00 00 00 64 00 11 00 00 08 74 65  ........d.....te
0030  73 74 53 53 49 44 30 1C 01 00 00 0F C2 AC 02 02  stSSID0.........
0040  00 00 0F C2 AC 04 00 0F C2 AC 02 01 00 00 0F C2  ................
0050  AC 02 00 00                                      ....

Press enter to start

.................................................................
Sent 130 packets.