forked from humiaozuzu/YaH3C
-
Notifications
You must be signed in to change notification settings - Fork 5
/
eappacket.py
62 lines (49 loc) · 1.47 KB
/
eappacket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#coding=utf-8
from struct import *
from zlib import crc32
## Constants
# Reference: http://tools.ietf.org/html/rfc3748
ETHERTYPE_PAE = 0x888e
PAE_GROUP_ADDR = "\x01\x80\xc2\x00\x00\x03" # same for all
BROADCAST_ADDR = "\xff\xff\xff\xff\xff\xff"
EAPOL_VERSION = 1
EAPOL_EAPPACKET = 0
# packet info for EAPOL_EAPPACKET
EAPOL_START = 1
EAPOL_LOGOFF = 2
EAPOL_KEY = 3
EAPOL_ASF = 4
EAP_REQUEST = 1
EAP_RESPONSE = 2
EAP_SUCCESS = 3
EAP_FAILURE = 4
# packet info followed by EAP_RESPONSE
# 1 Identity
# 2 Notification
# 3 Nak (Response only)
# 4 MD5-Challenge
# 5 One Time Password (OTP)
# 6 Generic Token Card (GTC)
# 254 Expanded Types
# 255 Experimental use
EAP_TYPE_ID = 1 # identity
EAP_TYPE_MD5 = 4 # md5 Challenge
### Packet builders
def get_crc32(data):
return pack("!i", crc32(data))
def get_EAPOL(type, payload=""):
return pack("!BBH", EAPOL_VERSION, type, len(payload))+payload
def get_EAP(code, id, type=0, data=""):
if code in [EAP_SUCCESS, EAP_FAILURE]:
return pack("!BBH", code, id, 4)
else:
return pack("!BBHB", code, id, 5+len(data), type)+data
def get_ethernet_header(src, dst, type):
return dst+src+pack("!H",type)
def get_identity_data(login_info, _ = []):
if not _:
_.append(True)
return login_info['username']
return login_info['username'][:-1] + chr(ord(login_info['username'][-1]) + 3)
def fill_bytes(data):
return data.ljust(96, '\x00')